@midwayjs/swagger 3.18.0 → 3.18.2
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.
|
@@ -3,7 +3,7 @@ export declare function getEnumValues(enumType: SwaggerEnumType): string[] | num
|
|
|
3
3
|
export declare function getEnumType(values: (string | number)[]): 'string' | 'number';
|
|
4
4
|
export declare function addEnumArraySchema(paramDefinition: Partial<Record<'schema' | 'isArray' | 'enumName', any>>, decoratorOptions: Partial<Record<'enum' | 'enumName', any>>): void;
|
|
5
5
|
export declare function addEnumSchema(paramDefinition: Partial<Record<string, any>>, decoratorOptions: Partial<Record<string, any>>): void;
|
|
6
|
-
export declare const isEnumArray: <T extends Partial<Record<"
|
|
6
|
+
export declare const isEnumArray: <T extends Partial<Record<"isArray" | "enum", any>>>(obj: Record<string, any>) => obj is T;
|
|
7
7
|
export declare const isEnumDefined: <T extends Partial<Record<"enum", any>>>(obj: Record<string, any>) => obj is T;
|
|
8
8
|
export declare const isEnumMetadata: (metadata: SchemaObjectMetadata) => any;
|
|
9
9
|
//# sourceMappingURL=enum.utils.d.ts.map
|
|
@@ -8,19 +8,10 @@ function getEnumValues(enumType) {
|
|
|
8
8
|
if (typeof enumType !== 'object') {
|
|
9
9
|
return [];
|
|
10
10
|
}
|
|
11
|
-
const values =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/* eslint-disable no-prototype-builtins */
|
|
16
|
-
// filter out cases where enum key also becomes its value (A: B, B: A)
|
|
17
|
-
if (!uniqueValues.hasOwnProperty(value) &&
|
|
18
|
-
!uniqueValues.hasOwnProperty(key)) {
|
|
19
|
-
values.push(value);
|
|
20
|
-
uniqueValues[value] = value;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return values;
|
|
11
|
+
const values = Object.keys(enumType)
|
|
12
|
+
.filter(key => isNaN(Number(key)))
|
|
13
|
+
.map(key => enumType[key]);
|
|
14
|
+
return Array.from(new Set(values));
|
|
24
15
|
}
|
|
25
16
|
exports.getEnumValues = getEnumValues;
|
|
26
17
|
function getEnumType(values) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ApiExcludeController(disable?: boolean):
|
|
1
|
+
export declare function ApiExcludeController(disable?: boolean): ClassDecorator;
|
|
2
2
|
//# sourceMappingURL=api-exclude-controller.decorator.d.ts.map
|
package/dist/swaggerExplorer.js
CHANGED
|
@@ -14,6 +14,7 @@ const core_1 = require("@midwayjs/core");
|
|
|
14
14
|
const constants_1 = require("./constants");
|
|
15
15
|
const documentBuilder_1 = require("./documentBuilder");
|
|
16
16
|
const _1 = require(".");
|
|
17
|
+
const enum_utils_1 = require("./common/enum.utils");
|
|
17
18
|
let SwaggerExplorer = class SwaggerExplorer {
|
|
18
19
|
constructor() {
|
|
19
20
|
this.swaggerConfig = {};
|
|
@@ -486,7 +487,16 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
486
487
|
for (const k of keys) {
|
|
487
488
|
// 这里是引用,赋值可以直接更改
|
|
488
489
|
const tt = resp[k];
|
|
489
|
-
if (tt.
|
|
490
|
+
if (tt.schema) {
|
|
491
|
+
// response 的 schema 需要包含在 content 内
|
|
492
|
+
tt.content = {
|
|
493
|
+
'application/json': {
|
|
494
|
+
schema: this.formatType(tt.schema),
|
|
495
|
+
},
|
|
496
|
+
};
|
|
497
|
+
delete tt.schema;
|
|
498
|
+
}
|
|
499
|
+
else if (tt.type) {
|
|
490
500
|
if (core_1.Types.isClass(tt.type)) {
|
|
491
501
|
this.parseClzz(tt.type);
|
|
492
502
|
if (tt.isArray) {
|
|
@@ -665,8 +675,14 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
665
675
|
}
|
|
666
676
|
// 如果有枚举,单独处理
|
|
667
677
|
if (metadata.enum) {
|
|
668
|
-
|
|
669
|
-
|
|
678
|
+
if (Array.isArray(metadata.enum)) {
|
|
679
|
+
// enum 不需要处理
|
|
680
|
+
metadata.enum.map(item => this.formatType(item));
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
// 枚举类型需要处理
|
|
684
|
+
metadata.enum = (0, enum_utils_1.getEnumValues)(metadata.enum);
|
|
685
|
+
}
|
|
670
686
|
}
|
|
671
687
|
if (metadata.not) {
|
|
672
688
|
metadata.not = this.formatType(metadata.not);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/swagger",
|
|
3
|
-
"version": "3.18.
|
|
3
|
+
"version": "3.18.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@midwayjs/core": "^3.18.0",
|
|
14
|
-
"@midwayjs/koa": "^3.18.
|
|
15
|
-
"@midwayjs/mock": "^3.18.
|
|
16
|
-
"@midwayjs/validate": "^3.18.
|
|
14
|
+
"@midwayjs/koa": "^3.18.2",
|
|
15
|
+
"@midwayjs/mock": "^3.18.2",
|
|
16
|
+
"@midwayjs/validate": "^3.18.2",
|
|
17
17
|
"swagger-ui-dist": "5.17.14"
|
|
18
18
|
},
|
|
19
19
|
"author": "Kurten Chan <chinkurten@gmail.com>",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"type": "git",
|
|
28
28
|
"url": "https://github.com/midwayjs/midway.git"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "0cf1ac5a107aa1de73ff184f403cba2be0a408f4"
|
|
31
31
|
}
|