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 1 commit into
base: master
Choose a base branch
from

Conversation

ctreatma
Copy link

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.

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.
@@ -0,0 +1,12 @@
description: |-
Copy link
Author

@ctreatma ctreatma Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a pinch, I added the entire impacted spec as a test resource, but I need to trim it down to just the parts necessary for the new test.

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

Successfully merging this pull request may close these issues.

None yet

1 participant