4

I am new in swagger and want to deploy an API which is having query string. This is the API I am getting encoded URL after passing the parameter in the GET method.

API URL with Parameter should be:-

baseurl/v1/auth/[email protected]

but I am getting something like:-

baseurl/v1/auth/getOTP?email=somename%40email.com

what I have tried is:-

    "/auth/getOTP": {
  "get": {
    "tags": [
      "pet"
    ],
    "summary": "",
    "description": "",
    "operationId": "findPetsByStatus",
    "produces": [
      "application/json",
      "application/xml"
    ],
    "parameters": [
      {
        "name": "email",
        "in": "path",
        "description": "",
        "required": true,
        "type": "string",
      }
    ],
    "responses": {
      "200": {
        "description": "successful operation",
        "schema": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Pet"
          }
        }
      },
      "400": {
        "description": "Invalid value"
      }
    },
    "security": [
      {
        "petstore_auth": [
          "write:pets",
          "read:pets"
        ]
      }
    ]
  }
},
4
  • add this property allowReserved: true in your parameters and for more details swagger.io/docs/specification/serialization
    – turivishal
    Commented Jul 15, 2020 at 11:25
  • @turivishal: where should I add this property, "parameters": [ { "name": "email", "in": "path", "description": "", "required": true, "type": "string", "allowReserved":true } its also not working Commented Jul 15, 2020 at 11:30
  • Yes, You can add in specific parameters object together with name, in, type properties
    – turivishal
    Commented Jul 15, 2020 at 11:31
  • it's not working Commented Jul 15, 2020 at 11:38

1 Answer 1

1

Swagger OpenAPI has Specified: in this GitHub Issue-1840, It is specifically disallowed on in: path parameters for the same reason they don't allow optional path parameters, e.g. {/foo} By having variable path segments it become difficult to resolve a URL to an operation.

If you want to use some kind of hack then follow this GitHub Issue-230.

If you really needed then Its support in in: query parameters, as below,

The allowReserved keyword specifies whether the reserved characters :/?#[]@!$&'()*+,;= in parameter values are allowed to be sent as they are, or should be percent-encoded. By default, allowReserved is false, and reserved characters are percent-encoded.

Here you need to set it to true,

"parameters": [
    {
        "name": "email",
        "in": "query",
        "description": "",
        "required": true,
        "type": "string",
        "allowReserved": true
    }
],

Look at the Example Swagger Describing Parameters and For more details follow Swagger Serialization.

3
  • I have tried this, but it's working for swagger-ui only not for any other clients. Any ideas? Commented Jul 1, 2021 at 6:12
  • What are other clients?
    – turivishal
    Commented Jul 1, 2021 at 8:08
  • I am not sure but there will be some settings in postman see question1, question2
    – turivishal
    Commented Jul 1, 2021 at 8:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.