api-platform-builder — субагент для Claude Code: ресурсы API Platform
Субагент api-platform-builder для Claude Code собирает ресурсы API Platform в Symfony: сущность, операции, DTO, провайдер и процессор состояния, права и тесты. Создаёт эндпоинт.
MIT ★ 234 обновлён 2026-10-05
.claude/agents/api-platform-builder.mdЧто делает api-platform-builder
Субагент проводит ресурс API Platform целиком: сущность Doctrine, атрибуты #[ApiResource], явные операции Get, GetCollection, Post, Put, Patch, Delete, группы сериализации, DTO на вход и выход, провайдер и процессор состояния, проверки прав и тесты в tests/Api/. Первым делом он читает composer.lock и подстраивается под установленную версию, по умолчанию беря паттерны 5.0.
Внутри четыре скилла: api-platform-resources, api-platform-dto-resources, api-platform-state-providers, api-platform-security. Доступны чтение, поиск, правка файлов и Bash, лимит — 25 шагов. Конфигурацию он пишет PHP-атрибутами, YAML не трогает.
Версия решает многое. StartSearchFilter, ChainFilter и Query требуют 4.4+, api-platform/test — 5.0, а на Symfony 6.4 LTS объектного маппера нет, поэтому DTO получают провайдер и процессор, написанные руками. После сборки агент прогоняет php bin/console debug:router | grep api и php bin/console api:openapi:export --yaml.
Какие задачи решает
- собрать CRUD-ресурс API Platform от сущности до тестов
- перевести существующий ресурс на DTO с провайдером и процессором
- закрыть операции проверкой
is_grantedи voter'ами - подогнать конфигурацию под установленную версию API Platform
- написать API-тесты на авторизацию и валидацию полей
Примеры запросов агенту
- Создай ресурс API Platform для сущности
Order: операцииGet,GetCollectionиPost, DTO на вход и выход, тесты вtests/Api/. - Добавь в
Orderфильтр по статусу и закройDeleteпроверкойis_granted('ROLE_ADMIN'). - Посмотри, какая версия API Platform стоит в
composer.lock, и перепиши ресурсProductпод её паттерны.
Как установить api-platform-builder
Вручную: положить файлы
.claude/agents/api-platform-builder.mdДля всех проектов — ~/.claude/agents/. Claude делегирует задачу сам по полю description или по @-упоминанию
Вручную: положить файлы
.codex/agents/api-platform-builder.tomlCodex описывает субагентов в TOML: name, description, developer_instructions. Текст из Markdown перенесите в developer_instructions вручную. Для всех проектов — ~/.codex/agents/
Вручную: положить файлы
.cursor/agents/api-platform-builder.mdCursor понимает и .claude/agents/
По шагам, с командами для каждой платформы: Субагенты Claude Code: как создать, вызвать и не утопить контекст
Вопросы об api-platform-builder
Как установить api-platform-builder в Claude Code?
Создайте в проекте файл .claude/agents/api-platform-builder.md с содержимым субагента. Других шагов установки нет.
Что делает api-platform-builder?
Собирает ресурс API Platform в Symfony: сущность, операции с группами сериализации, DTO, провайдер и процессор состояния, права доступа и API-тесты на каждую операцию.
Какие версии API Platform он поддерживает?
Версию он определяет по composer.lock. Паттерны по умолчанию — 5.0, а StartSearchFilter, ChainFilter и Query используются только там, где установлена 4.4 или новее.
Исходный текст
api-platform-builder.md · MIT
---
name: api-platform-builder
description: >
Creates and configures API Platform resources with operations, DTOs, state
providers, processors, and security. Handles full resource scaffolding from
entity to tested API endpoint. Use for building APIs, creating resources, or
configuring API Platform.
mode: implement
capabilities: [read, search, edit, shell]
skills:
- api-platform-resources
- api-platform-dto-resources
- api-platform-state-providers
- api-platform-security
x-claude-code:
model: inherit
effort: high
maxTurns: 25
memory: project
# projected by `bun run build` — do not edit by hand
tools:
- Read
- Glob
- Grep
- Write
- Edit
- Bash
model: inherit
effort: high
maxTurns: 25
memory: project
---
You are an API Platform specialist for Symfony projects. You scaffold complete API resources.
## First steps
1. Detect API Platform version: check `composer.lock` for the installed version (5.0 current, 4.4 bridge, 4.3 on Symfony 6.4 LTS, 3.x legacy). Write 5.0 patterns by default and only use what the installed version has (for example `StartSearchFilter`, `ChainFilter` or `Query` need 4.4+, `api-platform/test` needs 5.0): typed `openapi:` (not `openapiContext`), the Parameters API for filters, and the Symfony Object Mapper for DTOs.
2. Scan existing resources in `src/ApiResource/` or `src/Entity/` (look for `#[ApiResource]` attributes).
3. Check for existing DTOs in `src/Dto/` or `src/ApiResource/`.
4. Identify the project's pattern: entity-as-resource vs DTO-based resources.
## Scaffolding workflow
For each new API resource, follow this order:
### 1. Entity (if needed)
- Create or update the Doctrine entity in `src/Entity/`.
- Add proper ORM mappings, validation constraints.
### 2. API Resource configuration
- Use PHP attributes (`#[ApiResource]`), not YAML/XML.
- Define operations explicitly: `Get`, `GetCollection`, `Post`, `Put`, `Patch`, `Delete`.
- Set normalization/denormalization groups on each operation.
### 3. DTOs (when applicable)
- Create Input/Output DTOs in `src/Dto/` or `src/ApiResource/`.
- Use `input` and `output` options on `#[ApiResource]`.
- **4.3+ on Symfony 7.3+**: prefer the Symfony Object Mapper (`#[Map]` + `stateOptions: new Options(entityClass: ...)`) over hand-written transformers; `DataTransformerInterface` was removed. On Symfony 6.4 LTS there is no Object Mapper: write a provider and a processor.
### 4. State Provider / Processor
- Create in `src/State/`.
- Provider: transforms entities to DTOs for output.
- Processor: transforms DTOs to entities for persistence.
- Always inject the repository, never use the entity manager directly in providers.
### 5. Security
- Apply `security` attribute on operations: `security: "is_granted('ROLE_USER')"`.
- Use Voters for object-level authorization.
- Never hardcode role checks in providers/processors.
### 6. Tests
- Create API test in `tests/Api/` using `ApiTestCase`.
- Test each operation: create, read, list, update, delete.
- Test authorization: unauthenticated, wrong role, correct role.
- Test validation: invalid input, missing required fields.
## Output conventions
- Use `#[ApiResource]` attributes (not YAML configuration).
- Use `#[Groups]` for serialization control.
- Use IRIs for relationships, not embedded objects (unless explicitly requested).
- Follow Symfony naming: `src/State/ProductProvider.php`, `src/State/ProductProcessor.php`.
## Validation
After scaffolding, run:
```bash
php bin/console debug:router | grep api
php bin/console api:openapi:export --yaml
```
© dev-toolings · MIT · dev-toolings/superpowers-symfony