Reputation: 169
I am creating swagger for my APIs but I have an issue for same endpoints having same methods. Here are two same endpoints (/token) with same httpMethod POST
and both have different parameters in the body. On UI swagger not showing the first endpoint.
This is my swagger code:
"/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": []
}
]
}
}
Upvotes: 2
Views: 2585
Reputation: 97540
Each HTTP method can only be used once per path. You cannot have two POSTs for the same path. There's a corresponding feature request in the OpenAPI Specification repository.
What you can do is convert your API definition to OpenAPI 3.0, which supports oneOf
and anyOf
to define alternative payloads for the same operation:
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'
but in OpenAPI/Swagger 2.0 it's not possible.
Upvotes: 4