Skip to content

Normalize relative ref paths to avoid duplicating schemas #2105

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

Open
wants to merge 4 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.

@ctreatma ctreatma force-pushed the collapse-equivalent-refs branch from 6f1d634 to 18d5450 Compare June 17, 2024 15:10
@nmarriotti
Copy link

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

@ctreatma ctreatma force-pushed the collapse-equivalent-refs branch 2 times, most recently from d25dc19 to e2fd955 Compare August 8, 2024 20:11
@ctreatma ctreatma force-pushed the collapse-equivalent-refs branch from e2fd955 to 8174b8f Compare December 20, 2024 17:08
@ctreatma
Copy link
Author

I rebased on the latest from master to confirm that the issue described in this PR still exists and that the changes in this PR are sufficient to resolve it.

@ctreatma ctreatma force-pushed the collapse-equivalent-refs branch 2 times, most recently from 47a4931 to 26e34ae Compare January 8, 2025 17:18
@ctreatma ctreatma force-pushed the collapse-equivalent-refs branch from 929aacc to 74720bc Compare January 17, 2025 17:20
ctreatma added a commit to equinix/equinix-sdk-go that referenced this pull request Feb 24, 2025
The semantic-release tool explicitly ignores the `.gitignore` file,
which means that the automated release process will commit all files
that are present in the local repo even if they are in the `.gitignore`.
This updates the Metal codegen task to explicitly clean up the temporary
merged spec. If swagger-api/swagger-parser#2105 gets merged and is
included in an openapi-generator release before this SDK loses support
for Metal, we can remove the temporary merged Metal spec.
@ctreatma ctreatma force-pushed the collapse-equivalent-refs branch from 74720bc to adcfebb Compare March 31, 2025 21:11
@ctreatma ctreatma force-pushed the collapse-equivalent-refs branch from adcfebb to 1cd8e74 Compare July 16, 2025 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants