Skip to content

Fix embedded ID relation response schemas - #3334

Merged
bnasslahsen merged 2 commits into
springdoc:mainfrom
exijn:issue-3136-embedded-id-schema
Sep 6, 2026
Merged

Fix embedded ID relation response schemas#3334
bnasslahsen merged 2 commits into
springdoc:mainfrom
exijn:issue-3136-embedded-id-schema

Conversation

@exijn

@exijn exijn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Convert nested response references for non-exported Spring Data REST associations to response schemas.
  • Preserve embedded ID scalar properties while preventing association objects from being expanded in read response schemas.
  • Add a minimal @EmbeddedId/@MapsId regression fixture and compare the complete generated OpenAPI 3.1 document with a golden file.

Root cause

SpringDocDataRestUtils rewrote top-level and _embedded entity response references, but did not rewrite associations to entities that were not themselves exported as repositories. Those properties retained the raw ModelConverters schema, which expanded the @EmbeddedId and @MapsId association fields recursively.

Compatibility

The change is limited to non-exported Spring Data REST association properties in generated response schemas. Existing exported relation handling, request schemas, and relation-free embeddables remain unchanged.

Testing

  • mvn -pl springdoc-openapi-tests/springdoc-openapi-data-rest-tests -am -Dtest=SpringDocApp40Test '-Dsurefire.failIfNoSpecifiedTests=false' test
  • mvn -pl springdoc-openapi-tests/springdoc-openapi-data-rest-tests -Dtest=SpringDocApp40Test '-Dsurefire.failIfNoSpecifiedTests=false' test
  • mvn -pl springdoc-openapi-tests/springdoc-openapi-data-rest-tests test (79 tests pass)
  • mvn install (the reactor reached springdoc-openapi-javadoc-tests, where existing Javadoc golden-output tests fail because descriptions, summaries, and tags are missing; the targeted app40 test and data REST module pass)

Fixes #3136

@bnasslahsen
bnasslahsen merged commit 373e5ea into springdoc:main Sep 6, 2026
1 check failed
bnasslahsen added a commit that referenced this pull request Sep 6, 2026
Spring Data REST serializes associations to entities that are not
themselves exported as repositories inside the containing
representation. SpringDocDataRestUtils rewrote only top-level and
_embedded entity references, so those properties kept the raw
ModelConverters schema and expanded their @EmbeddedId and @mapsid
association fields recursively.

Backport of #3334 to the Spring Boot 3 line, with the OAS 3.0 variant
of the regression test added: the two versions take different branches
when the _embedded items schema is resolved, JsonSchema for 3.1 and
ArraySchema for 3.0.

Fixes #3136

Co-Authored-By: 한의준 <exijn@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bnasslahsen added a commit that referenced this pull request Sep 6, 2026
…schemas

Fix embedded ID relation response schemas (backport of #3334)
@bnasslahsen

Copy link
Copy Markdown
Collaborator

Merged, thank you.

I added two things on top of your change:

  • v30/app40. Your regression test covers OAS 3.1 only, and the two versions take different branches when the _embedded items schema is resolved — JsonSchema for 3.1, ArraySchema for 3.0 — so the 3.0 path was untested. Reverting the fix makes the new test fail on components.schemas.Goal.properties.impactsByInitiatives.items.$ref and on the same property of EntityModelGoal, which is exactly the recursive expansion described in Incorrect schema/example with @EmbeddedId + relations (Spring Data REST) #3136.
  • allAssociationsFieldsMap.getOrDefault(className, …) in updateResponseSchema, so an entity that reaches it without having been registered in the map cannot raise a NullPointerException.

Backported to spring-boot-3 in 998a254, adapted to that branch's Set<String> signatures and with its own golden files (spring-hateoas emits a different Link schema there).

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.

Incorrect schema/example with @EmbeddedId + relations (Spring Data REST)

3 participants