Skip to content

Duplicate Schema References in oneOf - OAS 3.1 #4822

Open
@bnasslahsen

Description

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'

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