Skip to main content
skill CX Codex

api-platform-dto-resources — Claude Code skill

The api-platform-dto-resources skill decouples your API contract from Doctrine entities in API Platform via Symfony's Object Mapper.

MIT ★ 234 updated 2026-10-05

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add dev-toolings/superpowers-symfony --skill api-platform-dto-resources -a claude-code
Open on GitHub

What api-platform-dto-resources does

The skill streamlines DTO resources in API Platform v5, v4.4, and v4.3 with built-in Object Mapper support. Instead of returning the entity directly, define an #[ApiResource] class as a DTO and bind it to the entity using #[Map(source: ...)] and #[Map(target: ...)]. Transformed fields (renamed, formatted, computed) use #[Map(transform: ...)].

It covers three approaches: automatic Object Mapper via stateOptions, separate input and output classes per operation, and custom ProcessorInterface for intricate logic. Object Mapper requires Symfony 7.3+ and does not work on API Platform 3.4 (manual mapping in provider and processor is needed there). On API Platform 5.0, ObjectMapperProcessor moves to ObjectMapperInputProcessor and ObjectMapperOutputProcessor.

The skill steers around the removal of DataTransformerInterface and clarifies the shift in processor architecture. Output includes resource classes with mappings, the chosen mapping path and rationale, and tests for each operation's request and response.

What it helps with

  • Decouple API contract from Doctrine entity
  • Rename entity fields in the API layer without code duplication
  • Define separate request and response shapes per operation
  • Migrate from removed DataTransformerInterface to Object Mapper
  • Compute and output derived fields not stored in the entity

Example prompts for the agent

  • Create a DTO for your entity with field mapping via #[Map]
  • Set up input and output classes for create and update operations
  • Write a custom processor to handle complex data transformations

How to install api-platform-dto-resources

1Skills CLI (Vercel)

npx skills add dev-toolings/superpowers-symfony --skill api-platform-dto-resources -a claude-code

2Manually: put the files in place

~/.claude/skills/api-platform-dto-resources/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/api-platform-dto-resources/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about api-platform-dto-resources

How do I install api-platform-dto-resources in Claude Code?

Run npx skills add dev-toolings/superpowers-symfony --skill api-platform-dto-resources -a claude-code, then open ~/.claude/skills/api-platform-dto-resources/SKILL.md.

What does this skill do?

It automates entity-to-DTO mapping in API Platform using Symfony's Object Mapper, enabling you to keep your API contract separate from the Doctrine entity and define different shapes for request and response data.

Which versions of API Platform does it support?

Object Mapper works on API Platform v5, v4.4, and v4.3, but requires Symfony 7.3+. On API Platform 3.4 and Symfony 6.4 LTS, manual mapping in provider and processor is required.

Source text

SKILL.md · MIT
---
name: api-platform-dto-resources
description: Map entities to API DTOs in API Platform (v5, 4.4, 4.3) with the Symfony Object Mapper (#[Map], stateOptions) for decoupled input/output contracts
capabilities: [read, search, edit, shell]
tags: [api-platform]
# projected by `bun run build` — do not edit by hand
allowed-tools:
  - Read
  - Glob
  - Grep
  - Write
  - Edit
  - Bash
---

# 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.

## Guardrails
- The automatic Object Mapper provider and processor only apply when `stateOptions` has an `entityClass` and both the DTO and the entity carry `#[Map]`.
- `DataTransformerInterface` is gone: use Object Mapper or a provider and processor.
- No Object Mapper on 3.4 or on Symfony 6.4 LTS (it needs Symfony 7.3+): map manually in a `ProviderInterface` and a `ProcessorInterface`.
- `ObjectMapperProcessor` is removed in 5.0: the automatic path uses `ObjectMapperInputProcessor` and `ObjectMapperOutputProcessor` (4.3+).
- Never return the entity itself from a DTO resource: only mapped fields reach the client.

## Progressive disclosure
- Use this file for execution posture and risk controls.
- Open references when deep implementation details are needed.

## Output contract
- The resource, input, and output classes with their `#[Map]` bindings.
- The mapping path chosen (Object Mapper or custom processor) and why.
- Tests showing the request and response shape of each operation.

## References
- `reference.md`

© dev-toolings · MIT · dev-toolings/superpowers-symfony

Similar skills

All skills for Backend and APIs →

From the same set51

The whole set →
doctrine-fetch-modes doctrine-fetch-modes guides Doctrine ORM and DBAL 4 query optimization in Symfony. Fixes N+1 queries, configures lazy loading, and implements DTO hydration. CX Codex +1 ★ 234repo stars api-platform-resources api-platform-resources is a Claude Code skill for configuring API Platform resources for REST and GraphQL. It activates for resource creation and changes to operations, pagination, or OpenAPI docs. CX Codex +1 ★ 234repo stars messenger-retry-failures messenger-retry-failures sorts out failed Symfony Messenger handlers: whether a message deserves another attempt, when it goes straight to the failure transport, and how to pull it back. CX Codex +1 ★ 234repo stars api-platform-state-providers Configures API Platform State Providers and Processors in Symfony. It helps decouple data retrieval and persistence from Doctrine entities. CX Codex +1 ★ 234repo stars api-platform-filters api-platform-filters tells the agent how to wire search, range, date and boolean filters into API Platform collection endpoints in Symfony, and how to leave the deprecated attribute behind. CX Codex +1 ★ 234repo stars doctrine-performance-optimizer doctrine-performance-optimizer audits Doctrine ORM code in read-only mode to detect looped relation queries, evaluate fetch strategies, and suggest DTO hydration, batch processing, or database indexes. CX Codex ★ 234repo stars symfony-reviewer symfony-reviewer reviews changed Symfony files for architecture, security, and framework conventions. Run it after edits or ask for a code review. CX Codex ★ 234repo stars doctrine-architect doctrine-architect — a read-only subagent that opens your Symfony entities and migrations, then hands back a relation map with a migration plan. CX Codex ★ 234repo stars

Project sponsors

Companies that keep this analytics open