api-platform-serialization
Skill2 starsChanged 6 months agoMITView on GitHub
Master API Platform 4.3 serialization — design groups (`entity:operation` convention, read ≠ write), force IRI on relations with `#[ApiProperty(readableLink: false, writableLink: false)]`, prevent circular references with `MaxDepth`, use `BackedEnum` natively, apply `#[Context]` for per-property formats, install a Context Builder for dynamic role-based groups, decide between Context Builder (runtime) and Resource/Operation Mutators (build-time), and configure 4.x defaults (`hydra_prefix: false`, `skip_null_values: true`, `gen_id`). Trigger when adding `Groups`, mixing read/write, deciding between embed vs IRI, calculating fields in a normalizer, hiding fields by role, or debugging "why is my field null in the response".
In this repository52 other files it gives its agents.
- api-platform-dto-resourcesSkill
- 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-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
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Add MaxDepth + enable_max_depth: true on circular relations.
- Very specific: line 30
One group per direction: Never reuse product:read for writes.
- Very specific: line 31
Sensitive fields out of every group: Use #[Ignore] for passwords, tokens, reset codes.
- Very specific: line 32
BackedEnumfor statuses: 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 — Serialization
Use when
- Adding
#[Groups]to a resource or DTO. - Forcing relations to serialize as IRIs (or, exceptionally, embedded).
- Calculating fields without polluting the entity (custom normalizer).
- Adding admin-only or owner-only fields with a dynamic group.
- Tuning per-property date format / context with
#[Context].
Default workflow
- Define the read vs write groups (
product:list,product:read,product:create,product:update). - Apply
#[Groups]on every exposed property with a deliberate scope. - Force IRI on relations with
#[ApiProperty(readableLink: false, writableLink: false)]unless embedding is explicitly required. - Add
MaxDepth+enable_max_depth: trueon circular relations. - For computed / role-dependent fields, decide: Context Builder (runtime), Mutator (build-time), or custom Normalizer.
Guardrails
- One group per direction. Never reuse
product:readfor writes. - Sensitive fields out of every group. Use
#[Ignore]for passwords, tokens, reset codes. BackedEnumfor statuses. Never freestring.hydra_prefix: falseis the 4.x default — tests and clients consumemember,totalItems, etc. without thehydra:prefix.skip_null_values: trueis the 4.x default — no more"field": nullin responses.
Progressive disclosure
SKILL.mdcovers posture and decision tree.reference.mdcarries the full patterns: groups, MaxDepth, IRI forcing, BackedEnum,#[Context], custom Normalizer (ALREADY_CALLED pattern), conditional normalizer (Security-aware), Context Builder vs Mutator,gen_id, name converter,getValues()trick.
Output contract
- Resource / DTO with explicit per-property groups.
- Relations either IRI-only or embedded with a documented reason.
- Tests asserting the exact shape of the JSON-LD response.
- No
nullproperties leaking in the response (verifyskip_null_values).
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.

