swagger-api / swagger-editor

Swagger Editor
https://editor.swagger.io
Apache License 2.0
8.86k stars 2.24k forks source link

multipart/form-data ui missing schema view #5125

Open hoermannpaul opened 3 months ago

hoermannpaul commented 3 months ago

Q&A (please complete the following information)

Content & configuration

Using online editor (or local spring boot swagger UI installation) with following definition:

openapi: 3.0.3
info:
  title: Some demo API
  version: 0.1.0
paths:
  /somepath:
    post:
      summary: "test"
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties: # Request parts
                id:
                  type: string
                  format: uuid
                address:
                  type: object
                  properties:
                    street:
                      type: string
                    city:
                      type: string
                profileImage:
                  type: string
                  format: base64
            encoding:
              profileImage:
                contentType: image/png, image/jpeg
      responses:
        '200':
          description: OK

Swagger-Editor configuration options: doesn't apply (online editor defaults)

Describe the bug you're encountering

Content header is not properly set as default for objects in multipart resquests.

To reproduce...

Steps to reproduce the behavior:

  1. Paste provided def into editor
  2. Click on endpoint (expand view) Shouldn't there be something to view schema (next to example data button) like displayed in figure 1? It's missing as seen in figure 2.
  3. If you hit execute now, following curl command is suggested (which doensn't work with generated java code):
    curl -X 'POST' \
    'https://editor.swagger.io/somepath' \
    -H 'accept: */*' \
    -H 'Content-Type: application/json' \
    -d '{
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "address": {
    "street": "string",
    "city": "string"
    },
    "profileImage": "string"
    }'

    Where I expect:

    curl -X 'POST' \
    'https://editor.swagger.io/somepath' \
    -H 'accept: */*' \
    -H 'Content-Type: application/json' \
    -d '{
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "address": {
    "street": "string",
    "city": "string"
    },
    "profileImage": "string"
    };type=application/json'

Expected behavior

Executing curl command fails because default content-type is application/octet-stream, which is rejected by a properly configured REST Api. Further, I'd expect a schema view for request body, which works if just changing 'multipart/form-data' to 'application/json' in given definition. Adding encoding for parameter manually adds correct header.

Screenshots

figure 1

figure 2

Additional context or thoughts

Maybe related to https://github.com/swagger-api/swagger-editor/issues/4609