GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: External Refs with same name are ignored (#2055) by ewaostrowska · Pull Request #2382 · swagger-api/swagger-parser

Conversation

@ewaostrowska

@ewaostrowska ewaostrowska commented Aug 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Pull Request

Description

When two external files each define a component with the same local name (e.g., both expose a schema called limit), the parser was silently discarding the second definition and pointing both usages at the first. This caused incorrect, incomplete resolved documents that were hard to diagnose because no error or warning was emitted. The same problem applied to all component types (schemas, parameters, responses, request bodies, headers, security schemes, links, examples, callbacks).

What was broken

Same-name external components were merged into one, losing data:

// POST /a-path references external_ref_1.json#/limit  ("There can be only 1")
// PUT  /a-path references external_ref_2.json#/limit  ("There can be only 2")

// Before: both operations resolved to the same component; second definition was silently dropped
openAPI.getComponents().getParameters().size() == 1  // wrong — only "limit" present

// After: each distinct external ref gets its own key
openAPI.getComponents().getParameters().size() == 2  // ✓  "limit" + "limit_1"
post.getParameters().get(0).getDescription()  // "There can be only 1" ✓
put .getParameters().get(0).getDescription()  // "There can be only 2" ✓

What changed

  • ExternalRefProcessor — replaced the ad-hoc, per-type name-collision logic with a single call to ComponentNameAllocator.allocate(...). The old code had a different (buggy) implementation duplicated for every component type; the new code is a single loop that appends _N suffixes until a free or reusable slot is found.

  • ComponentNameAllocator (new class) — centralises name allocation for all OpenAPI component maps. Uses pluggable policies for key lookup (exact vs. case-insensitive), ref-equivalence (delegated to ResolverCache), and value-equality reuse. Schemas use case-insensitive key lookup (matching existing behaviour); all other component types use exact-case keys.


Fixes: #2055

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.

All reactions
@ewaostrowska
ewaostrowska force-pushed the issue-2055 branch from 870f802 to 587694b Compare August 18, 2026 13:23
@ewaostrowska

ewaostrowska commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

The solution maintains the different approach to the key sensitivity in between schema and non-schema components.

For schema component:
Pet and pet can be resolved to the same component

For non-schema component:
Pet and pet won't be resolved to the same component

I have decided to keep this separation as this would be a breaking change for the users and therefore if such appraoch is confirmed I would prefer to see it in a major version.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ewaostrowska
ewaostrowska requested review from daniel-kmiecik and djankows August 19, 2026 09:38
@ewaostrowska ewaostrowska mentioned this pull request Aug 19, 2026
Swagger parser fails to link correct external reference if it refers to a file with non-unique name #2143
Closed
djankows
djankows approved these changes Aug 19, 2026
View reviewed changes
@ewaostrowska
fix: External Refs with same name are ignored (#2055)
e5cf7a1
@ewaostrowska
ewaostrowska force-pushed the issue-2055 branch from 587694b to e5cf7a1 Compare August 20, 2026 10:58
@ewaostrowska
ewaostrowska merged commit f605c3c into master Aug 20, 2026
7 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ewaostrowska
ewaostrowska deleted the issue-2055 branch August 20, 2026 11:03
@jimshowalter jimshowalter mentioned this pull request Sep 3, 2026
[Bug]: Regression: resolveFully fails when components key does not match external file basename #2399
Open
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@djankows djankows djankows approved these changes
@daniel-kmiecik daniel-kmiecik Awaiting requested review from daniel-kmiecik

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

External Refs with same name are ignored

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ewaostrowska @djankows
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.