-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Proposal: Default responses for all endpoints #521
Comments
👍 to the suggestion. As you mentioned, this would save A LOT of copy/paste. |
Link to meta #566 |
Just a reminder, please use github reactions, rather than "+1" comments (two recent ones deleted). |
Is there any progress with this? The ticket is open for more than 3 years now... :( |
I cannot imagine why this is not fixed yet as this issue just makes impossible to specify an error for an invalid path (404) or method (405). |
you can reference responses, which is more or less what is being requested here: paths:
/my_endpoint:
get:
responses:
404:
$ref: "#/components/responses/notFound"
405:
$ref: "#/components/responses/methodNotAllowed"
/other:
get:
responses:
404:
$ref: "#/components/responses/notFound"
405:
$ref: "#/components/responses/methodNotAllowed"
components:
responses:
notFound:
description: "Not found response"
content":
application/json":
schema:
$ref: "#/components/schemas/notFoundResponse"
methodNotAllowed:
description: "Method Not Allowed response"
content":
application/json":
schema:
$ref: "#/components/schemas/methodNotAllowedResponse" I know this is much more verbose, but at least is a workaround.... |
+1 dream about this feature |
+1, will be useful |
+1, amazing feature |
+1, I will be gratefull |
+1 this will save a lot of repeating docs code |
+1 would save a lot of time |
+1 |
this will be usefull |
This would be incredibly useful and performance booster! |
its so helpfull if this feature is exist |
We have about 800 endpoints. Repeating the same error response references everywhere increases the JSON a lot... |
I'm also wondering how this isn't a thing yet. There's so many responses that are just part of every single endpoint by default. Things like "content-type not supported", "invalid credentials", "request entity too large", "malformed content", and more... Also, what about responses that aren't even tied to an endpoint at all? For example, an "endpoint does not exist" response? I obviously can't add that response to any of the endpoint definitions. Maybe some of those are not supposed to be part of the API definition at all, but I'm using |
I'm currently looking at the possible need to add a default / override for the JSON Schema, A design question comes up between simplicity and extensibility of this "default" feature. Would something like: openapi: 3.1.0
info:
title: API
version: 1.0.0
defaults:
responses:
'405':
description: Method not allowed
schema:
$ref: '#/components/responses/error'
'429':
description: Too many requests
schema:
$ref: '#/components/responses/error'
headers:
.... address the requirements for people in this issue? Bearing in mind @darrelmiller's very good advice in this tweet. |
+1 for this feature! |
I'm interested in that. Similar to what's been discussed so far in #563 |
We currently (3.0) using the go to method to achieve "less" copy past: Definition:
Usage:
And to "customize default responses" we sneak them in as components/schemas not components/responses Definition:
Usage:
So we may have both if really necessary.. but native support would be much appreciated.. pretty please with extra sugar on? ;-) |
I'm confused, sorry. Native support for what exactly? You can't use |
For us it makes "no sense" to distinguishe between schemas and responses. (depending on usecase)
so why is it that
I would like to see either the possibility to customize responses (somewhat) like schemas or to mark schemas as responses (so the won't be seen as DTOs) (hence native support) |
I'm afraid I still don't follow. A |
Maybe i'am bad with explanations :D .. i wan't to achieve what comment #521 (comment) says it can't be done ;) |
@DerDu unfortunately that comment has a |
Hi, the Using that example, e.g. Without the ability to use |
RFC7807 error schema allows reuse of the same schema with the flexibility
to apply different messages for each error in your service. You can create
infinite examples of every possible error but the schema remains the same.
…On Fri, May 5, 2023, 14:21 Homa Wong ***@***.***> wrote:
that comment has a ... in the example just where it would explain what it
is trying to achieve
Hi, the ... literally means adding anything specific for that usage.
Using that example, 400.BadRequest only describes the HTTP Status that it
is a bad request.
i.e. the user pass in something that does not recognized or accepted by
the endpoint.
What could they be? That's specific to every usage.
e.g. customer-id is missing, item-count can't be negative number, etc.
Without the ability to use allOf at the response level,
none of the response can be reused when we need to do any customization
tailors to each usage.
—
Reply to this email directly, view it on GitHub
<#521 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHU7MTK7B7VSUMGITXAZAU3XEVAKPANCNFSM4BV5WOKA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Not the way that I understand it…
https://datatracker.ietf.org/doc/html/rfc7807
Grammar specifically says you can have additional fields.
…On Fri 5 May 2023 at 20:42, Jeremy Fiel ***@***.***> wrote:
RFC7807 error schema allows reuse of the same schema with the flexibility
to apply different messages for each error in your service. You can create
infinite examples of every possible error but the schema remains the same.
On Fri, May 5, 2023, 14:21 Homa Wong ***@***.***> wrote:
> that comment has a ... in the example just where it would explain what it
> is trying to achieve
>
> Hi, the ... literally means adding anything specific for that usage.
>
> Using that example, 400.BadRequest only describes the HTTP Status that it
> is a bad request.
> i.e. the user pass in something that does not recognized or accepted by
> the endpoint.
> What could they be? That's specific to every usage.
>
> e.g. customer-id is missing, item-count can't be negative number, etc.
>
> Without the ability to use allOf at the response level,
> none of the response can be reused when we need to do any customization
> tailors to each usage.
>
> —
> Reply to this email directly, view it on GitHub
> <
#521 (comment)
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AHU7MTK7B7VSUMGITXAZAU3XEVAKPANCNFSM4BV5WOKA
>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
—
Reply to this email directly, view it on GitHub
<#521 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHCBEMMZ7NETJ2BIAZ7PHBDXEVCZPANCNFSM4BV5WOKA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
You can have additional fields because the schema is not constrained but it
has five properties which are meant to define a common error object
…On Sun, May 7, 2023, 12:54 Maxime Lenglet ***@***.***> wrote:
Not the way that I understand it…
https://datatracker.ietf.org/doc/html/rfc7807
Grammar specifically says you can have additional fields.
On Fri 5 May 2023 at 20:42, Jeremy Fiel ***@***.***> wrote:
> RFC7807 error schema allows reuse of the same schema with the flexibility
> to apply different messages for each error in your service. You can
create
> infinite examples of every possible error but the schema remains the
same.
>
> On Fri, May 5, 2023, 14:21 Homa Wong ***@***.***> wrote:
>
> > that comment has a ... in the example just where it would explain what
it
> > is trying to achieve
> >
> > Hi, the ... literally means adding anything specific for that usage.
> >
> > Using that example, 400.BadRequest only describes the HTTP Status that
it
> > is a bad request.
> > i.e. the user pass in something that does not recognized or accepted by
> > the endpoint.
> > What could they be? That's specific to every usage.
> >
> > e.g. customer-id is missing, item-count can't be negative number, etc.
> >
> > Without the ability to use allOf at the response level,
> > none of the response can be reused when we need to do any customization
> > tailors to each usage.
> >
> > —
> > Reply to this email directly, view it on GitHub
> > <
>
#521 (comment)
> >,
> > or unsubscribe
> > <
>
https://github.com/notifications/unsubscribe-auth/AHU7MTK7B7VSUMGITXAZAU3XEVAKPANCNFSM4BV5WOKA
> >
> > .
> > You are receiving this because you commented.Message ID:
> > ***@***.***>
> >
>
> —
> Reply to this email directly, view it on GitHub
> <
#521 (comment)
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AHCBEMMZ7NETJ2BIAZ7PHBDXEVCZPANCNFSM4BV5WOKA
>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
--
Maxime LENGLET
Ingénieur Senior backend/full-stack Java/Web/API/GraphQL
259 avenue du Maréchal Leclerc, 91300 Massy
06 65 17 09 31
—
Reply to this email directly, view it on GitHub
<#521 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHU7MTL3ZY5COIS54P32EZTXE7OUBANCNFSM4BV5WOKA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Specifically, section 3.2: |
Also, even if you can come up with a generic data structure (error or normal response), Using rfc7807 as an example, {
"type": string,
"title": string,
"detail": ...
...
} But what are the possible values for Even if we don't change them to an {
"type": "https://example.com/probs/out-of-credit",
"title": "You do not have enough credit.",
"detail": "Your current balance is 30, but that costs 50.",
"instance": "/account/12345/msgs/abc",
"balance": 30,
"accounts": ["/account/12345",
"/account/67890"]
} At the minimum we should be able to add descriptions and other info on top of the common response. Currently, the common response can only be used as-is, thus greatly limits its reusability. |
Could be. But at the same time the API Spec fails to describe what the API actually returns. i.e. the API Spec failed to serve as the documentation of the API. |
fyi, this long-standing issue is addressed in: https://github.com/OAI/moonwalk |
You might not want to give your your phone number and address publicly on Github? |
Thanks for pointing this... that's the problem of answering by email. Fixed now. Thanks!! |
I'm not sure why this rather simple proposal sparked so much debate. It only took working with OpenAPI for a few days for me to notice this gap when defining my API. Nonetheless, it's not clear what the idiomatic way is for dealing with errors that are common to all your paths (401/403 is the simplest example). Defining these for every path just doesn't seem right. If the spec was solely for documentation, I would say that error types that are truly universal to all your endpoints, and thus not surprising to callers of your API, are not even worth defining in your spec. But omitting errors that your API can return can have negative implications as soon as you start generating type safe clients with your spec. This proposal is already 8 years old - how can we move it forward? |
Would this be covered by the suggested |
@ralfhandl yes, I think we can mark this "Moved to Moonwalk" and close it out here (Features added to Moonwalk will be back-ported to 3.x if it makes sense to do so, so there's no need to track it in both repositories).
This is a standards group, debating things that seem simple is practically a requirement 🙃 It's definitely frustrating at times, but I suspect this didn't get into 3.1 partially because there was a bit of a debate about how much we really even want to document all responses, but mostly because we had big things in 3.1 already and no one realized that the spec work would slow down so much afterwards. But it will find some sort of home in 4.0 (Moonwalk). And possibly to some degree in a future 3.x. |
Thanks for clarifying! |
This is already possible to achieve using |
I suggest that we add "default responses" that can be defined as default response for All endpoints. This would avoid copy-paste for some common responses like:
429 Too Many Requests
405 Method Not Allowed
The format could be
Or if flexibility is required, we could alter the default response keyword to take a list of responsedefinitions. This could benefit with the response code range proposal (#516).
this would require some changes to the default response keyword.
The text was updated successfully, but these errors were encountered: