fix: resolve $ref inside allOf of unreferenced component schemas#2367
Open
seonwooj0810 wants to merge 1 commit into
Open
fix: resolve $ref inside allOf of unreferenced component schemas#2367seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
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.
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.
Fixes #2270
Root cause
ResolverFully.resolveFully(OpenAPI)copies the component maps into its internal fields but then only iteratesopenAPI.getPaths()to drive resolution. Any component schema that is not reachable through a path is therefore never resolved — so a$refnested inside theallOfof such a component schema stays unresolved even whenresolveFully(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 anIdentityHashMapcache 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 emptypathsand a componentContact = allOf: [ $ref SObject, {inline} ]. The test asserts that afterresolveFully(true)the inner$refis resolved (gone, withSObject's properties inlined). It fails before this change (expected null, but was: #/components/schemas/SObject) and passes after.Verification done
swagger-parser-v3module 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/allOfform. Not covered by any prior test, so flagging it explicitly.