Skip to content

fix(jsonschema): don't leak operation deprecation onto sub-schemas#8289

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:repro-7064
Jun 12, 2026
Merged

fix(jsonschema): don't leak operation deprecation onto sub-schemas#8289
soyuka merged 1 commit into
api-platform:4.3from
soyuka:repro-7064

Conversation

@soyuka

@soyuka soyuka commented Jun 11, 2026

Copy link
Copy Markdown
Member
Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Issues Closes #7064
License MIT

Problem

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.

Given a User resource with a deprecated Put, embedded as a property of a CustomUserAction (Post), the nested User schema in the OpenAPI docs got flagged deprecated (and dropped from Swagger UI) even though it's reached through the non-deprecated Post.

Cause

When a resource is embedded, SchemaFactory::buildSchema() recurses with operation = null and FORCE_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 deprecated Put. The deprecation flag at SchemaFactory:133 was 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 deprecated when 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.

  • The operation's own input schema (...-update) stays deprecated.
  • PATCH keeps its own distinct key (...-update.jsonMergePatch).
  • The embedded variant (...-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 asserts deprecated on a component schema (all deprecation assertions are path-level via OpenApiFactory or Hydra owl:deprecated).

Tests

Functional test in OpenApiTest with two fixtures reproducing the issue (deprecated Put resource embedded in a Post resource), asserting the nested component schema is present and not deprecated.

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
@soyuka soyuka merged commit ce4f6c2 into api-platform:4.3 Jun 12, 2026
112 checks passed
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.

1 participant