我正在为我的API创建招摇,但我有相同方法的相同端点的问题。以下是两个具有相同httpMethod POST
的相同端点(/ token),并且两者在主体中具有不同的参数。在UI上招摇没有显示第一个端点。
这是我的招摇代码:
"/token": {
"post": {
"tags": [
"Authorisation"
],
"summary": "Get Token by Username and Password",
"operationId": "6bfe7ad3-64e8-4550-8fc9-c93ff30f4f0e",
"consumes": [
"application/x-www-form-urlencoded"
],
"parameters": [
],
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/getTokenResponse"
}
}
},
"security": [
{
"basic_auth": []
}
]
},
"post": {
"tags": [
"Authorisation"
],
"summary": "Refresh Acces Token",
"operationId": "6bfe7ad3-64e8-4550-8fc9-c93ff30f4f0e",
"consumes": [
"application/x-www-form-urlencoded"
],
"parameters": [
],
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/getTokenResponse"
}
}
},
"security": [
{
"basic_auth": []
}
]
}
}
答案 0 :(得分:2)
每个HTTP方法每个路径只能使用一次。对于同一路径,您不能有两个POST。在OpenAPI规范存储库中有相应的feature request。
您可以做的是将您的API定义转换为OpenAPI 3.0,它支持oneOf
和anyOf
来为同一操作定义备用有效负载:
openapi: 3.0.0
...
paths:
/token:
post:
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
oneOf:
- $ref: '#/components/schemas/getTokenRequest'
- $ref: '#/components/schemas/refreshTokenRequest'
但是在OpenAPI / Swagger 2.0中它是不可能的。