Skip to content

feature: define api response description globally  #884

Closed
@razvanz

Description

@razvanz

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently, there's no way of configuring exception responses globaly.

Expected behavior

It would be great to be able to define response documentation globally. Maybe in the same way auth is added:

const app = await NestFactory.create(AppModule)

const document = SwaggerModule.createDocument(
  app,
  new DocumentBuilder()
    .setTitle('Custom API')
    .addBearerAuth()
    .addResponse({
      status: 500,
      description: 'Internal server error'
    }) // Same type as @ApiResponse decorator: ApiResponseOptions
    .build()
)
SwaggerModule.setup('docs', app, document)

await app.listen(3000)

Minimal reproduction of the problem with instructions

N/A

What is the motivation / use case for changing the behavior?

Having the ability to define exception responses globally would remove a good amount of redundant code that now needs to be defined on every controller.

Environment


Nest version: 7.4.2
 
For Tooling issues:
- Node version: 14.4.0
- Platform: Linux

Others:
- @nestjs/swagger: 4.5.12

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