Skip to content

[Bug]: Parser confuses referenced models with same name #2333

@bodograumann

Description

@bodograumann

Description

When parsing an openapi spec (using resolve: true) that has models A referencing C from file1 and B referencing C from file2, it will use C from file1 for both A and B.

I have created a reproduction in openapi-generator here: OpenAPITools/openapi-generator@43f0c76, only noticing afterwards, that the bug lies with swagger-parser.

The downstream project uses the following code for parsing:

https://github.com/OpenAPITools/openapi-generator/blob/81115a094b2c80f9d23bc5a28d717d65ed043177/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java#L683-L687

        final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);
        ParseOptions options = new ParseOptions();
        options.setResolve(true);
        options.setResolveResponses(true);
        SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpec, authorizationValues, options);

Affected Version

2.1.41

Steps to Reproduce

Try to parse the following spec using resolve: true.

Main spec file

openapi: 3.0.3
info:
  title: Pet Store API
  version: 1.0.0
paths: {}
components:
  schemas:
    SomeItem:
      $ref: "inventory.yaml#/components/schemas/Pet"
    Pet:
      $ref: "pets.yaml#/components/schemas/Pet"

inventory.yaml

openapi: 3.0.3
info:
  title: Inventory API
  version: 1.0.0
paths: {}
components:
  schemas:
    Pet:
      type: object
      properties:
        name:
          type: string

pets.yaml

openapi: 3.0.3
info:
  title: Pets API
  version: 1.0.0
paths: {}
components:
  schemas:
    Pet:
      type: object
      properties:
        id:
          type: integer

Expected Behavior

SomeItem should include a name property and Pet should include an id property.

Actual Behavior

Both SomeItem and Pet use the same model Pet from inventory.yaml and contain the name attribute.

Environment

  • Java version: OpenJDK 11
  • Build tool: mvn 3.9.15
  • OS: Arch Linux

Checklist

  • I have searched the existing issues and this is not a duplicate.
  • I have provided sufficient information for maintainers to reproduce the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions