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

How to specify the error response types for swagger #540

Closed
loucass003 opened this issue Aug 11, 2023 · 5 comments
Closed

How to specify the error response types for swagger #540

loucass003 opened this issue Aug 11, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers question Further information is requested

Comments

@loucass003
Copy link
Contributor

Using the nestjs swagger api, I used to set the response errors and code with the different decorators like so

  @Header('Cache-Control', 'no-cache')
  @ApiOperation({
    description: 'Build a specific configuration of the firmware',
  })
  @ApiOkResponse({ type: BuildResponseDTO })
  @ApiBadRequestResponse({ type: VersionNotFoundError })
  buildFirmware(@Body() body: CreateBuildFirmwareDTO) {
    return this.firmwareService.buildFirmware(body);
  }

How can I specify those possible responses with nestia?

@loucass003
Copy link
Contributor Author

it looks like a good way to support this could be to check the
@throws and if the type is an http exception specifying the response code and the payload

Something like this perhaps?

  /**
   * @throws {import("./errors/version-not-found.error").VersionNotFoundExeption}
   */
   @TypedRoute.Post("/build")
  buildFirmware(@Body() body: CreateBuildFirmwareDTO) {
    return this.firmwareService.buildFirmware(body);
  }
export const VersionNotFoundError = 'Version not found';
export class VersionNotFoundExeption extends HttpException {
  constructor() {
    super(VersionNotFoundError, HttpStatus.BAD_REQUEST);
  }
}

@samchon
Copy link
Owner

samchon commented Aug 11, 2023

Will support new decorator function @TypedException<T>().

But as I'm working another thing (typia.protobuf), this feature would be implemented later.

@samchon samchon self-assigned this Aug 11, 2023
@samchon samchon added enhancement New feature or request good first issue Good for newcomers question Further information is requested labels Aug 11, 2023
@loucass003
Copy link
Contributor Author

loucass003 commented Aug 11, 2023

Is there at least a way to use both legacy decorators and nestia to generate a swagger document?

that would allow us to keep using nestia while waiting for the exceptions to be implemented. Not having this feature would mean that we would have to stop using nestia in our project

@samchon
Copy link
Owner

samchon commented Aug 12, 2023

Good idea, I will.

Not possible to adapt @ApiBadRequestResponse like decorators in nestia.

Instead, I'll provide you @TypedException<T>(), and it may not require lots of modifications.

The next version will be published at this week.

@samchon
Copy link
Owner

samchon commented Aug 16, 2023

#548

Upgrade to v1.6.4, then what you want would be prepared.

@samchon samchon closed this as completed Aug 16, 2023
samchon added a commit that referenced this issue Aug 17, 2023
Even when no description being configured, the `description` field in swagger documents must have a `string` value at least `""`.
samchon added a commit that referenced this issue Aug 17, 2023
Complement #540 - `ISwaggerRoute.IResponseBody.description` is required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants