egg-Swagger-doc配置basicAuth

egg-Swagger-doc 链接

授权支持两种,apiKey和auth2

在这里插入图片描述
现在配置basicAuth

config.default.js

    swaggerdoc: {
     // openapi:'3.0.0',
      dirScanner: "./app/controller",
      apiInfo: {
        title: "egg-api",
        description: "个人接口文档",
        version: "1.0.0",
      },
      schemes: ["http", "https"],
      consumes: ["application/json"],
      produces: ["application/json"],
      securityDefinitions: {
        basicAuth: { // basicAuth之后接口注释 @basicAuth
          type: "basic",
        },
        // apikey: {
        //   type: 'apiKey',
        //   name: 'clientkey',
        //   in: 'header',
        // },
        // oauth2: {
        //   type: 'oauth2',
        //   tokenUrl: 'http://petstore.swagger.io/oauth/dialog',
        //   flow: 'password',
        //   scopes: {
        //     'write:access_token': 'write access_token',
        //     'read:access_token': 'read access_token',
        //   },
        // },
      },
      enableSecurity: true,
      // enableValidate: true,
      routerMap: false,
      enable: true,
    },
  });
  /**
   * @summary 获取文章列表
   * @description 分页获取文章列表
   * @router get /api/v1/article
   * @request query integer curPage 页码 默认 1
   * @request query integer pageSize 单页数量 默认 20
   * @response 200 baseResponse successed
   * @basicAuth basicAuth: []
   */
  async index() {
    const { ctx, service } = this;
    const { curPage = 1, pageSize = 20 } = ctx.query;
    const query = {
      limit: pageSize,
      offset: (curPage- 1) * pageSize,
      order: [
        [ 'order', 'DESC' ],
      ],
    };
  ......
  }

配置了,但是接口处注解 @basicAuth 不识别

源码 node-modules
在这里插入图片描述
在这里插入图片描述
添加这几行代码,完美解决

在这里插入图片描述


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值