Response Object with optional empty response via content negotiation. #5067
-
|
How would I model a Response Object where one of the My API uses RFC7240 this would result in say a POST /foo
content-type: application/json
prefer: return=minimal
{"foo": "bar"}
HTTP/1.1 201
preference-applied: return=minimal
location: http://example.com/foo/123or POST /foo
content-type: application/json
prefer: return=representation
{"foo": "bar"}
HTTP/1.1 201
preference-applied: return=minimal
location: http://example.com/foo/123
content-type: application/json
{"foo": "bar"}The closest i can get is the following: ...
post:
parameters:
- name: prefer
in: header
required: false
schema:
type: string
enum: [ "return=minimal", "return=representation" ]
requestBody:
content:
application/json:
schema:
type: object
properties:
foo:
type: str
required: true
responses:
"201":
headers:
location:
schema:
type: string
format: uri
preference-applied:
schema:
type: string
enum: [ "return=minimal", "return=representation" ]
content:
application/json:
schema:
type: object
properties:
foo:
type: str
...but that implies that the and further, is there any way to tie the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
This is not an answer to your question, but rather an observation for the purpose of addressing this problem in the future: the problem is that for requests, "requestBody" is split out as a property of its own, allowing As a potential stopgap solution, you could perhaps do this: ...
responses:
"201":
headers:
...
content:
application/json:
description: "used for prefer: return=representation"
schema:
type: object
properties:
foo:
type: str
*/*:
description: "no response body is returned for prefer: return=minimal"
schema: false |
Beta Was this translation helpful? Give feedback.
This is not an answer to your question, but rather an observation for the purpose of addressing this problem in the future: the problem is that for requests, "requestBody" is split out as a property of its own, allowing
"required":falseto be used when it is relevant, but there is nowhere to specify that a response body is optional because its "content" property is at the same level as the response headers. One possible solution is to add a "responseBody" underneath, which could have a "required" property, adjacent to "content".As a potential stopgap solution, you could perhaps do this: