Open
Description
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:
ApiResponse:
type: object
properties:
result:
type: object
errorCode:
type: integer
errors:
type: array
items:
type: string
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;
}
and for the endpoints:
ApiResponse<User> getUsers() ...
ApiResponse<Book> getBooks() ...
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
...