cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger UI - OneOf with discriminator didn't show schema

New Member

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. Smiley Happy

1 REPLY 1
Moderator

Re: Swagger UI - OneOf with discriminator didn't show schema

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

Helen Kosova
SmartBear Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.
New Here?
Join us and watch the welcome video: