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/getOTP?email=somename@email.com

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"
        ]
      }
    ]
  }
},
Mohsen Alyafei
  • 4,765
  • 3
  • 30
  • 42
Divakar Kumar
  • 41
  • 1
  • 1
  • 2

1 Answers1

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.

turivishal
  • 34,368
  • 7
  • 36
  • 59
  • I have tried this, but it's working for swagger-ui only not for any other clients. Any ideas? – Ashutosh Sharma Jul 01 '21 at 06:12
  • What are other clients? – turivishal Jul 01 '21 at 08:08
  • I am not sure but there will be some settings in postman see [question1](https://stackoverflow.com/questions/43611238/url-encode-postman-variable), [question2](https://stackoverflow.com/questions/49961858/how-to-handle-url-with-special-characters-present-in-password-in-postman/49964318#49964318) – turivishal Jul 01 '21 at 08:53