swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Duplicate Schema References in oneOf - OAS 3.1

Open bnasslahsen opened this issue 9 months ago • 0 comments

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'

bnasslahsen avatar Jan 11 '25 15:01 bnasslahsen