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

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

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
  1. Very specific:

    Add MaxDepth + enable_max_depth: true on circular relations.

    line 26
  2. Very specific:

    One group per direction: Never reuse product:read for writes.

    line 30
  3. Very specific:

    Sensitive fields out of every group: Use #[Ignore] for passwords, tokens, reset codes.

    line 31
  4. Very specific:

    BackedEnum for statuses: Never free string.

    line 32

≈ “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 — 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

  1. Define the read vs write groups (product:list, product:read, product:create, product:update).
  2. Apply #[Groups] on every exposed property with a deliberate scope.
  3. Force IRI on relations with #[ApiProperty(readableLink: false, writableLink: false)] unless embedding is explicitly required.
  4. Add MaxDepth + enable_max_depth: true on circular relations.
  5. For computed / role-dependent fields, decide: Context Builder (runtime), Mutator (build-time), or custom Normalizer.

Guardrails

  • One group per direction. Never reuse product:read for writes.
  • Sensitive fields out of every group. Use #[Ignore] for passwords, tokens, reset codes.
  • BackedEnum for statuses. Never free string.
  • hydra_prefix: false is the 4.x default — tests and clients consume member, totalItems, etc. without the hydra: prefix.
  • skip_null_values: true is the 4.x default — no more "field": null in responses.

Progressive disclosure

  • SKILL.md covers posture and decision tree.
  • reference.md carries 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 null properties leaking in the response (verify skip_null_values).

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.