swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

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

Open jtreminio opened this issue 3 years ago • 13 comments
trafficstars

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

jtreminio avatar Nov 24 '21 17:11 jtreminio

I confirm the problem.

andrzepakula avatar Jan 07 '22 13:01 andrzepakula

I Have the same problem

griesi007 avatar Dec 07 '22 13:12 griesi007

any solution on this one? I am facing same issue

botink27 avatar Dec 16 '22 16:12 botink27

I am also facing this issue as well.

joshuadwinn avatar Apr 28 '23 20:04 joshuadwinn

are there any workarounds for this? i need array of DTOs which has bool flag and file itself.

MichalNemec avatar Sep 05 '23 20:09 MichalNemec

Same for me...

GFoniX avatar Oct 05 '23 11:10 GFoniX

I faced the same problem.

Nested structures are not defined correctly.

bralbral avatar Dec 12 '23 03:12 bralbral

has anyone figured out a good workaround for this? it would help to cleanup a lot of endpoints for us when uploading multiple files with data for the images like title, tag,...

MichalNemec avatar Jan 31 '24 22:01 MichalNemec

I have the same issue. Flattening complex structures for display in multipart (to avoid this limitation) is confusing to users trying to understand them and it breaks symmetry with the json nested schemas.

heather486 avatar Jul 09 '24 20:07 heather486