Skip to content

Commit 752188f

Browse files
committed
feat: 更新 swagger 可定制化根目录配置,如 DOCS_SWAGGER_ROOT
1 parent 893b608 commit 752188f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ module.exports = function(app) {
9797
DOCS_SWAGGER=true
9898
```
9999

100+
通过扩展配置 `DOCS_SWAGGER_ROOT`,可支持其它目录 `path.resolve(process.env.DOCS_SWAGGER_ROOT, '**/*.js')` 目录下文件
101+
102+
```conf
103+
DOCS_SWAGGER_ROOT={{ dirname }}
104+
```
105+
100106
配置 swagger 文档,需要在接口方法中增加注释,如下:
101107

102108
```js

src/plugins/docs/swagger.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ function swaggerOptionsFactory(spec, config) {
2424
// basePath: '/', // Base path (optional)
2525
},
2626
// Path to the API docs
27-
apis: [ path.resolve(root, 'src/**/*.js'), path.resolve(__dirname, '**/*.js') ],
27+
apis: [
28+
path.resolve(root, 'src/**/*.js'),
29+
path.resolve(__dirname, '**/*.js'),
30+
].concat(process.env.DOCS_SWAGGER_ROOT ? [
31+
path.resolve(process.env.DOCS_SWAGGER_ROOT, '**/*.js'),
32+
] : []),
2833
};
2934
}
3035
return {

0 commit comments

Comments
 (0)