Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize relative ref paths to avoid duplicating schemas #2105

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ctreatma
Copy link

@ctreatma ctreatma commented Jun 17, 2024

Currently, if an OpenAPI spec contains multiple relative refs to the same file, but those refs are located in different files and use different relative paths to reach the one file, swagger-parser will create a separate, duplicate schema for each relative path rather than reusing the same schema across all equivalent paths.

For example, given a spec with the following refs:

  • In spec root directory, $ref: ./components/schemas/Thing.yaml
  • In components/paths subdirectory, $ref: ../../components/schemas/Thing.yaml

The parser will produce a Thing and a Thing_1 schema object instead of reusing Thing for the second, equivalent reference.

This updates the ref processor to resolve relative paths before processing relative refs in order to produce a single Thing schema that is reused for all equivalent references.

Fixes #2016, fixes #1518, and maybe others.

@nmarriotti
Copy link

Just ran into this issue today. Glad to see a fix is on the way (hopefully soon). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants