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".
In this repository52 other files it gives its agents.
- api-platform-errorsSkill
- api-platform-file-uploadSkill
- api-platform-filtersSkill
- api-platform-identifiersSkill
- api-platform-mcpSkill
- api-platform-mutatorsSkill
- api-platform-openapiSkill
- api-platform-paginationSkill
- api-platform-performanceSkill
- api-platform-resilienceSkill
- api-platform-resourcesSkill
- api-platform-securitySkill
- api-platform-serializationSkill
- api-platform-state-processorsSkill
- api-platform-state-providersSkill
- api-platform-testsSkill
- api-platform-upgradeSkill
- api-platform-userSkill
- api-platform-versioningSkill
- bootstrap-checkSkill
- brainstormingSkill
- config-env-parametersSkill
- controller-cleanupSkill
- cqrs-and-handlersSkill
- daily-workflowSkill
- doctrine-batch-processingSkill
- doctrine-fetch-modesSkill
- doctrine-fixtures-foundrySkill
- doctrine-migrationsSkill
- doctrine-relationsSkill
- doctrine-transactionsSkill
- effective-contextSkill
- executing-plansSkill
- functional-testsSkill
- interfaces-and-autowiringSkill
- makefile-disciplineSkill
- messenger-retry-failuresSkill
- ports-and-adaptersSkill
- quality-checksSkill
- rate-limitingSkill
- runner-selectionSkill
- strategy-patternSkill
- symfony-cacheSkill
- symfony-messengerSkill
- symfony-schedulerSkill
- symfony-votersSkill
- tdd-with-pestSkill
- tdd-with-phpunitSkill
- test-doubles-mockingSkill
- using-symfony-superpowersSkill
- value-objects-and-dtosSkill
- writing-plansSkill
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
- Distinctive: line 25
Test the contract: 201 with the right shape, 422 on invalid payload, IRI resolution.
- Very specific: line 29
Always type relations as Resources (Customer $customer), never scalar IDs.
- Very specific: line 30
Use BackedEnum for any status / type / category — never free string.
≈ “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.
Files
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 (
CreateOrderInputvsUpdateOrderInput). - The contract needs IRI-only relations and
BackedEnumstatuses. - A simple CRUD could benefit from the new Symfony Object Mapper 4.3 to skip Provider/Processor boilerplate.
Default workflow
- Decide: pure DTO (full Provider/Processor) or Object Mapper 4.3 (when mapping is mechanical).
- Define
InputandOutputDTOs asfinal readonlywith Symfony validator attributes. - Wire them on the operation (
input:,output:,processor:/provider:) — or annotate with#[Map]if using Object Mapper. - 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
BackedEnumfor any status / type / category — never freestring. - Object Mapper 4.3 is for mechanical mapping only. Persistence logic, aggregation, side effects → keep an explicit Processor.
Progressive disclosure
SKILL.mdlists the decision and the four steps.reference.mdcovers the full DTO patterns + Object Mapper 4.3 (#[Map(source:)], transformers, when it auto-activates).
Output contract
- New
final readonlyInput/Output classes. - The
#[ApiResource]operation wired with the rightinput/output/processor/provider(or#[Map]annotations). - Validation + IRI-resolution coverage in functional tests.
References
reference.md
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
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.

