Skip to content

RelationFieldSchemaDecorator applies the root class's relation hints to foreign definitions #11

Open

Description

@schmunk42

Problem

RelationFieldSchemaDecorator::buildSchema() walks every entry of $schema->getDefinitions() and decorates iri-reference properties using the Doctrine metadata of the root $className — without checking which class a definition actually belongs to.

As far as I can tell, API Platform's OpenApiFactory builds all operations into one shared definitions object. If that holds, each buildSchema() call re-decorates every definition collected so far, not just the ones embedded in the current resource:

  • two resources with a same-named relation (parent, owner, menu, …) pointing at different targets → array_merge() overwrites the hints, and whichever class was built last wins
  • a definition of resource B gets x-collection / x-resource-class from resource A's association

The behaviour predates #10, but #10 runs the decorator for output schemas too, so it now affects more definitions.

Impact

Proposal

  • resolve the class per definition instead of using the root class — e.g. only decorate the definition(s) the current buildSchema() call produced (diff the definition keys before/after the decorated call), or map the definition key back to its resource short name
  • skip a property that already carries x-collection (explicit configuration and earlier, correct decoration win)
  • add a unit test with a mocked SchemaFactoryInterface: two classes, same relation name, different targets → each definition keeps its own hints

Acceptance

  • every iri-reference property carries hints derived from the class that owns it
  • covered by a test

Activity

  1. self-assigned this
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions