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.32k stars 8.91k forks source link

Polymorphism support [] #5806

Open ruioliveiras opened 4 years ago

ruioliveiras commented 4 years ago

I there, I'm doing an integration with Lagom Framework.

I already being able to generate OpenAPI definition, and it is working very well: Swagger definition

openapi: 3.0.1
info:
  title: ''
  description: description
  contact:
    name: ''
    url: ''
    email: cenas@dott.pt
  license:
    name: ''
    url: ''
  version: v0
paths:
  /example:
    post:
      tags:
        - Tag1
      summary: the brief1
      description: the notes
      operationId: method1
      parameters:
        - name: name
          in: query
          required: false
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BaseA'
        required: true
      responses:
        '200':
          description: the response brief
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/DataList'
                  - type: object
                    properties:
                      values:
                        type: array
                        items:
                          $ref: '#/components/schemas/BaseA1'
components:
  schemas:
    DataList:
      type: object
      properties:
        values:
          type: array
          items:
            type: object
        total:
          type: integer
          format: int32
    ServiceCall:
      type: object
    Example:
      type: object
      properties:
        name:
          type: string
    BaseA1:
      type: object
      properties:
        t:
          type: string
        a:
          type: integer
          format: int64
    BaseA2:
      type: object
      properties:
        t:
          type: string
        a2:
          type: string
        a22:
          type: string
    BaseA:
      allOf:
        - type: object
          properties:
            t:
              type: string
        - oneOf:
           - $ref: '#/components/schemas/BaseA1'
           - $ref: '#/components/schemas/BaseA2'
        - discriminator:
            propertyName: type

Screenshots

My current problem, is because is difficult call APIs that use polymorphic payload (the POST:/example with request payload #/components/schemas/BaseA ) The Swagger UI don't help creating this polymorphic payload ... it only present property 't' image

How can we help?

What is the best way to represent this polymorphic payloads?

Thanks in advance, i would appreciate help, In the future i could open-source this integration LAGOM <-> SWAGGER

ruioliveiras commented 4 years ago

I think I will solve my problem with multiple examples: One example per implementation examples: BaseA1: value: ... BaseA2: value: ...