You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and have specific endpoints return a specific implementation of the generic response like:
paths:
/users:
get:
responses:
content:
'application/json':
schema:
$ref: '#/components/schemas/ApiResponse'
result:
type: User <-- somehow define the specific object type of result. Ideally a ref to another schema
/books:
get:
responses:
content:
'application/json':
schema:
$ref: '#/components/schemas/ApiResponse'
result:
type: Book <-- somehow define the specific object type of result. Ideally a ref to another schema
This should then create a Java class for the ApiResponse like:
class ApiResponse<T> {
private T result;
private int errorCode;
private List<String> errors;
}
I thought of somehow using mustache templates and overriding specific schemas with the template but I don't know how that would work. Maybe there is already an easier build in solution?
Otherwise, please guide me to a useful documentation on how to use templates for this use-case.
Additional context
...
The text was updated successfully, but these errors were encountered:
First of all, this question is more about the OpenAPI Specification itself. As of today, the current version is 3.1.0, which does not support dynamic links (at least this feature is not described).
So as I understand it, the generic data structures support is part of JSON Schema which the OAS 3.1 is built upon. The only difference in 3.1.1 is the spec explicitly calls out the use of using dynamicRef and dynamicAnchor for generic data structures as an example. But technically the 3.1.0 spec already supports this according to the OAS maintainers (see this comment)
Is your feature request related to a problem? Please describe.
I couldn't find a solution to define a generic response for open-api Spring generator or in general for the open-api generator.
Describe the solution you'd like
In my yaml file I want to define something like this:
and have specific endpoints return a specific implementation of the generic response like:
This should then create a Java class for the ApiResponse like:
and for the endpoints:
Describe alternatives you've considered
I thought of somehow using mustache templates and overriding specific schemas with the template but I don't know how that would work. Maybe there is already an easier build in solution?
Otherwise, please guide me to a useful documentation on how to use templates for this use-case.
Additional context
...
The text was updated successfully, but these errors were encountered: