@midwayjs/swagger 3.14.13 → 3.14.14-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/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -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-exclude-endpoint.decorator.js +2 -4
- package/dist/decorators/api-extension.decorator.d.ts +1 -1
- package/dist/decorators/api-extra-model.decorator.d.ts +1 -1
- package/dist/decorators/api-header.decorator.js +1 -2
- package/dist/decorators/api-oauth2.decorator.d.ts +1 -1
- package/dist/decorators/api-operation.decorator.js +3 -3
- package/dist/decorators/api-response.decorator.js +1 -2
- package/dist/decorators/api-security.decorator.d.ts +2 -1
- package/dist/decorators/api-security.decorator.js +7 -3
- package/dist/decorators/api-tags.decorator.d.ts +1 -1
- package/dist/decorators/helpers.d.ts +1 -1
- package/dist/decorators/helpers.js +17 -3
- package/dist/interfaces/index.d.ts +5 -0
- package/dist/swaggerExplorer.js +12 -8
- package/package.json +3 -4
- package/LICENSE +0 -21
package/dist/constants.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare const DECORATORS_PREFIX = "swagger";
|
|
2
|
+
export declare const DECORATORS_CLASS_METADATA = "swagger:class_metadata";
|
|
3
|
+
export declare const DECORATORS_METHOD_METADATA = "swagger:method_metadata";
|
|
2
4
|
export declare const DECORATORS: {
|
|
3
5
|
API_OPERATION: string;
|
|
4
6
|
API_RESPONSE: string;
|
|
@@ -9,6 +11,7 @@ export declare const DECORATORS: {
|
|
|
9
11
|
API_EXTRA_MODEL: string;
|
|
10
12
|
API_MODEL_PROPERTIES_ARRAY: string;
|
|
11
13
|
API_SECURITY: string;
|
|
14
|
+
API_EXCLUDE_SECURITY: string;
|
|
12
15
|
API_EXCLUDE_ENDPOINT: string;
|
|
13
16
|
API_EXCLUDE_CONTROLLER: string;
|
|
14
17
|
API_EXTENSION: string;
|
package/dist/constants.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DECORATORS = exports.DECORATORS_PREFIX = void 0;
|
|
3
|
+
exports.DECORATORS = exports.DECORATORS_METHOD_METADATA = exports.DECORATORS_CLASS_METADATA = exports.DECORATORS_PREFIX = void 0;
|
|
4
4
|
exports.DECORATORS_PREFIX = 'swagger';
|
|
5
|
+
exports.DECORATORS_CLASS_METADATA = 'swagger:class_metadata';
|
|
6
|
+
exports.DECORATORS_METHOD_METADATA = 'swagger:method_metadata';
|
|
5
7
|
exports.DECORATORS = {
|
|
6
8
|
API_OPERATION: `${exports.DECORATORS_PREFIX}/apiOperation`,
|
|
7
9
|
API_RESPONSE: `${exports.DECORATORS_PREFIX}/apiResponse`,
|
|
@@ -12,6 +14,7 @@ exports.DECORATORS = {
|
|
|
12
14
|
API_EXTRA_MODEL: `${exports.DECORATORS_PREFIX}/apiExtraModel`,
|
|
13
15
|
API_MODEL_PROPERTIES_ARRAY: `${exports.DECORATORS_PREFIX}/apiModelPropertiesArray`,
|
|
14
16
|
API_SECURITY: `${exports.DECORATORS_PREFIX}/apiSecurity`,
|
|
17
|
+
API_EXCLUDE_SECURITY: `${exports.DECORATORS_PREFIX}/apiExcludeSecurity`,
|
|
15
18
|
API_EXCLUDE_ENDPOINT: `${exports.DECORATORS_PREFIX}/apiExcludeEndpoint`,
|
|
16
19
|
API_EXCLUDE_CONTROLLER: `${exports.DECORATORS_PREFIX}/apiExcludeController`,
|
|
17
20
|
API_EXTENSION: `${exports.DECORATORS_PREFIX}/apiExtension`,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiBasicAuth(name?: string):
|
|
1
|
+
export declare function ApiBasicAuth(name?: string): ClassDecorator;
|
|
2
2
|
//# sourceMappingURL=api-basic.decorator.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiBearerAuth(name?: string):
|
|
1
|
+
export declare function ApiBearerAuth(name?: string): ClassDecorator;
|
|
2
2
|
//# sourceMappingURL=api-bearer.decorator.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiCookieAuth(name?: string):
|
|
1
|
+
export declare function ApiCookieAuth(name?: string): ClassDecorator;
|
|
2
2
|
//# sourceMappingURL=api-cookie.decorator.d.ts.map
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiExcludeEndpoint = void 0;
|
|
4
|
-
const core_1 = require("@midwayjs/core");
|
|
5
4
|
const constants_1 = require("../constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
6
|
function ApiExcludeEndpoint(disable = true) {
|
|
7
|
-
return (0,
|
|
8
|
-
disable,
|
|
9
|
-
}, false);
|
|
7
|
+
return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_EXCLUDE_ENDPOINT, true);
|
|
10
8
|
}
|
|
11
9
|
exports.ApiExcludeEndpoint = ApiExcludeEndpoint;
|
|
12
10
|
//# sourceMappingURL=api-exclude-endpoint.decorator.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiExtension(extensionKey: string, extensionProperties: any):
|
|
1
|
+
export declare function ApiExtension(extensionKey: string, extensionProperties: any): ClassDecorator & MethodDecorator;
|
|
2
2
|
//# sourceMappingURL=api-extension.decorator.d.ts.map
|
|
@@ -4,7 +4,6 @@ exports.ApiHeaders = exports.ApiHeader = void 0;
|
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
5
|
const enum_utils_1 = require("../common/enum.utils");
|
|
6
6
|
const helpers_1 = require("./helpers");
|
|
7
|
-
const core_1 = require("@midwayjs/core");
|
|
8
7
|
const defaultHeaderOptions = {
|
|
9
8
|
name: '',
|
|
10
9
|
};
|
|
@@ -30,7 +29,7 @@ function ApiHeader(options) {
|
|
|
30
29
|
if (descriptor) {
|
|
31
30
|
return (0, helpers_1.createParamDecorator)(param, defaultHeaderOptions)(target, key, descriptor);
|
|
32
31
|
}
|
|
33
|
-
return (0,
|
|
32
|
+
return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_HEADERS, param)(target, undefined, undefined);
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
35
|
exports.ApiHeader = ApiHeader;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiOAuth2(scopes: string[], name?: string):
|
|
1
|
+
export declare function ApiOAuth2(scopes: string[], name?: string): ClassDecorator;
|
|
2
2
|
//# sourceMappingURL=api-oauth2.decorator.d.ts.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiOperation = void 0;
|
|
4
|
-
const core_1 = require("@midwayjs/core");
|
|
5
4
|
const constants_1 = require("../constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
6
|
const defaultOperationOptions = {
|
|
7
7
|
summary: '',
|
|
8
8
|
};
|
|
9
9
|
function ApiOperation(options) {
|
|
10
|
-
return (0,
|
|
10
|
+
return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_OPERATION, {
|
|
11
11
|
...defaultOperationOptions,
|
|
12
12
|
...options,
|
|
13
|
-
}
|
|
13
|
+
});
|
|
14
14
|
}
|
|
15
15
|
exports.ApiOperation = ApiOperation;
|
|
16
16
|
//# sourceMappingURL=api-operation.decorator.js.map
|
|
@@ -4,7 +4,6 @@ exports.ApiDefaultResponse = exports.ApiUnsupportedMediaTypeResponse = exports.A
|
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
6
|
const httpStatus_1 = require("../common/httpStatus");
|
|
7
|
-
const core_1 = require("@midwayjs/core");
|
|
8
7
|
function ApiResponse(options) {
|
|
9
8
|
const [type, isArray] = (0, helpers_1.getTypeIsArrayTuple)(options.type, options.isArray);
|
|
10
9
|
options.type = type;
|
|
@@ -13,7 +12,7 @@ function ApiResponse(options) {
|
|
|
13
12
|
const groupedMetadata = {
|
|
14
13
|
[options.status || 'default']: options,
|
|
15
14
|
};
|
|
16
|
-
return (0,
|
|
15
|
+
return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_RESPONSE, groupedMetadata);
|
|
17
16
|
}
|
|
18
17
|
exports.ApiResponse = ApiResponse;
|
|
19
18
|
const ApiOkResponse = (options = {}) => ApiResponse({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { SecurityRequirementObject } from '../interfaces';
|
|
2
|
-
export declare function ApiSecurity(name: string | SecurityRequirementObject, requirements?: string[]):
|
|
2
|
+
export declare function ApiSecurity(name: string | SecurityRequirementObject, requirements?: string[]): ClassDecorator;
|
|
3
|
+
export declare function ApiExcludeSecurity(): MethodDecorator;
|
|
3
4
|
//# sourceMappingURL=api-security.decorator.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiSecurity = void 0;
|
|
4
|
-
const core_1 = require("@midwayjs/core");
|
|
3
|
+
exports.ApiExcludeSecurity = exports.ApiSecurity = void 0;
|
|
5
4
|
const constants_1 = require("../constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
6
|
function ApiSecurity(name, requirements = []) {
|
|
7
7
|
let metadata;
|
|
8
8
|
if (typeof name === 'string') {
|
|
@@ -11,7 +11,11 @@ function ApiSecurity(name, requirements = []) {
|
|
|
11
11
|
else {
|
|
12
12
|
metadata = name;
|
|
13
13
|
}
|
|
14
|
-
return (0,
|
|
14
|
+
return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_SECURITY, metadata);
|
|
15
15
|
}
|
|
16
16
|
exports.ApiSecurity = ApiSecurity;
|
|
17
|
+
function ApiExcludeSecurity() {
|
|
18
|
+
return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_EXCLUDE_SECURITY, true);
|
|
19
|
+
}
|
|
20
|
+
exports.ApiExcludeSecurity = ApiExcludeSecurity;
|
|
17
21
|
//# sourceMappingURL=api-security.decorator.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiTags(tags: string | string[]):
|
|
1
|
+
export declare function ApiTags(tags: string | string[]): ClassDecorator & MethodDecorator;
|
|
2
2
|
//# sourceMappingURL=api-tags.decorator.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Type } from '../interfaces';
|
|
2
2
|
export declare function createPropertyDecorator<T extends Record<string, any> = any>(metakey: string, metadata: T): PropertyDecorator;
|
|
3
|
-
export declare function createMixedDecorator<T = any>(metakey: string, metadata: T):
|
|
3
|
+
export declare function createMixedDecorator<T = any>(metakey: string, metadata: T): ClassDecorator & MethodDecorator;
|
|
4
4
|
export declare function createParamDecorator<T extends Record<string, any> = any>(metadata: T, initial: Partial<T>): MethodDecorator;
|
|
5
5
|
export declare function getTypeIsArrayTuple(input: Type | undefined | string | Record<string, any>, isArrayFlag: boolean): [Type | undefined | string | Record<string, any>, boolean];
|
|
6
6
|
export declare function getSchemaPath(clzz: Type | string): string;
|
|
@@ -8,14 +8,28 @@ function createPropertyDecorator(metakey, metadata) {
|
|
|
8
8
|
}
|
|
9
9
|
exports.createPropertyDecorator = createPropertyDecorator;
|
|
10
10
|
function createMixedDecorator(metakey, metadata) {
|
|
11
|
-
return (
|
|
11
|
+
return (target, methodName) => {
|
|
12
|
+
if (methodName) {
|
|
13
|
+
(0, core_1.attachPropertyDataToClass)(constants_1.DECORATORS_METHOD_METADATA, {
|
|
14
|
+
key: metakey,
|
|
15
|
+
propertyName: methodName,
|
|
16
|
+
metadata,
|
|
17
|
+
}, target, methodName);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
(0, core_1.attachClassMetadata)(constants_1.DECORATORS_CLASS_METADATA, {
|
|
21
|
+
key: metakey,
|
|
22
|
+
metadata,
|
|
23
|
+
}, target);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
12
26
|
}
|
|
13
27
|
exports.createMixedDecorator = createMixedDecorator;
|
|
14
28
|
function createParamDecorator(metadata, initial) {
|
|
15
|
-
return (
|
|
29
|
+
return createMixedDecorator(constants_1.DECORATORS.API_PARAMETERS, {
|
|
16
30
|
...initial,
|
|
17
31
|
...metadata,
|
|
18
|
-
}
|
|
32
|
+
});
|
|
19
33
|
}
|
|
20
34
|
exports.createParamDecorator = createParamDecorator;
|
|
21
35
|
function getTypeIsArrayTuple(input, isArrayFlag) {
|
|
@@ -374,4 +374,9 @@ export interface SwaggerOptions {
|
|
|
374
374
|
*/
|
|
375
375
|
routerFilter?: (url: string, options: RouterOption) => boolean;
|
|
376
376
|
}
|
|
377
|
+
export interface MixDecoratorMetadata {
|
|
378
|
+
key: string;
|
|
379
|
+
metadata: any;
|
|
380
|
+
propertyName?: string;
|
|
381
|
+
}
|
|
377
382
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/swaggerExplorer.js
CHANGED
|
@@ -105,8 +105,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
105
105
|
}
|
|
106
106
|
// 解析额外的模型
|
|
107
107
|
this.parseExtraModel(target);
|
|
108
|
-
|
|
109
|
-
const metaForClass = (0, core_1.getClassMetadata)(core_1.INJECT_CUSTOM_METHOD, target) || [];
|
|
108
|
+
const metaForClass = (0, core_1.getClassMetadata)(constants_1.DECORATORS_CLASS_METADATA, target) || [];
|
|
110
109
|
// 获取参数的元数据
|
|
111
110
|
const metaForParams = (0, core_1.getClassMetadata)(core_1.INJECT_CUSTOM_PARAM, target) || [];
|
|
112
111
|
// 获取控制器选项
|
|
@@ -165,8 +164,10 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
165
164
|
// 生成URL
|
|
166
165
|
let url = (prefix + webRouter.path).replace('//', '/');
|
|
167
166
|
url = replaceUrl(url, parseParamsInPath(url));
|
|
167
|
+
// 方法元数据
|
|
168
|
+
const metaForMethods = (0, core_1.getPropertyDataFromClass)(constants_1.DECORATORS_METHOD_METADATA, target, webRouter.method) || [];
|
|
168
169
|
// 判断是否忽略当前路由
|
|
169
|
-
const endpoints =
|
|
170
|
+
const endpoints = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_EXCLUDE_ENDPOINT &&
|
|
170
171
|
item.propertyName === webRouter.method);
|
|
171
172
|
// 如果存在需要忽略的路由,则跳过当前循环
|
|
172
173
|
if (endpoints[0]) {
|
|
@@ -192,13 +193,13 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
192
193
|
continue;
|
|
193
194
|
}
|
|
194
195
|
// 生成路由方法
|
|
195
|
-
this.generateRouteMethod(url, webRouter, paths,
|
|
196
|
+
this.generateRouteMethod(url, webRouter, paths, metaForMethods, routerArgs, headers, target);
|
|
196
197
|
// 如果当前路径的标签长度为0,则赋值标签
|
|
197
198
|
if (paths[url][webRouter.requestMethod].tags.length === 0) {
|
|
198
199
|
paths[url][webRouter.requestMethod].tags = strTags;
|
|
199
200
|
}
|
|
200
201
|
// 过滤出扩展信息
|
|
201
|
-
const exts =
|
|
202
|
+
const exts = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_EXTENSION &&
|
|
202
203
|
item.propertyName === webRouter.method);
|
|
203
204
|
// 如果存在扩展信息,则将其添加到路径中
|
|
204
205
|
for (const e of exts) {
|
|
@@ -206,8 +207,11 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
206
207
|
Object.assign(paths[url][webRouter.requestMethod], e.metadata);
|
|
207
208
|
}
|
|
208
209
|
}
|
|
210
|
+
const excludeSecurity = metaForMethods.find(item => {
|
|
211
|
+
return item.key === constants_1.DECORATORS.API_EXCLUDE_SECURITY;
|
|
212
|
+
});
|
|
209
213
|
// 如果存在安全信息,则将其添加到路径中
|
|
210
|
-
if (security.length > 0) {
|
|
214
|
+
if (security.length > 0 && !excludeSecurity) {
|
|
211
215
|
if (!paths[url][webRouter.requestMethod].security) {
|
|
212
216
|
paths[url][webRouter.requestMethod].security = [];
|
|
213
217
|
}
|
|
@@ -559,8 +563,8 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
559
563
|
* @param clzz
|
|
560
564
|
*/
|
|
561
565
|
parseExtraModel(clzz) {
|
|
562
|
-
const
|
|
563
|
-
const extraModels =
|
|
566
|
+
const metaForClass = (0, core_1.getClassMetadata)(constants_1.DECORATORS_CLASS_METADATA, clzz) || [];
|
|
567
|
+
const extraModels = metaForClass.filter(item => item.key === constants_1.DECORATORS.API_EXTRA_MODEL);
|
|
564
568
|
for (const m of extraModels) {
|
|
565
569
|
if (Array.isArray(m.metadata)) {
|
|
566
570
|
for (const sclz of m.metadata) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/swagger",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.14-beta.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@midwayjs/koa": "^3.14.12",
|
|
15
15
|
"@midwayjs/mock": "^3.14.12",
|
|
16
16
|
"@midwayjs/validate": "^3.14.12",
|
|
17
|
-
"swagger-ui-dist": "5.11.
|
|
17
|
+
"swagger-ui-dist": "5.11.7"
|
|
18
18
|
},
|
|
19
19
|
"author": "Kurten Chan <chinkurten@gmail.com>",
|
|
20
20
|
"license": "MIT",
|
|
@@ -27,6 +27,5 @@
|
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
29
|
"url": "https://github.com/midwayjs/midway.git"
|
|
30
|
-
}
|
|
31
|
-
"gitHead": "d145ad36adb40cfe7bf780e2ec07049d5ee90bdd"
|
|
30
|
+
}
|
|
32
31
|
}
|
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.
|