Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple success and failure sections for a single code #1803

Open
alifemove opened this issue Apr 30, 2024 · 1 comment
Open

Multiple success and failure sections for a single code #1803

alifemove opened this issue Apr 30, 2024 · 1 comment

Comments

@alifemove
Copy link

alifemove commented Apr 30, 2024

Is your feature request related to a problem? Please describe.
Endpoints that return the same error or success code for multiple reasons; i.e. 200 that returns a specific payload structure if there is only 1 record vs a different payload structure if there are > 1 records

Describe the solution you'd like
Be able to do something along the lines of

@success 200 {object} SuccessSingle
@success 200 {object} SuccessPage
@failure     400 "Bad Request"
@failure     400 "Invalid filter in query"

I found that I could use <br/> in the failures to basically do the same thing, but not sure about success.

@failure    400 "Bad Request<br/>Invalid filter in query"
@alexrjones
Copy link

Both OpenAPI 2.0 and 3+ specs only support one response type per status code (ref). In 3+ I think you could use oneOf to describe this, which would be relatively easy to implement. In 2.0 you'd need to use a combination of allOf and discriminator, which is more complicated, because discriminator comes with some restrictions:

The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the required property list. When used, the value MUST be the name of this schema or any schema that inherits it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants