Skip to content

fix(jsonschema): embed relations of non-resource objects in output schema#8294

Merged
soyuka merged 1 commit into
api-platform:4.3from
alexisLefebvre:fix-jsonschema-embed-non-resource-relations
Jun 13, 2026
Merged

fix(jsonschema): embed relations of non-resource objects in output schema#8294
soyuka merged 1 commit into
api-platform:4.3from
alexisLefebvre:fix-jsonschema-embed-non-resource-relations

Conversation

@alexisLefebvre

Copy link
Copy Markdown
Contributor
Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT
Doc PR -

What

On output, a relation declared on a non-resource object (e.g. a Doctrine entity embedded as a readable link, but not itself an #[ApiResource]) is now embedded as a $ref in the generated JSON Schema, instead of being typed as an iri-reference string.

Why

A non-resource object is serialized by Symfony's standard object normalizer — AbstractItemNormalizer::supportsNormalization() only handles resource classes — which embeds its related resources as full objects regardless of their readableLink or gen_id. SchemaPropertyMetadataFactory decided embed-vs-IRI per property and, for such a relation (default readableLink: false, and a real IRI so gen_id is not false), emitted an iri-reference string. The advertised schema therefore diverged from the actual payload, and a strict JSON Schema client rejected it (for instance an MCP client validating a tool's structuredContent against its advertised outputSchema, where an embedded OrderItem.supplier object failed {type: string, null}).

The fix mirrors the serializer at the single factory that owns the decision: on output, when the parent class is not a resource, treat its resource relations as embedded. Relations on resource DTOs keep following their own readableLink and are unaffected — covered by an added test that pins a resource parent to iri-reference.

…hema

On output, a non-resource object is serialized by the standard object
normalizer, which embeds its related resources regardless of readableLink
or gen_id, while schema generation typed them as iri-reference strings.
Treat resource relations of a non-resource parent as embedded on output
so the advertised schema matches the payload.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@soyuka soyuka merged commit 9e18fe0 into api-platform:4.3 Jun 13, 2026
110 of 112 checks passed
@alexisLefebvre alexisLefebvre deleted the fix-jsonschema-embed-non-resource-relations branch June 13, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants