nest swagger UI在请求头中携带token

描述

nest中配置swagger后, swaggerUI中没有能够设置请求头的地方 (token需要通过header传递)

在这里插入图片描述

解决

main.ts 启用swagger的位置加上 .addBearerAuth()

  const config = new DocumentBuilder()
    .setTitle('My API')
    .setDescription('My API')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api/doc', app, document, {
    customSiteTitle: 'YNote API',
  });

controller控制器上加上 @ApiBearerAuth()

@ApiTags('test')
@ApiBearerAuth()
@Controller({
  path: 'test',
})
export class TestController {}

只要添加了@ApiBearerAuth()的控制器接口, swaggerUI上请求时才会在header中加上authorizations

在这里插入图片描述

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-13 01:34:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 01:34:01       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 01:34:01       58 阅读
  4. Python语言-面向对象

    2024-07-13 01:34:01       69 阅读

热门阅读

  1. 我的大事记

    2024-07-13 01:34:01       20 阅读
  2. 每天一个数据分析题(四百二十八)- 方差分析

    2024-07-13 01:34:01       24 阅读
  3. C++ 函数返回值是void* 使用场景

    2024-07-13 01:34:01       23 阅读
  4. 2974.最小数字游戏

    2024-07-13 01:34:01       21 阅读
  5. ahb 总线的一些思考

    2024-07-13 01:34:01       24 阅读
  6. 级联目标检测:构建高效目标识别的多阶段策略

    2024-07-13 01:34:01       23 阅读
  7. C语言8 数组与字符串

    2024-07-13 01:34:01       21 阅读
  8. 人工智能讲座——深度学习实现行人重识别

    2024-07-13 01:34:01       23 阅读
  9. LeetCode 算法:全排列 c++

    2024-07-13 01:34:01       24 阅读
  10. 云端日历同步大师:iCloud让工作与生活井井有条

    2024-07-13 01:34:01       26 阅读
  11. 简述linux通知链机制

    2024-07-13 01:34:01       25 阅读
  12. 关于如何上传本地文件到Linux主机

    2024-07-13 01:34:01       17 阅读