Skip to content

[REQ] [SPRING] Return generic ResponseEntity from generated controllers #17520

@ravaelamanov

Description

@ravaelamanov

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:

  1. 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.
  2. 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.
  3. 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 😉

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions