swagger - 带有 NestJS 的 Swagger 不会为某些端点附加 Bearer 令牌
问题描述
我有一个 NestJS 控制器:
@Controller('users')
@ApiTags('users')
export class UserController {
constructor(
private userService: UserService,
private userRoleService: UserRoleService,
private readonly translationService: TranslationService,
) {}
@Get('organization-admin')
@AuthorizeFor(RoleType.ORGANIZATION_ADMIN)
@HttpCode(HttpStatus.OK)
@ApiOkResponse({
description: 'Access for organization admin granted'
})
async organizationAdmin(@AuthUser() user: UserEntity): Promise<string> {
return `Hello organization admin ${user.firstName}`;
}
@Post(':id/assign-role')
@AuthorizeFor(RoleType.ORGANIZATION_ADMIN)
@HttpCode(HttpStatus.OK)
@ApiOkResponse({
status: HttpStatus.OK,
description: 'Role assigned to user',
type: UserRoleDto,
})
async assignRoleToUser(
@Body() userRole: CreateUserRoleDto,
@UUIDParam('id') userId: string
): Promise<CreateUserRoleDto> {
const user = await this.userService.findOne({ id: userId });
return this.userRoleService.createUserRole(user, userRole);
}
}
使用 swagger - Bearer 令牌附加到请求@Get('organization-admin')
但不会附加到@Post(':id/assign-role')
.
你能帮我弄清楚为什么会发生吗?
提前致谢。
解决方案
尝试将@ApiBearerAuth()
装饰器添加到您的端点/控制器
推荐阅读
- ios - 从另一个值创建新字典
- java - 检查类型后将父对象作为子对象传递
- swift - 禁用 UIWebView 和/或 WKWebView 中样式表的加载
- android - 升级依赖项后无法解析 ActivityTestRule。无法导入 ActivityTestRule
- react-native - 如何配置 Expo 以允许全局模块导入?
- javascript - 异步函数内部的一些错误无法正常工作
- ios - 如何修改 MVVM Cross 中的绑定值
- php - 您在 codeigniter 中指定了无效的数据库连接组
- javascript - React-Router 不会在位置参数更改时卸载
- javascript - 按字母顺序对列表中的文本范围进行排序