swagger-api / swagger-api/swagger-ui

Form field order not respected

Open
#5,279 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cat: try-it-out swagger-js type: enhancement
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Content & configuration

When specifying fields with a multipart/form-data response the order of the fields in the request can be significant, but swagger-ui sends the fields in a different order to they were declared in the swagger (order seems random).

For instance, consider two fields, one that defines some metadata that defines how to handle the second field which can potentially be very large, requiring the response to be streamed in a single pass. If the order of fields is reversed then the response cannot be properly processed.

This was first raised in this issue, but it was requested to create a new issue for this:
https://github.com/swagger-api/swagger-ui/issues/1939#issuecomment-474523572

For example given this Swagger/OpenAPI definition:

  /jobexecutor/rest/v1/jobs/cdk.calculators.verify:
   summary: Verify structure (CDK)
   description: Verify that the molecules are valid according to CDK
   post:
     summary: Post the job
     requestBody:
       content:
         multipart/form-data:
           schema:
             type: object
             properties:
               options:
                 type: object
               input_metadata:
                 type: object
               input_data:
                 type: object
           encoding:
             input_metadata:
               contentType: application/x-squonk-dataset-metadata+json
             input_data:
               contentType: application/x-squonk-dataset-molecule+json

I would expect the fields that are posted by swagger-ui to be in the order options, input_metadata, input_data but this is not the case

Describe the solution you'd like

The fields should be POSTed in the order they are declared in the swagger

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 by reproducing the multipart/form-data request from the OpenAPI example and inspect the request-building path that creates its fields. Compare the emitted order with the schema property order. Done means swagger-ui posts options, input_metadata, and input_data in their declared order, with the existing content types preserved.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.