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

  1. Require symfony/object-mapper and set stateOptions: new Options(entityClass: ...) on the DTO resource.
  2. Bind the DTO and the entity with #[Map(source: ...)] and #[Map(target: ...)], and use #[Map(transform: ...)] for computed fields.
  3. For distinct shapes, create input and output classes and wire them with input: and output: on each operation.
  4. When mapping needs real logic, write a custom ProcessorInterface that calls ObjectMapperInterface::map().
  5. Test each operation: payload in, response shape out.
Installs
64
GitHub Stars
224
First Seen
Sep 18, 2026