Swagger API URL 参数问题
Swagger API URL Parameter issue
我是 swagger API 文档的新手,想部署一个具有查询字符串的 API。这是我在 GET 方法中传递参数后得到的 API。
baseurl/v1/auth/getOTP?mobile=98XXXXXX14
我想要这个:-
baseurl/v1/auth/getOTP/mobile/98XXXXXX14
我正在执行的是:-
"/auth/getOTP": {
"get": {
"tags": [
"pet"
],
"summary": "",
"description": "",
"operationId": "findPetsByStatus",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"name": "mobile",
"in": "query",
"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"
]
}
]
}
},
你的问题在这里:
{
"name": "mobile",
"in": "query", // <-- Right here.
"description": "",
"required": true,
"type": "string",
}
为了让手机号码在路径中而不是查询中,您需要更改两件事。
首先,将路径更改为"/auth/getOTP/mobile/{mobile}"
。
二、修改参数说明:
{
"name": "mobile",
"in": "path", // This.
"description": "",
"required": true,
"type": "string",
}
详细了解 OAS path templates & parameters。
我是 swagger API 文档的新手,想部署一个具有查询字符串的 API。这是我在 GET 方法中传递参数后得到的 API。
baseurl/v1/auth/getOTP?mobile=98XXXXXX14
我想要这个:-
baseurl/v1/auth/getOTP/mobile/98XXXXXX14
我正在执行的是:-
"/auth/getOTP": {
"get": {
"tags": [
"pet"
],
"summary": "",
"description": "",
"operationId": "findPetsByStatus",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"name": "mobile",
"in": "query",
"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"
]
}
]
}
},
你的问题在这里:
{
"name": "mobile",
"in": "query", // <-- Right here.
"description": "",
"required": true,
"type": "string",
}
为了让手机号码在路径中而不是查询中,您需要更改两件事。
首先,将路径更改为"/auth/getOTP/mobile/{mobile}"
。
二、修改参数说明:
{
"name": "mobile",
"in": "path", // This.
"description": "",
"required": true,
"type": "string",
}
详细了解 OAS path templates & parameters。