Skip to content

Duplicated schemas produced when shared schema references local schema #1961

Closed

Description

@AmateurECE

Consider the following schemas:

TestCase.yaml:

components:
  schemas:
    TestCase_TestCase:
      anyOf:
      - $ref: ./TestCase.v1.yaml#/components/schemas/TestCase_v1_TestCase
    TestCase_Foo:
      properties:
        FooTypes:
          items:
            $ref: ./TestCase.yaml#/components/schemas/TestCase_FooType
          type: array
      type: object
    TestCase_FooType:
      enum:
      - All
      - OEM
      type: string
info:
  title: '#TestCase.TestCase'
openapi: 3.0.1

TestCase.v1.yaml:

components:
  schemas:
    TestCase_v1_TestCase:
      properties:
        Foo:
          $ref: ./TestCase.yaml#/components/schemas/TestCase_Foo
      type: object
info:
  title: '#TestCase.v1.TestCase'
openapi: 3.0.1

While parsing TestCase.yaml, swagger-parser produces a duplicate schema, TestCase_Foo_1. The path of logic that introduces the duplicate schema begins at ExternalRefProcessor.java:60, where the comparison fails because newSchema.properties.get("FooTypes").items.$ref is "./TestCase.yaml#/components/schemas/TestCase_FooType", while in existingModel it's "#/components/schemas/TestCase_FooType". I'm hoping to either bring this issue to light so that the maintainers can implement a fix, or suggest a fix that I can implement and submit a pull request for. I'm open to either!

This behavior is present at the HEAD of master (currently 2.0.17-SNAPSHOT, #08a76302e250), and as far back as 2.0.11. Unfortunately, I can't test with releases pre-2.0.11.

Activity

  1. changed the title [-]Duplicated schemas produced when referenced locally and externally[/-] [+]Duplicated schemas produced when shared schema references local schema[/+] on Aug 15, 2023
  2. AmateurECE commented on Dec 21, 2023

    @AmateurECE
    ContributorAuthor

    Hi there! Has anyone from the team had a chance to review this pull request yet? Thanks very much for your consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions