Reputation: 9896
I have an endpoint that can return different 200 success responses. Each response is a different content-type with different headers.
Every example I see online of 'different responses' only demonstration the basic example of the same content-type with a different content structure, like different JSON objects.
OneOf
doesn't work because the responses aren't a complete schema. I cannot rename the response HTTP codes or append anything like 200-image-response
"/download-content": {
"get": {
"responses": {
200: { // doesn't work
"oneOf": [
{
"$ref": "#/components/responses/200-image-response"
},
{
"$ref": "#/components/responses/200-video-response"
}
]
},
500: { // completely fine
"$ref": "#/components/responses/500"
}
}
}
}
I have already had to use work-arounds in other places in my contract due to limitations of openapi, but I am not sure how I can create a work-around in this case since the endpoint won't change nor will any request headers.
Upvotes: 0
Views: 630
Reputation: 2393
As you've discovered, you can't use the oneOf
schema keyword directly under a response
object.
You need something like
responses:
'200':
description: OK
content:
'image/jpeg':
schema:
$ref: '#/components/schemas/image'
'video/mpeg':
schema:
$ref: '#/components/schemas/video'
Upvotes: 1