Reputation: 41
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"
]
}
]
}
},
Upvotes: 4
Views: 19092
Reputation: 36114
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.
Upvotes: 1