gpt4 book ai didi

Swagger API特殊字符问题

转载 作者:行者123 更新时间:2023-12-05 06:14:22 25 4
gpt4 key购买 nike

我是 swagger 的新手,想部署一个具有查询字符串的 API。这是我在 GET 方法中传递参数后获取编码 URL 的 API。

带有参数的 API URL 应该是:-

baseurl/v1/auth/getOTP?email=somename@email.com

但我得到的是:-

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

我试过的是:-

    "/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"
]
}
]
}
},

最佳答案

Swagger OpenAPI 已指定: 在此 GitHub Issue-1840 , 它在 in: path 参数上被特别禁止,原因与它们不允许可选路径参数相同,例如{/foo} 通过使用可变路径段,很难将 URL 解析为操作。

如果您想使用某种 hack,请关注此 GitHub Issue-230 .

如果你真的需要那么它支持在in:query参数中,如下,

allowReserved关键字指定是否允许参数值中的保留字符:/?#[]@!$&'()*+,;=按原样发送,或者应该进行百分比编码。默认情况下,allowReservedfalse,保留字符采用百分号编码。

这里需要设置为true,

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

看例子Swagger Describing Parameters更多详情请关注Swagger Serialization .

关于Swagger API特殊字符问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62913646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com