swagger-api / swagger-api/swagger-ui

Polymorphism support []

Open
#5,806 1 comment 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the request-body rendering in Swagger UI with the provided OpenAPI 3.0.1 definition, focusing on BaseA, its oneOf schemas, and the discriminator. Review how the UI currently presents the polymorphic payload and define completion as exposing a usable way to select and construct BaseA1 or BaseA2 data.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.