Skip to content

fix(jsonapi): exclude relations from openapi attributes schema#8313

Open
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/8308-jsonapi-attributes-relations
Open

fix(jsonapi): exclude relations from openapi attributes schema#8313
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/8308-jsonapi-attributes-relations

Conversation

@soyuka

@soyuka soyuka commented Jun 16, 2026

Copy link
Copy Markdown
Member
Q A
Branch? 4.3
Tickets Fixes #8308
License MIT

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 under attributes. The attributes variant never appears in an actual JSON:API response, so the generated spec misrepresents the API. The buggy schema also exposes id where 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 $ref to the full resource schema:

-        $replacement['attributes']['properties'] = $attributes;
+        $replacement['attributes'] = ['$ref' => $currentRef];

buildDefinitionPropertiesSchema() already builds a correct $attributes array (relation properties skipped, id renamed to _id), but it became dead code. A second spot in the collection path re-applied the same full $ref.

Fix

  • Restore use of the built $attributes array for data.attributes.properties.
  • Drop the collection-path attributes.$ref override so collection items reuse the corrected item data schema.

Tests

  • New testRelationIsExcludedFromAttributes: relation absent from attributes, present in relationships; _id present, bare id absent.
  • Updated two pre-existing assertions that encoded the buggy $ref behavior.

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
@soyuka soyuka force-pushed the fix/8308-jsonapi-attributes-relations branch from 609ba15 to 454a259 Compare June 16, 2026 15:04
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