GeezerVison is showing github.com — fix: Inlining of references with dot (#2109) by ewaostrowska · Pull Request #2384 · swagger-api/swagger-parser
Conversation
Pull Request
Description
InlineModelResolver.flatten() generated bare schema names (e.g. admin.user) instead of fully-qualified local references (#/components/schemas/admin.user) in every $ref it produced. For simple names this was harmless, but when a model title contained a dot the bare name admin.user was parsed as a relative file reference rather than a local component reference, breaking resolution.
The array-item case for request/response bodies was previously fixed in #2330. This PR applies the same prefix to all remaining paths.
Fix
Every call-site in InlineModelResolver that sets a $ref to an extracted schema now prepends Components.COMPONENTS_SCHEMAS_REF (#/components/schemas/) instead of a bare name.
Swagger Core's $ref setter skips the auto-prefix when the name contains a ., treating it as a potential relative file path. That's correct for resolve, where admin.user could legitimately refer to ./admin.user. In flatten, every schema being referenced has just been extracted into #/components/schemas/ by the resolver, so the target is always local.
Out of scope (known issues, not introduced by this PR)
-
Reporter of Getting invalid reference when used with flatten = true option #2109 uses example with a space admin.user schema . The spec requires component keys to match ^[a-zA-Z0-9\.\-_]+$. A space is not in that character class, so admin.user schema is not a valid component key.
-
InlineModelResolver.java:179-180 registers am (the array) instead of inner (the item schema). - such behavior is a non-reported bug
Fixes: #2109
Type of Change
- 🐛 Bug fix
- ✨ New feature
- ♻️ Refactor (non-breaking change)
- 🧪 Tests
- 📝 Documentation
- 🧹 Chore (build or tooling)
Checklist
- I have added/updated tests as needed
- I have added/updated documentation where applicable
- The PR title is descriptive
- The code builds and passes tests locally
- I have linked related issues (if any)
Screenshots / Additional Context
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
djankows
djankows approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.