agentleFS
gerard-labsgerard-labs/superpowers-api-platform/skills/api-platform-dto-resources/SKILL.md

api-platform-dto-resources

Skill2 starsChanged 6 months agoMITView on GitHub

Introduce Input/Output DTOs in API Platform 4.3 to decouple the API contract from the Doctrine entity, validate at the boundary, force IRI-only relations (no scalar IDs), and use BackedEnum natively. Covers the new Symfony Object Mapper 4.3 integration (`#[Map]`, ObjectMapperProvider/Processor) for boilerplate-free DTO ↔ Entity mapping on simple CRUDs. Trigger when the API contract diverges from the entity, when validation rules differ per operation, when a price/money/enum needs explicit boundaries, or when "decouple my entity from the API".

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test the contract: 201 with the right shape, 422 on invalid payload, IRI resolution.

    line 25
  2. Very specific:

    Always type relations as Resources (Customer $customer), never scalar IDs.

    line 29
  3. Very specific:

    Use BackedEnum for any status / type / category — never free string.

    line 30

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Platform 4.3 — Input/Output DTOs (+ Object Mapper 4.3)

Use when

  • The API contract should not be a one-to-one reflection of the Doctrine entity.
  • Validation rules differ per operation (CreateOrderInput vs UpdateOrderInput).
  • The contract needs IRI-only relations and BackedEnum statuses.
  • A simple CRUD could benefit from the new Symfony Object Mapper 4.3 to skip Provider/Processor boilerplate.

Default workflow

  1. Decide: pure DTO (full Provider/Processor) or Object Mapper 4.3 (when mapping is mechanical).
  2. Define Input and Output DTOs as final readonly with Symfony validator attributes.
  3. Wire them on the operation (input:, output:, processor: / provider:) — or annotate with #[Map] if using Object Mapper.
  4. Test the contract: 201 with the right shape, 422 on invalid payload, IRI resolution.

Guardrails

  • DTOs hold no business logic — just validated transport.
  • Always type relations as Resources (Customer $customer), never scalar IDs.
  • Use BackedEnum for any status / type / category — never free string.
  • Object Mapper 4.3 is for mechanical mapping only. Persistence logic, aggregation, side effects → keep an explicit Processor.

Progressive disclosure

  • SKILL.md lists the decision and the four steps.
  • reference.md covers the full DTO patterns + Object Mapper 4.3 (#[Map(source:)], transformers, when it auto-activates).

Output contract

  • New final readonly Input/Output classes.
  • The #[ApiResource] operation wired with the right input / output / processor / provider (or #[Map] annotations).
  • Validation + IRI-resolution coverage in functional tests.

References

  • reference.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.