-
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
Do we need to clarify what a response missing content means #3536
Comments
Hi! I need the same clarification:
I'm working on some scaffolding tools that have to extract meaning from these kinds of situations. My original interpretation was "will have a response with something" but that obviously breaks the intention when So:
I saw the discussion at #2236 but that's outside my current scope because we are not intending to support optionally present responses (yet). |
It depends on what you mean...
|
Discussion in TDC this week, we don't think we can infer from an absence of response information in an API description whether this means there is no response expected, or the response information is missing from the API description file. |
I would do that with... responses:
2xx:
content:
*/*:
schema: {} ..but |
Given the questions in this thread, we might need to be more explicit in the specification that absence of a specification does NOT indicate that a particular component must be absent; rather the lack of a specification for a thing means that anything is allowed. I'm sure there is some kind of strict language in RFC-style that can be used here, rather than doing it colloquially. |
Thanks for the detailed response!
So something like: responses:
200:
description: "Everything went OK!"
content:
*/*:
schema: false Right? Is an exception like "A 204 response without schema can be interpreted as a false schema" viable? I know this is ugly, but I saw multiple APIs do: responses:
204:
description: "Don't expect any content from me lol. I'm a 204"
You mean that as a schema for the
Maybe something like:
If we want a
The biggest issue with the exception is that it breaks reusability of responses via de |
I'm using this specification for such cases: '204':
description: Success with an empty body
content: {} It works for openapi-backend by validateResponse check based on this condition: https://github.com/openapistack/openapi-backend/blob/5.11.1/src/validation.ts#L766 |
That's not what that means, though. What you are saying by using an empty json object for the media types is simply "the response is unspecified", not "the response must be empty". If your tooling is interpreting that differently, that is an error. |
@karenetheridge Thanks for the update, that's interesting 🤔 For an empty json object it should be responses:
'204':
description: Success with an empty body
content:
application/json: {} Anyway, although the I could agree that the Source: https://swagger.io/docs/specification/v3_0/describing-responses/ Because in that case, technically the body in the response may contain any information without being validated against the specification. As an alternative, this version is also works for me: responses:
'204':
description: Success with an empty body
content:
application/json: {}
schema:
type: 'null' but in that case, I have to put const endpointHanlder = async (ctx) => {
ctx.status = 204
+ ctx.body = null
} otherwise, it would be an error: "message": "Response validation failed.",
"details": [
{
"instancePath": "",
"schemaPath": "#/type",
"keyword": "type",
"params": {
"type": "null"
},
"message": "must be null"
}
], |
I'm afraid that's not correct either -- the value under a media type name ("application/json") is a json schema, and an empty json schema ( This would indicate the expectation that there is no body (it is saying: for any media type, the body content must match the literal empty string): ...
content:
*/*:
schema:
const: '' If your particular web framework uses a You could also do this, which says "if the Content-Length header exists, it must consist of the literal zero value": ...
parameters:
- in: header
name: Content-Length
required: false
schema:
const: '0' |
@karenetheridge The "201":
description: Created
headers:
Content-Length:
schema:
const: 0 I think this would indicate a 201 response MUST NOT have content. The
BTW I think you meant Media Type Object here, which is what you show in your example. |
oh, yes, at some point I forgot we were talking about responses, which use (Unifying these into the same type of object would be a lovely thing to do for moonwalk.) |
@karenetheridge yup, I was just re-formatting it for a response. And we will definitely do something about that by 4.0. |
I've been writing up guides for contract testing with OpenAPI in a bunch of different languages, and the Ruby on Rails one using https://github.com/mkon/openapi_contracts/ gave this great example, letting me know an empty response has been defined, but a response has been provided by the API implementation.
Here's some OpenAPI for visual people:
Does this mean "There is definitely no content" or "I haven't bothered defining it but dont worry about it"?
There are ways to define a "dont worry about it" thats a bit more specific, like:
Or you can pop an example in instead of worrying about defining a schema but still providing something tangible for docs/mocks to think about.
Scrabbling round the spec I coudn't find anything in 3.0 or 3.1 but the SmartBear Guide on Describing Responses does explicitly say:
This leads me to think all responses missing a
content
should have no body, because otherwise there's going to be some weird logic going "If 204 then missing means definitely no body but otherwise it just means I dunno!"Would that be a breaking change to 3.1.x if its clarifying intent? Or does this have to go to Moonwalk?
The text was updated successfully, but these errors were encountered: