api-platform-dto-resources
Installation
SKILL.md
Api Platform Dto Resources (Symfony)
Use when
- The
#[ApiResource]class must be the API contract, decoupled from the Doctrine entity. - Entity and API fields differ in name or format (rename, formatted price, computed value).
- Create, update, or list operations need their own input or output shape.
- Migrating code that relied on
DataTransformerInterface, which no longer exists.
Default workflow
- Require
symfony/object-mapperand setstateOptions: new Options(entityClass: ...)on the DTO resource. - Bind the DTO and the entity with
#[Map(source: ...)]and#[Map(target: ...)], and use#[Map(transform: ...)]for computed fields. - For distinct shapes, create input and output classes and wire them with
input:andoutput:on each operation. - When mapping needs real logic, write a custom
ProcessorInterfacethat callsObjectMapperInterface::map(). - Test each operation: payload in, response shape out.