@midwayjs/swagger 3.3.13 → 3.4.0-beta.10
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 +2 -5
- package/dist/interfaces/index.d.ts +19 -0
- package/dist/swaggerExplorer.js +13 -5
- package/dist/swaggerMiddleware.js +7 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# midway swagger module
|
|
2
2
|
|
|
3
3
|
## Thanks to [@nestjs/swagger](https://github.com/nestjs/swagger)
|
|
4
4
|
|
|
5
|
-
[](http://packagequality.com/#?package=midway-core)
|
|
6
|
-
[](https://github.com/midwayjs/midway/pulls)
|
|
7
|
-
|
|
8
5
|
this is a sub package for midway.
|
|
9
6
|
|
|
10
|
-
Document: [https://midwayjs.org
|
|
7
|
+
Document: [https://midwayjs.org](https://midwayjs.org)
|
|
11
8
|
|
|
12
9
|
## License
|
|
13
10
|
|
|
@@ -336,5 +336,24 @@ export interface SwaggerOptions {
|
|
|
336
336
|
* 可以使用 1-xxx、2-xxx、3-xxx 来定义 tag
|
|
337
337
|
*/
|
|
338
338
|
tagSortable?: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* UI 展示中需要用到的配置
|
|
341
|
+
* 可以参考 https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#display
|
|
342
|
+
*/
|
|
343
|
+
displayOptions?: {
|
|
344
|
+
deepLinking?: boolean;
|
|
345
|
+
displayOperationId?: boolean;
|
|
346
|
+
defaultModelsExpandDepth?: number;
|
|
347
|
+
defaultModelExpandDepth?: number;
|
|
348
|
+
defaultModelRendering?: 'example' | 'model';
|
|
349
|
+
displayRequestDuration?: boolean;
|
|
350
|
+
docExpansion?: 'list' | 'full' | 'none';
|
|
351
|
+
filter?: boolean | string;
|
|
352
|
+
maxDisplayedTags?: number;
|
|
353
|
+
showExtensions?: boolean;
|
|
354
|
+
showCommonExtensions?: boolean;
|
|
355
|
+
useUnsafeMarkdown?: boolean;
|
|
356
|
+
tryItOutEnabled?: boolean;
|
|
357
|
+
};
|
|
339
358
|
}
|
|
340
359
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/swaggerExplorer.js
CHANGED
|
@@ -381,7 +381,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
381
381
|
* @param p
|
|
382
382
|
*/
|
|
383
383
|
parseFromParamsToP(paramMeta, p) {
|
|
384
|
-
var _a, _b, _c
|
|
384
|
+
var _a, _b, _c;
|
|
385
385
|
if (paramMeta) {
|
|
386
386
|
const param = paramMeta.metadata;
|
|
387
387
|
if (param) {
|
|
@@ -392,7 +392,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
392
392
|
if (param.in === 'query') {
|
|
393
393
|
p.allowEmptyValue = param.allowEmptyValue || false;
|
|
394
394
|
}
|
|
395
|
-
if (param.example) {
|
|
395
|
+
if (typeof param.example !== undefined) {
|
|
396
396
|
p.example = param.example;
|
|
397
397
|
}
|
|
398
398
|
if (param.examples) {
|
|
@@ -432,13 +432,22 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
432
432
|
};
|
|
433
433
|
}
|
|
434
434
|
if (param.isArray) {
|
|
435
|
+
let ref;
|
|
436
|
+
if ((_c = p === null || p === void 0 ? void 0 : p.schema) === null || _c === void 0 ? void 0 : _c.$ref) {
|
|
437
|
+
ref = p.schema.$ref;
|
|
438
|
+
}
|
|
435
439
|
p.schema = {
|
|
436
440
|
type: 'array',
|
|
437
441
|
items: {
|
|
438
|
-
type: (_d = (_c = p === null || p === void 0 ? void 0 : p.schema) === null || _c === void 0 ? void 0 : _c.$ref) !== null && _d !== void 0 ? _d : convertSchemaType(param.type),
|
|
439
442
|
format: param.format,
|
|
440
443
|
},
|
|
441
444
|
};
|
|
445
|
+
if (ref) {
|
|
446
|
+
p.schema.items.$ref = ref;
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
p.schema.items.type = convertSchemaType(param.type);
|
|
450
|
+
}
|
|
442
451
|
}
|
|
443
452
|
else {
|
|
444
453
|
if (!p.schema) {
|
|
@@ -492,12 +501,11 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
492
501
|
Object.keys(props).forEach(key => {
|
|
493
502
|
var _a, _b;
|
|
494
503
|
const metadata = props[key].metadata;
|
|
495
|
-
if (metadata === null || metadata === void 0 ? void 0 : metadata.example) {
|
|
504
|
+
if (typeof (metadata === null || metadata === void 0 ? void 0 : metadata.example) !== undefined) {
|
|
496
505
|
if (!tt.example) {
|
|
497
506
|
tt.example = {};
|
|
498
507
|
}
|
|
499
508
|
tt.example[key] = metadata === null || metadata === void 0 ? void 0 : metadata.example;
|
|
500
|
-
delete metadata.example;
|
|
501
509
|
}
|
|
502
510
|
if (typeof (metadata === null || metadata === void 0 ? void 0 : metadata.required) !== undefined) {
|
|
503
511
|
if (metadata === null || metadata === void 0 ? void 0 : metadata.required) {
|
|
@@ -103,7 +103,13 @@ let SwaggerMiddleware = class SwaggerMiddleware {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
replaceInfo(content) {
|
|
106
|
-
|
|
106
|
+
let str = `location.href.replace('${this.swaggerConfig.swaggerPath}/index.html', '${this.swaggerConfig.swaggerPath}/index.json'),\n validatorUrl: null,`;
|
|
107
|
+
if (this.swaggerConfig.displayOptions) {
|
|
108
|
+
Object.keys(this.swaggerConfig.displayOptions).forEach(key => {
|
|
109
|
+
str += `\n${key}: ${this.swaggerConfig.displayOptions[key]},`;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return content.replace('"https://petstore.swagger.io/v2/swagger.json",', str);
|
|
107
113
|
}
|
|
108
114
|
static getName() {
|
|
109
115
|
return 'swagger';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/swagger",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.10",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
"index.d.ts"
|
|
10
10
|
],
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@midwayjs/core": "^3.
|
|
13
|
-
"@midwayjs/decorator": "^3.
|
|
14
|
-
"@midwayjs/koa": "^3.
|
|
15
|
-
"@midwayjs/mock": "^3.
|
|
16
|
-
"
|
|
12
|
+
"@midwayjs/core": "^3.4.0-beta.10",
|
|
13
|
+
"@midwayjs/decorator": "^3.4.0-beta.10",
|
|
14
|
+
"@midwayjs/koa": "^3.4.0-beta.10",
|
|
15
|
+
"@midwayjs/mock": "^3.4.0-beta.10",
|
|
16
|
+
"@midwayjs/validate": "^3.4.0-beta.10",
|
|
17
|
+
"swagger-ui-dist": "4.12.0"
|
|
17
18
|
},
|
|
18
19
|
"author": "Kurten Chan <chinkurten@gmail.com>",
|
|
19
20
|
"license": "MIT",
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
"type": "git",
|
|
28
29
|
"url": "https://github.com/midwayjs/midway.git"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "560a5fa311605e4008c55f31c31bc4e12eeff2a5"
|
|
31
32
|
}
|