fix(jsonschema): don't leak operation deprecation onto sub-schemas#8289
Merged
Conversation
A deprecated write operation (e.g. a Put with a deprecationReason) marked the embedded resource's component schema as `deprecated: true` whenever that resource was reused as a property of another resource. The sub-schema is built with a guessed operation under FORCE_SUBSCHEMA, so it inherited deprecation that belongs to the operation/path, not to the resource shape embedded elsewhere. Only set `deprecated` when the operation was explicitly provided or the schema is not a forced sub-schema. The operation's own input schema stays deprecated; the embedded variant no longer does. Closes api-platform#7064
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
A deprecated write operation (e.g. a
Putwith adeprecationReason) marked the embedded resource's component schema asdeprecated: truewhenever that resource was reused as a property of another resource.Given a
Userresource with a deprecatedPut, embedded as a property of aCustomUserAction(Post), the nestedUserschema in the OpenAPI docs got flagged deprecated (and dropped from Swagger UI) even though it's reached through the non-deprecatedPost.Cause
When a resource is embedded,
SchemaFactory::buildSchema()recurses withoperation = nullandFORCE_SUBSCHEMA.ResourceMetadataTrait::findOperation()then guesses an operation: for an input sub-schema,findOperationForType()picks the first operation whose method is in[POST, PATCH, PUT]— here the deprecatedPut. The deprecation flag atSchemaFactory:133was then stamped onto a sub-schema that was never built for that operation.Note the output path already behaved correctly (the guessed operation is blanked), so only input sub-schemas leaked.
Fix
Only set
deprecatedwhen the operation was explicitly provided, or when the schema is not a forced sub-schema. Deprecation belongs to the operation/path, not to a resource shape embedded elsewhere....-update) staysdeprecated.PATCHkeeps its own distinct key (...-update.jsonMergePatch)....-custom_update) is no longer deprecated.No change to operation selection (
findOperationForType), so generated schema names/content are unchanged — minimal BC impact. No existing test assertsdeprecatedon a component schema (all deprecation assertions are path-level viaOpenApiFactoryor Hydraowl:deprecated).Tests
Functional test in
OpenApiTestwith two fixtures reproducing the issue (deprecatedPutresource embedded in aPostresource), asserting the nested component schema is present and not deprecated.