Skip to content

How Can Swagger Identify Object Requests Containing Files #10392

Open
@Mathias02

Description

@Mathias02

Content & configuration

Swagger/OpenAPI definition:

# your YAML here

paths:
 /upload:
   post:
     summary: Upload indexed files
     requestBody:
       content:
         multipart/form-data:
           schema:
             type: object
             properties:
               files:
                 type: array
                 items:
                   type: object
                   properties:
                     file:
                       type: string
                       format: binary
                     title:
                       type: string
     responses:
       "200":
         description: Files uploaded successfully

Swagger-UI configuration options:

SwaggerUI({
  // your config options here
 url: "https://my-api.com/openapi.json",
 dom_id: "#swagger-ui",
 presets: [SwaggerUI.presets.apis],
 layout: "BaseLayout"
})
?yourQueryStringConfig
?defaultModelsExpandDepth=-1

Is your feature request related to a problem?

Yes!

Swagger UI does not support indexed form fields in multipart/form-data requests but many backend frameworks can handle form data with indexed object keys such as spring Boot etc. Currently, Swagger UI does not generate these indexed form fields, making it difficult to test APIs directly from the UI.

Describe the solution you'd like

Swagger UI should support indexed naming for form fields in multipart/form-data;
A. By allowing OpenAPI schemas to generate indexed form fields,
B. Ensure that these indexed fields are properly serialized in requests,
C. Improve the UI to handle dynamic form entries. e.g , "Add More" which should be a button to add new indexed fields).

Describe alternatives you've considered

1.Writing a custom frontend to handle indexed form requests.
2. Manually renaming fields (file_0, file_1), but this is not a real array,
3. Using Postman instead of Swagger UI for testing.

  • None of these solutions are ideal, as they require workarounds instead of a native Swagger UI implementation

Additional context

  • This feature would improve Swagger UI’s usability for APIs handling file uploads with metadata,
  • Many users have requested better support for multipart form arrays in OpenAPI,
  • This would eliminate the need for external tools like Postman when testing APIs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions