-
I'm interested in creating an OpenAPI specification for my Rest API, but one thing that bothers me is the defining of responses for the API. My API has 2 specific JSON replies based on HTTP response codes:
While I can, for the most part, create two components to cover the 403 and 404 cases, would I like to have an example scheme that depicts an example link matching the provided URL path for the successful request. This, to my knowledge, requires me to create a separate scheme for each API endpoint I have if I want to have this. So my question now is, can I define some kind of placeholder in the scheme, to then be replaced with whatever value I provide? Like f.e. components:
schemas:
image-response-200:
type: object
properties:
error:
type: boolean
example: false
link:
type: string
example: "https://example.com/img/{type}/{type}_001.jpg"
time:
type: integer
format: int32
example: 0 would then allow me to provide "cat" as type somewhere and the example shown would have I hope such a feature exists, as it would reduce the copy-paste jobs I have by a lot in the end... |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Any update here? Is this possible? |
Beta Was this translation helpful? Give feedback.
-
I do believe - one way to answer/tackle initial ask is to use uri template approach which is common way to discover/resolve API behavior in scope of HATEOS semantics. Thanks. |
Beta Was this translation helpful? Give feedback.
-
@MelleD it is possible in 3.1 using JSON Schema draft 2020-12's |
Beta Was this translation helpful? Give feedback.
-
Closing as answered, given no further replies. |
Beta Was this translation helpful? Give feedback.
@MelleD it is possible in 3.1 using JSON Schema draft 2020-12's
$dynamicAnchor
and$dynamicRef
. It is not possible in 3.0 or earlier.