fix: external schema resolution in OAS 3.1 files#2272
Open
dennisameling wants to merge 3 commits intoswagger-api:masterfrom
Open
fix: external schema resolution in OAS 3.1 files#2272dennisameling wants to merge 3 commits intoswagger-api:masterfrom
dennisameling wants to merge 3 commits intoswagger-api:masterfrom
Conversation
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.
Description
When parsing OpenAPI 3.1 specifications with external schema references (e.g.,
$ref: "./schemas/health.yaml"), the parser resolves the schemas correctly but does not add them tocomponents.schemas. This causesopenAPI.getComponents().getSchemas()to return null (as reported in #2266), breaking downstream tooling like code generators that rely on component schemas being populated.This works correctly for OpenAPI 3.0 specs (via
SchemaProcessor/ExternalRefProcessor) but was missing in the OpenAPI 3.1 code path (OpenAPI31Traverser).OpenAPI31Traverser.traverseSchema()handles local refs (starting with#) by adding them tocomponents.schemas, but has no equivalent logic for external refs. External schemas are resolved and inlined during traversal, but never registered as components.Updated behavior for
setResolve(true)Before: External schemas were resolved and inlined directly at the usage site.
components.schemaswas not populated with external schemas.After: External schemas are added to
components.schemasand replaced with local $refs (e.g.,$ref: "#/components/schemas/ex"). The schema content now lives in components instead of being inlined.Fixed behavior for
setResolveFully(true)Before: External schemas were resolved and inlined. components.schemas was not populated.
After: External schemas are added to components.schemas and still inlined at usage sites (because ResolverFully expands all remaining $refs afterward).
Fixes: #2266
Type of Change
Checklist
Screenshots / Additional Context