fix(jsonschema): embed relations of non-resource objects in output schema#8294
Open
alexisLefebvre wants to merge 1 commit into
Open
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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$refin the generated JSON Schema, instead of being typed as aniri-referencestring.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 theirreadableLinkorgen_id.SchemaPropertyMetadataFactorydecided embed-vs-IRI per property and, for such a relation (defaultreadableLink: false, and a real IRI sogen_idis notfalse), emitted aniri-referencestring. 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'sstructuredContentagainst its advertisedoutputSchema, where an embeddedOrderItem.supplierobject 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
readableLinkand are unaffected — covered by an added test that pins a resource parent toiri-reference.