fix(jsonapi): exclude relations from openapi attributes schema#8313
Open
soyuka wants to merge 1 commit into
Open
fix(jsonapi): exclude relations from openapi attributes schema#8313soyuka wants to merge 1 commit into
soyuka wants to merge 1 commit into
Conversation
Relation properties were documented twice in the generated JSON:API OpenAPI schema: correctly under `relationships`, and incorrectly as full nested objects under `attributes`. The `attributes` variant never appears in a real JSON:API response. Regression from 79edced which replaced the relation-excluding attributes array with a blanket `$ref` to the full resource schema. Restore the built `$attributes` array (relations skipped, `id` renamed to `_id`) and drop the collection-path `$ref` override that re-leaked relations. Fixes api-platform#8308
609ba15 to
454a259
Compare
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.
Problem
For resources using the JSON:API format, the generated OpenAPI schema documents relation properties twice: correctly as resource linkage under
relationships, and incorrectly as a full nested object underattributes. Theattributesvariant never appears in an actual JSON:API response, so the generated spec misrepresents the API. The buggy schema also exposesidwhere a real response exposes_id.Root cause
Regression from 79edced ("fix(json-schema): share invariable sub-schemas", shipped in 4.2.0). It replaced the relation-excluding attributes array with a blanket
$refto the full resource schema:buildDefinitionPropertiesSchema()already builds a correct$attributesarray (relation properties skipped,idrenamed to_id), but it became dead code. A second spot in the collection path re-applied the same full$ref.Fix
$attributesarray fordata.attributes.properties.attributes.$refoverride so collection items reuse the corrected itemdataschema.Tests
testRelationIsExcludedFromAttributes: relation absent fromattributes, present inrelationships;_idpresent, bareidabsent.$refbehavior.