Forum Discussion

PavZav's avatar
PavZav
New Member
5 years ago

Swagger UI - OneOf with discriminator didn't show schema

Hi,

I'm trying this schema structure, but Swagger UI schema example don't show anything.

 

Simple example: 

openapi: 3.0.2
servers:
  - url: 'http://localhost:8080/'
    description: Test example
info:
  contact:
    email: some.email@address.cz
  title: Test discriminator example
  version: '0.0.1'
  license:
    name: TODO
    url: 'http://TODO.cz'
    
paths:
  '/example':
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/schema1Resp'
               
components:
  schemas:
    schema1Resp:
      type: object
      properties:
        data:
          oneOf:
            - $ref: '#/components/schemas/obj1Item'
            - $ref: '#/components/schemas/obj2Item'
          discriminator:
            propertyName: type
            mapping:
              obj1: '#/components/schemas/obj1Item'
              obj2: '#/components/schemas/obj2Item'

    obj1Item:
      type: object
      properties:
        type:
          type: string
          example: obj1
        firstTypeStructure:
          type: integer
          format: int32
          example: 123
          
    obj2Item:
      type: object
      properties:
        type:
          type: string
          example: obj1
        secondTypeStructure:
          type: string
          example: 'Some text'
          

Swagger UI - example value show nothing, but schema does.

 

Thans for yours help. :)

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi PavZav,

     

    Thanks for the report! The issue with oneOf/anyOf schema examples is tracked on GitHub here:

    https://github.com/swagger-api/swagger-ui/issues/3803

    You can subscribe to this issue to get notified when it's fixed.

     

    As a workaround, you can specify an example for the "data" property yourself:

            data:
              oneOf:
                - $ref: '#/components/schemas/obj1Item'
                - $ref: '#/components/schemas/obj2Item'
              discriminator:
                ...
              example:
                type: obj1
                firstTypeStructure: 123