swagger-api / swagger-api/swagger-ui

Multipart/form-data support for dynamic form form discriminator

Open
#7,418 3 comments 4 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

Content & configuration

If I configure a schema using a discriminator and oneOf, the form automatically generated is incomplete
image

Example of configuration:

openapi: 3.0.1
info:
  title: Unknown Service
  description: ''
  version: v1.0.1
paths:
  '/example':
    post:
      tags:
        - category
      summary: category.create
      description: not documented
      operationId: category.create
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ProductTypeFieldDef'
        required: true
      responses:
        '200':
          description: not documented

components:
  schemas:
    Str:
      required:
        - isRequired
        - name
        - validations
      type: object
      properties:
        regex:
          type: string
        name:
          type: string
        isRequired:
          type: boolean
        minLength:
          type: integer
          format: int32
        maxLength:
          type: integer
          format: int32
        type:
          type: string
          example: Str  
    Bool:
      required:
        - isRequired
        - name
        - validations
      type: object
      properties:
        name:
          type: string
        isRequired:
          type: boolean
        type:
          type: string
          example: Bool  
    ListItems:
      required:
        - isRequired
        - item
        - name
        - validations
      type: object
      properties:
        name:
          type: string
        isRequired:
          type: boolean
        maxSize:
          type: integer
          format: int32
        minSize:
          type: integer
          format: int32
        item:
          $ref: '#/components/schemas/ProductTypeFieldDef'
        type:
          type: string
          example: ListItems  
    ProductTypeFieldDef:
      allOf:
        - required:
            - isRequired
            - name
            - type
          type: object
          properties:
            isRequired:
              type: boolean
            name:
              type: string
        - discriminator:
            propertyName: type
          oneOf:
            - $ref: '#/components/schemas/ListItems'
            - $ref: '#/components/schemas/Bool'
            - $ref: '#/components/schemas/Str'
  
Is your feature request related to a problem?

No

Describe the solution you'd like
  1. I would like to have a select box to select one of the values of the discriminator
  2. I would like that dynamically show/hide the input, depending on the discriminator selected
Describe alternatives you've considered

I'm considering to implement it by myself, but if you guys could help with the places that i need to change would be very useful.

Additional context

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 with Swagger UI's dynamic form generation for the multipart/form-data schema in the issue's OpenAPI example, focusing on discriminator and oneOf handling. Trace how the form currently renders the ProductTypeFieldDef schema and identify existing tests for generated request forms. Done means a discriminator value selector changes the displayed inputs for each oneOf option and the behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.