swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.29k stars 8.91k forks source link

Wrong oneOf value when used with allOf in the same hierarchy #5818

Open ngirot opened 4 years ago

ngirot commented 4 years ago

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.0
info:
  version: 0.0.0
  title: test

paths: {}

components:
  schemas:

    Rich:
      type: object
      properties:
        bank_account:
          type: string

    Pet:
      type: object
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
      oneOf:
        - $ref: '#/components/schemas/Cat'
        - $ref: '#/components/schemas/Dog'
        - $ref: '#/components/schemas/RichDog'

    RichDog:
      type: object
      allOf:
        - $ref: '#/components/schemas/Rich'
        - $ref: '#/components/schemas/Dog'

    Dog:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            breed:
              type: string
              enum: [Dingo, Husky, Retriever, Shepherd]

    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            age:
              type: integer

Describe the bug you're encountering

When I try to use both anyOf and oneOf, the generated ui mix up the oneOf into a wrong type.

To reproduce...

Steps to reproduce the behavior: Use the yaml below in the online editor, having 4 types :

Then the Dog type contains a OneOf with all its sibling types and itself (Cat, Dog and RichDog).

Expected behavior

Not to see a wrong oneOf value in the Dog type.

Screenshots

screenshot

DennyBoy1989 commented 4 years ago

I have the same issue. Interestingly, this wrong "oneOf" property is not inlcuded again, if you would for example extend the "Cat" model block in your screenshot or if you open the "Pet" model definiton and click on "Cat". When I generated Java Classes from that schema, he got the hierarchical dependency right, so I think the defintion itself should be correct.