Multiple Decorators

For cleaner code, if you are using many @ApiResponse decorators you can use a decorator composition to have a single decoder in your controller.

By having many response types for one endpoint, our controller will have many lines of code that could get a bit confusing.

To avoid this, we can create a decorator that contains all the decorators for that endpoint.

Example:

To group all our decorators in a single one we will use Decorator composition:

Inside the applyDecorators function you must put all the decorators that your endpoint will have. Then, in your controller you just call this function as a decorator.

Last updated

Was this helpful?