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
添加这几行代码,完美解决