Skip to content

[Bug]: Superfluous sibling $ref when using oneOf in Schema annotation - OAS 3.1 #4959

@bostrom

Description

@bostrom

Description of the problem/issue

Using oneOf in an OAS 3.1 @Schema annotation results in an additional $ref in the root of the property.

This happens both when using two classes, and with one class, and allowing null as property value.

Expected behaviour is that $refs would only be used inside the oneOf array.

Affected Version

2.2.36

Steps to Reproduce

Allowing myProperty to be one of two classes:

Using:

    @Schema(oneOf = {SomeDto.class, OtherDto.class})

Actual outcome:

components:
  schemas:
    MyDto:
      type: object
      properties:
        myProperty:
          $ref: "#/components/schemas/SomeDto"
          oneOf:
            - $ref: "#/components/schemas/SomeDto"
            - $ref: "#/components/schemas/OtherDto"

Expected outcome:

components:
  schemas:
    MyDto:
      type: object
      properties:
        myProperty:
          oneOf:
            - $ref: "#/components/schemas/SomeDto"
            - $ref: "#/components/schemas/OtherDto"

Allowing myProperty to be a class or null:

Using:

    @Schema(oneOf = {SomeDto.class}, types = {"object", "null"})

Actual outcome:

components:
  schemas:
    MyDto:
      type: object
      properties:
        myProperty:
          type:
            - object
            - "null"
          $ref: "#/components/schemas/SomeDto"
          oneOf:
            - $ref: "#/components/schemas/SomeDto"

Expected outcome:

components:
  schemas:
    MyDto:
      type: object
      properties:
        myProperty:
          type:
            - object
            - "null"
          oneOf:
            - $ref: "#/components/schemas/SomeDto"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions