-
Notifications
You must be signed in to change notification settings - Fork 477
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
Adding @ApiFoundResponse on a dynamic redirect method still renders a 200 response code in the OpenAPI contract #1639
Comments
yeah it will be Basically, I guess this happen due to the following swagger/lib/plugin/visitors/controller-class.visitor.ts Lines 71 to 84 in 491b168
|
actually, isn't this the intended behavior? The spec will have that |
Hmmm, it would seem very strange for this to be intended behavior. It seems incorrect to list a response value in the OpenAPI spec that will never happen. Thinking about this as if an engineer was manually writing this schema, it seems wrong for them to include a 200 for a route that never returns such a status code. Also, any clients will be confused as to why they have to handle a 200. |
oh right |
Any news on this? We have a couple of routes that for instance return 204 codes; but in Swagger they're still listed with an additional 200 response, which is misleading. Maybe an option to skip adding the default response (via decorator?) could do the trick? |
are they statically defined? please show us a code snippet of it |
OpenAPI setup: const config = new DocumentBuilder()
.setTitle(process.env.npm_package_name)
.setDescription(process.env.npm_package_description)
.setVersion(process.env.npm_package_version)
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api/doc', app, document, {
swaggerOptions: { persistAuthorization: true },
}); Controller: @Controller({ path: '/user/check-eligibility', version: '2' })
export class EligibilityCheckerController {
@Get()
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiNoContentResponse({
description:
"The user's email address domain is eligible.",
})
@ApiUnauthorizedResponse({
description:
'The request is not authenticated, user needs to send a valid bearer token.',
})
@ApiForbiddenResponse({
description: 'This user is not eligible.',
})
public async checkEligibility(
@User() user: AccessToken,
@Res() response: Response,
) {
const isEligible =
await this.eligibilityCheckerService.checkUserEligibility(user);
if (isEligible) {
return response.status(204).send();
}
return response.status(403).send();
}
} Generated API documentation: We're not currently using the CLI, and I couldn't find a generated JSON or YAML, so here's a screenshot while I try to figure out how to get the generated document I don't understand where the |
from the swagger/lib/explorers/api-response.explorer.ts Lines 63 to 72 in 29331c7
|
Is there an existing issue for this?
Current behavior
It appears that the Swagger CLI is adding an extra 200 response code to a method that will never return a 200 response. Specifically, for a method that always returns a dynamic redirect that's been labeled with
@ApiFoundResponse
Example:
Which produces:
Minimum reproduction code
See above.
Steps to reproduce
See above.
Expected behavior
Only a single response is rendered - no 200 for a redirect.
Package version
5.1.3
NestJS version
8.0.11
Node.js version
14
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: