swagger-api / swagger-api/swagger-ui

Rendering nested object in multipart/form-data request "try it out" shows JSON vs form UI fields

Open
#7,672 13 comments 24 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cat: user experience needs: UX/design input pull-request-welcome
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: macOS
  • Browser: chrome
  • Version: 95.0.4638.69
  • Method of installation: non, using online version https://editor.swagger.io/
  • Swagger-UI version: [e.g. 3.10.0]
  • Swagger/OpenAPI version: OpenAPI 3.0.3

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
    title: 'My API'
    version: 3.0.0
servers: []
paths:
    /api_app:
        post:
            operationId: apiAppCreate
            requestBody:
                content:
                    multipart/form-data:
                        schema:
                            $ref: '#/components/schemas/ApiAppCreateRequest'
            responses:
                '200':
                    description: 'success'
                    content:
                        application/json:
                            schema: {}
components:
    schemas:
        ApiAppCreateRequest:
            properties:
                oauth:
                  type: object
                  properties:
                      callback_url:
                          type: string
                          example: 'https://example.com/oauth'
                      scopes:
                          type: array
                          items:
                              type: string
                          example:
                              - basic_account_info
                              - request_signature
            type: object
Describe the bug you're encountering

When a component schema is defined that has another object nested inside of it, the UI shows JSON instead of form fields in the "try it out" page.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io/
  2. Paste the above example
  3. Click on POST /api_app
  4. Click "Try it out"
  5. See JSON:

2021-11-24-111403

Expected behavior

I believe nested objects should be represented with UI fields like any other root-level field. For example, if I move callback_url and scopes into the top-level of ApiAppCreateRequest:

openapi: 3.0.3
info:
    title: 'My API'
    version: 3.0.0
servers: []
paths:
    /api_app:
        post:
            operationId: apiAppCreate
            requestBody:
                content:
                    multipart/form-data:
                        schema:
                            $ref: '#/components/schemas/ApiAppCreateRequest'
            responses:
                '200':
                    description: 'success'
                    content:
                        application/json:
                            schema: {}
components:
    schemas:
        ApiAppCreateRequest:
            properties:
              callback_url:
                  type: string
                  example: 'https://example.com/oauth'
              scopes:
                  type: array
                  items:
                      type: string
                  example:
                      - basic_account_info
                      - request_signature
            type: object

this is what I now see:

2021-11-24-111527

The problem is more obvious when you mix root-level properties with nested objects:

2021-11-24-111630

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

Reproduce the issue in Swagger UI's "Try it out" request-body form using the supplied OpenAPI 3.0.3 example. Inspect the multipart/form-data rendering path for nested object properties and compare it with the root-level case. Done means nested object fields render as form inputs rather than a JSON editor, while mixed root and nested properties remain usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.