Is your feature request related to a problem? Please describe.
What I need: I need to return different models for different status codes for a single http endpoint.
Use cases: exception handling (different models for success and error responses), several successful status codes (i.e. 20x) are returned by the endpoint
AFAIK, currently there's no way to generate a controller with generic ResponseEntity (i.e. ResponseEntity<?>, ResponseEntity) as return type.
Describe the solution you'd like
It would be nice to have a config property to indicate that generated controllers should return a generic ResponseEntity (e.g. a boolean property useGenericResponseEntity).
Describe alternatives you've considered
There're several workarounds to achieve desired behaviour:
- For exception handling we're currently using exceptions +
@ControllerAdvice. Unfortunately, there's a potential performance penalty behind this option - stack unwinding. It might affect latency and overall resource utilisation under high loads.
- Another option is modifying mustache templates and passing them to the generator with
templateDir option. This feels a bit hacky and might conflict with future updates of templates.
- An alternative option which we're are considering now is modifying the return type in generated sources in a separate task of gradle build script. But why to modify generated code when we can generate it correctly in the first place 😉
Is your feature request related to a problem? Please describe.
What I need: I need to return different models for different status codes for a single http endpoint.
Use cases: exception handling (different models for success and error responses), several successful status codes (i.e. 20x) are returned by the endpoint
AFAIK, currently there's no way to generate a controller with generic ResponseEntity (i.e. ResponseEntity<?>, ResponseEntity) as return type.
Describe the solution you'd like
It would be nice to have a config property to indicate that generated controllers should return a generic ResponseEntity (e.g. a boolean property
useGenericResponseEntity).Describe alternatives you've considered
There're several workarounds to achieve desired behaviour:
@ControllerAdvice. Unfortunately, there's a potential performance penalty behind this option - stack unwinding. It might affect latency and overall resource utilisation under high loads.templateDiroption. This feels a bit hacky and might conflict with future updates of templates.