swagger-api / swagger-api/swagger-ui

encoding...allowReserved attribute for URL encoded form data should be supported

Open
#5,597 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

I have swagger.json as follows:

{
"openapi": "3.0.0",

"servers": [
{
    "url": "http://localhost:8080"
},
{
    "url": "https://localhost:8081"
}
],
"tags": [
    {
        "name": "API",
     }
],
"paths": {
    "/api/hvp/v1/calls/{call-id}/js": {
        "post": {
            "tags": [
                "Post request"
            ],
            "operationId": "abcd", 
            "parameters": [
                {
                "name": "call-id",
                "description": "call id",
                "in": "path",
                 "schema": {
                        "type": "string"
                 },
                "required": true
                }
            ],
            "requestBody": {
                "$ref": "#/components/requestBodies/customEventBody"
            },
            "responses": {
                "204": {
                    "description": "NO CONTENT"

                },
                "400": {
                    "description": "Bad Request",
                    "content": {
                              "application/json": {
                                          "schema": {
                                              "type": "object",
                                           "properties": {
                                               "status":{
                                                 "type": "string"
                                                },
                                                "detail": {
                                                "type":"string"
                                              }
                                         }
                                   }
                              }
                         }

                }
            }
        }
    }
},
"components": {
    "requestBodies": {
        "customEventBody": {
                "description": "url encoded form data ",
                "content": {
                        "application/x-www-form-urlencoded":{
                               "schema": {
                                         "type": "object",
                                         "properties": {
                                             "document": {
                                               "type":"string"
                                             },
                                             "application":{
                                               "type": "string"
                                             }
                                }
                        },
                        "encoding": {
                             "document": {
                                   "allowReserved": true
                                     },
                             "application": {
                                   "allowReserved": true
                                     }
                            }
                   }
               }
           }
       }
  }

}

as per the OAS 3.0 specification I have set encoding attributes to allowReserved= true,
but I still see the curl command output that is shown in swagger UI -> tryOut option with ascii values for parenthesis and double quotes as follows:

Actual result is this: curl -X POST "http://v-jay-hvp-install:8080/api/hvp/v1/calls/fdfd/js" -H "accept: /" -H "Content-Type: application/x-www-form-urlencoded" -d "application=sss&document=%7B%22Property1%22%3A%22value1%22%7D"

Expected result is this : curl -X POST "http://v-jay-hvp-install:8080/api/hvp/v1/calls/fdfd/js" -H "accept: /" -H "Content-Type: application/x-www-form-urlencoded" -d "application=sss&document={"Property1":"value1"}

I see this in the OAS specs:
===snippet===
By default, reserved characters :/?#[]@!$&'()*+,;= in form field values within application/x-www-form-urlencoded bodies are percent-encoded when sent. To allow these characters to be sent as is, use the allowReserved keyword like so:
====snippet===

In addition, If it is possible to allow curly brackets in the string type, then it should be allowed as well.

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 with Swagger UI's Try It Out request generation for application/x-www-form-urlencoded bodies and reproduce the supplied OpenAPI example. Trace how encoding.allowReserved is handled for form fields, then verify that the generated curl command preserves the permitted reserved characters and that existing behavior remains intact.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.