Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting default type to response types #2548

Open
1 task done
bddvlpr opened this issue Aug 2, 2023 · 1 comment
Open
1 task done

Allow setting default type to response types #2548

bddvlpr opened this issue Aug 2, 2023 · 1 comment
Labels

Comments

@bddvlpr
Copy link

bddvlpr commented Aug 2, 2023

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

Currently, any @ApiResponse decorator has a never type by default. This can be very vexatious in case of using type-safe OpenAPI clients.

@ApiOkResponse({description: "Something happened"})
@ApiBadRequestResponse({description: "Something went wrong"})
@Get()
someTest() {
    // ...
    throw new HttpException('Some test', 400);
    // ...
}

Will result in the following types being generated:

{
    responses: {
        200: // ...
        400: never
    }
}

Describe the solution you'd like

Perhaps implementing a "default exception type" or a way of globally setting the default return type would help.

Teachability, documentation, adoption, migration strategy

No response

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

This allows the swagger to auto-generate (primarily) exceptions more streamlined to default HttpException results (see examples below).

A generic HttpException response.

{
    message: string,
    statusCode: number
}

Or, for example, a class-validator exception.

{
    message: string[],
    error: string,
    statusCode: number
}
@bddvlpr bddvlpr added the feature label Aug 2, 2023
@jmpecx
Copy link

jmpecx commented Dec 22, 2023

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants