swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.49k stars 8.96k forks source link

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

Open jairaju opened 5 years ago

jairaju commented 5 years ago

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.

RobGraham commented 4 years ago

Please add this! It's causing none of our swagger entries to work.

when Z = foo/bar in the parameters The path:/api/{Z} turns into /api/foo%2Fbar

webron commented 4 years ago

@RobGraham this will not help your case. allowReserved is only applicable to query parameters. At the moment, the spec does not support the / character in path parameters under any configuration.

jairaju commented 4 years ago

Hi, Thanks for your reply

I figured that out later

On Tue, Nov 26, 2019 at 9:50 AM Ron notifications@github.com wrote:

@RobGraham https://github.com/RobGraham this will not help your case. allowReserved is only applicable to query parameters. At the moment, the spec does not support the / character in path parameters under any configuration.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/swagger-api/swagger-ui/issues/5597?email_source=notifications&email_token=AJDW7ZJAHDLWC2UKS3R22SDQVRJDFA5CNFSM4IUWLIC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFECKNQ#issuecomment-558376246, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJDW7ZLEHKJB5ECXRR23SM3QVRJDFANCNFSM4IUWLICQ .

wilson0x4d commented 3 years ago

still not supported? we've been hacking around this for a while, but, would really like to remove a bunch of string replace code which only exists to compensate for our SwaggerUI usage.

lamoboos223 commented 2 years ago

hi @jairaju

i didn't get the solution. What did you do to work around this?