Skip to content

fix: resolve $ref inside allOf of unreferenced component schemas#2367

Open
seonwooj0810 wants to merge 1 commit into
swagger-api:masterfrom
seonwooj0810:fix/issue-2270-resolvefully-components
Open

fix: resolve $ref inside allOf of unreferenced component schemas#2367
seonwooj0810 wants to merge 1 commit into
swagger-api:masterfrom
seonwooj0810:fix/issue-2270-resolvefully-components

Conversation

@seonwooj0810

Copy link
Copy Markdown

Fixes #2270

Root cause

ResolverFully.resolveFully(OpenAPI) copies the component maps into its internal fields but then only iterates openAPI.getPaths() to drive resolution. Any component schema that is not reachable through a path is therefore never resolved — so a $ref nested inside the allOf of such a component schema stays unresolved even when resolveFully(true) is set (as reported, and confirmed by a second user).

Change

After walking the paths, also resolve the captured component schemas. resolveSchema(...) is backed by an IdentityHashMap cache and an in-progress guard, so component schemas already resolved while walking the paths are returned as-is — no double resolution, and recursive/self-referential schemas are safe.

Tests

Added Issue2270Test + issue-2270/openapi.yaml: a spec with empty paths and a component Contact = allOf: [ $ref SObject, {inline} ]. The test asserts that after resolveFully(true) the inner $ref is resolved (gone, with SObject's properties inlined). It fails before this change (expected null, but was: #/components/schemas/SObject) and passes after.

Verification done

  • Reproduced the bug on master with the new test (fails before the fix, passes after).
  • Ran the full swagger-parser-v3 module test suite: 610 tests, 0 failures, 0 errors (mvn -pl modules/swagger-parser-v3 test).

Note for reviewers

Previously-unreferenced component schemas now get resolved by resolveFully, which is the intended meaning of the option, but it is a visible output change for any consumer that relied on such components staying in raw $ref/allOf form. Not covered by any prior test, so flagging it explicitly.

ResolverFully.resolveFully() only walked the paths object, so component
schemas that are not reachable through any path were never resolved. A
$ref nested inside the allOf of such a component schema was left
unresolved even with resolveFully(true).

Resolve the captured component schemas after walking the paths.
resolveSchema is cached, so schemas already resolved via a path are
returned as-is and never resolved twice.
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.

[Bug]: allOf reference not resolved fully

1 participant