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

Duplicate Schema References in oneOf - OAS 3.1 #4822

Open
bnasslahsen opened this issue Jan 11, 2025 · 0 comments
Open

Duplicate Schema References in oneOf - OAS 3.1 #4822

bnasslahsen opened this issue Jan 11, 2025 · 0 comments

Comments

@bnasslahsen
Copy link

Environment:

  • swagger-core version: 2.2.27
  • OAS version: OAS 3.1

Given the Following Class Definition:

class MyModel {

    @Schema(description = "Hello", type = "object", oneOf = { Foo.class, Bar.class })
    @JsonProperty
    private Object thing;

    class Bar {
        private String bar;
    }

    class Foo {
        @JsonProperty
        private String foo;
    }
}

Current Result:

The generated OpenAPI specification includes duplicate entries in the oneOf construct for the thing property:

components:
  schemas:
    Bar:
      type: object
      description: The type Bar.
      properties:
        bar:
          type: string
          description: The Bar.
    Foo:
      type: object
      description: The type Foo.
      properties:
        foo:
          type: string
          description: The Foo.
    MyModel:
      type: object
      description: The type My model.
      properties:
        thing:
          type: object
          description: Hello
          oneOf:
            - $ref: '#/components/schemas/Foo'
            - $ref: '#/components/schemas/Bar'
            - $ref: '#/components/schemas/Foo'  **# Duplicate**
            - $ref: '#/components/schemas/Bar'  **# Duplicate**

Expected Result:

The oneOf construct should only include unique schema references without duplicates:

components:
  schemas:
    Bar:
      type: object
      description: The type Bar.
      properties:
        bar:
          type: string
          description: The Bar.
    Foo:
      type: object
      description: The type Foo.
      properties:
        foo:
          type: string
          description: The Foo.
    MyModel:
      type: object
      description: The type My model.
      properties:
        thing:
          type: object
          description: Hello
          oneOf:
            - $ref: '#/components/schemas/Foo'
            - $ref: '#/components/schemas/Bar'
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

No branches or pull requests

1 participant