@midwayjs/swagger 4.0.0-alpha.1 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/decorators/api-basic.decorator.d.ts +1 -1
- package/dist/decorators/api-bearer.decorator.d.ts +1 -1
- package/dist/decorators/api-cookie.decorator.d.ts +1 -1
- package/dist/decorators/api-oauth2.decorator.d.ts +1 -1
- package/dist/decorators/api-security.decorator.d.ts +2 -2
- package/dist/interfaces/index.d.ts +4 -0
- package/dist/swaggerExplorer.js +51 -56
- package/package.json +8 -7
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiBasicAuth(name?: string): ClassDecorator;
|
|
1
|
+
export declare function ApiBasicAuth(name?: string): ClassDecorator & MethodDecorator;
|
|
2
2
|
//# sourceMappingURL=api-basic.decorator.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiBearerAuth(name?: string): ClassDecorator;
|
|
1
|
+
export declare function ApiBearerAuth(name?: string): ClassDecorator & MethodDecorator;
|
|
2
2
|
//# sourceMappingURL=api-bearer.decorator.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiCookieAuth(name?: string): ClassDecorator;
|
|
1
|
+
export declare function ApiCookieAuth(name?: string): ClassDecorator & MethodDecorator;
|
|
2
2
|
//# sourceMappingURL=api-cookie.decorator.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiOAuth2(scopes: string[], name?: string): ClassDecorator;
|
|
1
|
+
export declare function ApiOAuth2(scopes: string[], name?: string): ClassDecorator & MethodDecorator;
|
|
2
2
|
//# sourceMappingURL=api-oauth2.decorator.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { SecurityRequirementObject } from '../interfaces';
|
|
2
|
-
export declare function ApiSecurity(name: string | SecurityRequirementObject, requirements?: string[]): ClassDecorator;
|
|
3
|
-
export declare function ApiExcludeSecurity(): MethodDecorator;
|
|
2
|
+
export declare function ApiSecurity(name: string | SecurityRequirementObject, requirements?: string[]): ClassDecorator & MethodDecorator;
|
|
3
|
+
export declare function ApiExcludeSecurity(): ClassDecorator & MethodDecorator;
|
|
4
4
|
//# sourceMappingURL=api-security.decorator.d.ts.map
|
|
@@ -280,6 +280,10 @@ export interface AuthOptions extends Omit<SecuritySchemeObject, 'type'> {
|
|
|
280
280
|
* authType = cookie 时可以修改,cookie 的名称
|
|
281
281
|
*/
|
|
282
282
|
cookieName?: string;
|
|
283
|
+
/**
|
|
284
|
+
* 添加全局默认要求
|
|
285
|
+
*/
|
|
286
|
+
addSecurityRequirements?: boolean;
|
|
283
287
|
}
|
|
284
288
|
/**
|
|
285
289
|
* see https://swagger.io/specification/
|
package/dist/swaggerExplorer.js
CHANGED
|
@@ -159,8 +159,8 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
159
159
|
if (headers.length > 0) {
|
|
160
160
|
headers = headers.map(item => item.metadata);
|
|
161
161
|
}
|
|
162
|
-
//
|
|
163
|
-
const
|
|
162
|
+
// 过滤出安全信息(方法优先)
|
|
163
|
+
const classSecurity = metaForClass.filter(item => item.key === constants_1.DECORATORS.API_SECURITY);
|
|
164
164
|
// 初始化路径对象
|
|
165
165
|
const paths = {};
|
|
166
166
|
// 如果存在路由信息,则遍历生成路径
|
|
@@ -171,6 +171,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
171
171
|
url = replaceUrl(url, parseParamsInPath(url));
|
|
172
172
|
// 方法元数据
|
|
173
173
|
const metaForMethods = core_1.MetadataManager.getMetadata(constants_1.DECORATORS_METHOD_METADATA, target, webRouter.method) || [];
|
|
174
|
+
const methodSecurity = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_SECURITY);
|
|
174
175
|
// 判断是否忽略当前路由
|
|
175
176
|
const endpoints = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_EXCLUDE_ENDPOINT &&
|
|
176
177
|
item.propertyName === webRouter.method);
|
|
@@ -215,20 +216,26 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
215
216
|
Object.assign(paths[url][webRouter.requestMethod], e.metadata);
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
// 优先级处理:method exclude > method security > class exclude > class security
|
|
220
|
+
const hasMethodExclude = metaForMethods.find(item => item.key === constants_1.DECORATORS.API_EXCLUDE_SECURITY);
|
|
221
|
+
const hasMethodSecurity = methodSecurity.length > 0;
|
|
222
|
+
const hasClassExclude = metaForClass.find(item => item.key === constants_1.DECORATORS.API_EXCLUDE_SECURITY);
|
|
223
|
+
const hasClassSecurity = classSecurity.length > 0;
|
|
224
|
+
if (hasMethodExclude) {
|
|
225
|
+
paths[url][webRouter.requestMethod].security = [];
|
|
226
|
+
}
|
|
227
|
+
else if (hasMethodSecurity) {
|
|
228
|
+
paths[url][webRouter.requestMethod].security = methodSecurity
|
|
229
|
+
.map(s => s.metadata)
|
|
230
|
+
.filter(Boolean);
|
|
231
|
+
}
|
|
232
|
+
else if (hasClassExclude) {
|
|
233
|
+
paths[url][webRouter.requestMethod].security = [];
|
|
234
|
+
}
|
|
235
|
+
else if (hasClassSecurity) {
|
|
236
|
+
paths[url][webRouter.requestMethod].security = classSecurity
|
|
237
|
+
.map(s => s.metadata)
|
|
238
|
+
.filter(Boolean);
|
|
232
239
|
}
|
|
233
240
|
}
|
|
234
241
|
}
|
|
@@ -513,7 +520,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
513
520
|
}
|
|
514
521
|
else {
|
|
515
522
|
tt.content = {
|
|
516
|
-
'text/
|
|
523
|
+
'text/plain': {
|
|
517
524
|
schema: {
|
|
518
525
|
type: convertSchemaType(tt.type),
|
|
519
526
|
},
|
|
@@ -847,52 +854,40 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
847
854
|
if (!opts) {
|
|
848
855
|
return;
|
|
849
856
|
}
|
|
850
|
-
const authType = opts
|
|
851
|
-
|
|
852
|
-
|
|
857
|
+
const { authType, name = '', addSecurityRequirements = false, ...otherOptions } = opts;
|
|
858
|
+
if (!authType) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
853
861
|
switch (authType) {
|
|
854
|
-
case 'basic':
|
|
855
|
-
|
|
856
|
-
const name = opts.name;
|
|
857
|
-
delete opts.name;
|
|
858
|
-
this.documentBuilder.addBasicAuth(opts, name);
|
|
859
|
-
}
|
|
862
|
+
case 'basic': {
|
|
863
|
+
this.documentBuilder.addBasicAuth(otherOptions, name);
|
|
860
864
|
break;
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
delete opts.name;
|
|
865
|
-
this.documentBuilder.addBearerAuth(opts, name);
|
|
866
|
-
}
|
|
865
|
+
}
|
|
866
|
+
case 'bearer': {
|
|
867
|
+
this.documentBuilder.addBearerAuth(otherOptions, name);
|
|
867
868
|
break;
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
delete opts.cookieName;
|
|
873
|
-
delete opts.securityName;
|
|
874
|
-
this.documentBuilder.addCookieAuth(cname, opts, secName);
|
|
875
|
-
}
|
|
869
|
+
}
|
|
870
|
+
case 'cookie': {
|
|
871
|
+
const { cookieName, securityName, ...options } = otherOptions;
|
|
872
|
+
this.documentBuilder.addCookieAuth(cookieName, options, securityName);
|
|
876
873
|
break;
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
delete opts.name;
|
|
881
|
-
this.documentBuilder.addOAuth2(opts, name);
|
|
882
|
-
}
|
|
874
|
+
}
|
|
875
|
+
case 'oauth2': {
|
|
876
|
+
this.documentBuilder.addOAuth2(otherOptions, name);
|
|
883
877
|
break;
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
delete opts.name;
|
|
888
|
-
this.documentBuilder.addApiKey(opts, name);
|
|
889
|
-
}
|
|
878
|
+
}
|
|
879
|
+
case 'apikey': {
|
|
880
|
+
this.documentBuilder.addApiKey(otherOptions, name);
|
|
890
881
|
break;
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
882
|
+
}
|
|
883
|
+
case 'custom': {
|
|
884
|
+
this.documentBuilder.addSecurity(name, otherOptions);
|
|
895
885
|
break;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
if (addSecurityRequirements) {
|
|
889
|
+
// 添加安全要求
|
|
890
|
+
this.documentBuilder.addSecurityRequirements(name);
|
|
896
891
|
}
|
|
897
892
|
}
|
|
898
893
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/swagger",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
"index.html"
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@
|
|
14
|
-
"@midwayjs/
|
|
15
|
-
"@midwayjs/
|
|
16
|
-
"@midwayjs/
|
|
17
|
-
"
|
|
13
|
+
"@apidevtools/swagger-parser": "11.0.1",
|
|
14
|
+
"@midwayjs/core": "^4.0.0-beta.1",
|
|
15
|
+
"@midwayjs/koa": "^4.0.0-beta.1",
|
|
16
|
+
"@midwayjs/mock": "^4.0.0-beta.1",
|
|
17
|
+
"@midwayjs/validate": "^4.0.0-beta.1",
|
|
18
|
+
"swagger-ui-dist": "5.18.3"
|
|
18
19
|
},
|
|
19
20
|
"author": "Kurten Chan <chinkurten@gmail.com>",
|
|
20
21
|
"license": "MIT",
|
|
@@ -28,5 +29,5 @@
|
|
|
28
29
|
"type": "git",
|
|
29
30
|
"url": "https://github.com/midwayjs/midway.git"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
|
|
32
33
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2013 - Now midwayjs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|