swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
773 stars 525 forks source link

Normalize relative ref paths to avoid duplicating schemas #2105

Open ctreatma opened 2 weeks ago

ctreatma commented 2 weeks ago

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:

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.