@midwayjs/swagger 3.0.0-beta.15 → 3.0.0
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/LICENSE +21 -0
- package/dist/documentBuilder.d.ts +1 -0
- package/dist/documentBuilder.js +22 -1
- package/dist/interfaces/index.d.ts +5 -0
- package/dist/swaggerExplorer.js +16 -6
- package/index.d.ts +1 -1
- package/package.json +9 -9
- package/CHANGELOG.md +0 -68
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
|
@@ -21,6 +21,7 @@ export declare class DocumentBuilder {
|
|
|
21
21
|
addApiKey(options?: SecuritySchemeObject, name?: string): this;
|
|
22
22
|
addBasicAuth(options?: SecuritySchemeObject, name?: string): this;
|
|
23
23
|
addCookieAuth(cookieName?: string, options?: SecuritySchemeObject, securityName?: string): this;
|
|
24
|
+
sortTags(): void;
|
|
24
25
|
build(): Omit<OpenAPIObject, 'paths'>;
|
|
25
26
|
}
|
|
26
27
|
//# sourceMappingURL=documentBuilder.d.ts.map
|
package/dist/documentBuilder.js
CHANGED
|
@@ -78,7 +78,11 @@ class DocumentBuilder {
|
|
|
78
78
|
return this;
|
|
79
79
|
}
|
|
80
80
|
getSchema(name) {
|
|
81
|
-
|
|
81
|
+
var _a, _b;
|
|
82
|
+
if ((_a = this.document.components) === null || _a === void 0 ? void 0 : _a.schemas) {
|
|
83
|
+
return (_b = this.document.components) === null || _b === void 0 ? void 0 : _b.schemas[name];
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
82
86
|
}
|
|
83
87
|
addTag(name, description = '', externalDocs) {
|
|
84
88
|
if (Array.isArray(name)) {
|
|
@@ -187,6 +191,23 @@ class DocumentBuilder {
|
|
|
187
191
|
});
|
|
188
192
|
return this;
|
|
189
193
|
}
|
|
194
|
+
sortTags() {
|
|
195
|
+
const tags = this.document.tags;
|
|
196
|
+
this.document.tags = tags.sort((a, b) => {
|
|
197
|
+
const s1 = a.name;
|
|
198
|
+
const s2 = b.name;
|
|
199
|
+
const len = s1.length > s2.length ? s2.length : s1.length;
|
|
200
|
+
for (let i = 0; i < len; i++) {
|
|
201
|
+
if (s1.charCodeAt(i) > s2.charCodeAt(i)) {
|
|
202
|
+
return 1;
|
|
203
|
+
}
|
|
204
|
+
else if (s1.charCodeAt(i) < s2.charCodeAt(i)) {
|
|
205
|
+
return -1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return 0;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
190
211
|
build() {
|
|
191
212
|
return this.document;
|
|
192
213
|
}
|
package/dist/swaggerExplorer.js
CHANGED
|
@@ -63,10 +63,14 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
scanApp() {
|
|
66
|
+
var _a;
|
|
66
67
|
const routes = (0, decorator_1.listModule)(decorator_1.CONTROLLER_KEY);
|
|
67
68
|
for (const route of routes) {
|
|
68
69
|
this.generatePath(route);
|
|
69
70
|
}
|
|
71
|
+
if ((_a = this.swaggerConfig) === null || _a === void 0 ? void 0 : _a.tagSortable) {
|
|
72
|
+
this.documentBuilder.sortTags();
|
|
73
|
+
}
|
|
70
74
|
}
|
|
71
75
|
getData() {
|
|
72
76
|
return this.documentBuilder.build();
|
|
@@ -99,11 +103,12 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
99
103
|
(controllerOption === null || controllerOption === void 0 ? void 0 : controllerOption.routerOptions.description) || tag.name;
|
|
100
104
|
}
|
|
101
105
|
else {
|
|
102
|
-
tag.name =
|
|
106
|
+
tag.name = controllerOption === null || controllerOption === void 0 ? void 0 : controllerOption.routerOptions.tagName;
|
|
103
107
|
tag.description =
|
|
104
108
|
(controllerOption === null || controllerOption === void 0 ? void 0 : controllerOption.routerOptions.description) || tag.name;
|
|
105
109
|
}
|
|
106
110
|
if (tag.name) {
|
|
111
|
+
strTags.push(tag.name);
|
|
107
112
|
this.documentBuilder.addTag(tag.name, tag.description);
|
|
108
113
|
}
|
|
109
114
|
}
|
|
@@ -197,7 +202,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
197
202
|
continue;
|
|
198
203
|
}
|
|
199
204
|
}
|
|
200
|
-
if (
|
|
205
|
+
if (decorator_1.Types.isClass(currentType)) {
|
|
201
206
|
this.parseClzz(currentType);
|
|
202
207
|
p.schema = {
|
|
203
208
|
$ref: '#/components/schemas/' + currentType.name,
|
|
@@ -213,6 +218,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
213
218
|
// 这里兼容一下 @File()、@Files()、@Fields() 装饰器
|
|
214
219
|
if (((_j = arg.metadata) === null || _j === void 0 ? void 0 : _j.type) === decorator_1.RouteParamTypes.FILESSTREAM) {
|
|
215
220
|
p.schema = {
|
|
221
|
+
type: 'object',
|
|
216
222
|
properties: {
|
|
217
223
|
files: {
|
|
218
224
|
type: 'array',
|
|
@@ -228,6 +234,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
228
234
|
}
|
|
229
235
|
if (((_k = arg.metadata) === null || _k === void 0 ? void 0 : _k.type) === decorator_1.RouteParamTypes.FILESTREAM) {
|
|
230
236
|
p.schema = {
|
|
237
|
+
type: 'object',
|
|
231
238
|
properties: {
|
|
232
239
|
file: {
|
|
233
240
|
type: 'string',
|
|
@@ -289,7 +296,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
289
296
|
// 这里是引用,赋值可以直接更改
|
|
290
297
|
const tt = resp[k];
|
|
291
298
|
if (tt.type) {
|
|
292
|
-
if (
|
|
299
|
+
if (decorator_1.Types.isClass(tt.type)) {
|
|
293
300
|
this.parseClzz(tt.type);
|
|
294
301
|
if (tt.isArray) {
|
|
295
302
|
tt.content = {
|
|
@@ -389,7 +396,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
389
396
|
}
|
|
390
397
|
else {
|
|
391
398
|
if (param.type) {
|
|
392
|
-
if (
|
|
399
|
+
if (decorator_1.Types.isClass(param.type)) {
|
|
393
400
|
this.parseClzz(param.type);
|
|
394
401
|
p.schema = {
|
|
395
402
|
$ref: '#/components/schemas/' + param.type.name,
|
|
@@ -425,6 +432,9 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
425
432
|
* @param clzz
|
|
426
433
|
*/
|
|
427
434
|
parseClzz(clzz) {
|
|
435
|
+
if (this.documentBuilder.getSchema(clzz.name)) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
428
438
|
const props = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_PROPERTY, clzz);
|
|
429
439
|
const tt = {
|
|
430
440
|
type: 'object',
|
|
@@ -478,7 +488,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
478
488
|
currentType = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _b === void 0 ? void 0 : _b.type;
|
|
479
489
|
delete metadata.items;
|
|
480
490
|
}
|
|
481
|
-
if (
|
|
491
|
+
if (decorator_1.Types.isClass(currentType)) {
|
|
482
492
|
this.parseClzz(currentType);
|
|
483
493
|
if (isArray) {
|
|
484
494
|
tt.properties[key] = {
|
|
@@ -644,7 +654,7 @@ function convertSchemaType(value) {
|
|
|
644
654
|
case 'String':
|
|
645
655
|
return 'string';
|
|
646
656
|
default:
|
|
647
|
-
return
|
|
657
|
+
return value;
|
|
648
658
|
}
|
|
649
659
|
}
|
|
650
660
|
//# sourceMappingURL=swaggerExplorer.js.map
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/swagger",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -9,23 +9,23 @@
|
|
|
9
9
|
"index.d.ts"
|
|
10
10
|
],
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@midwayjs/core": "^3.0.0
|
|
13
|
-
"@midwayjs/decorator": "^3.0.0
|
|
14
|
-
"@midwayjs/koa": "^3.0.0
|
|
15
|
-
"@midwayjs/mock": "^3.0.0
|
|
16
|
-
"swagger-ui-dist": "4.1
|
|
12
|
+
"@midwayjs/core": "^3.0.0",
|
|
13
|
+
"@midwayjs/decorator": "^3.0.0",
|
|
14
|
+
"@midwayjs/koa": "^3.0.0",
|
|
15
|
+
"@midwayjs/mock": "^3.0.0",
|
|
16
|
+
"swagger-ui-dist": "4.2.1"
|
|
17
17
|
},
|
|
18
18
|
"author": "Kurten Chan <chinkurten@gmail.com>",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsc",
|
|
22
22
|
"jest": "node --require=ts-node/register ../../node_modules/jest/bin/jest.js",
|
|
23
|
-
"test": "node --require=ts-node/register ../../node_modules/.bin/jest",
|
|
24
|
-
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --coverage --forceExit"
|
|
23
|
+
"test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
|
|
24
|
+
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
28
|
"url": "https://github.com/midwayjs/midway.git"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "55c26029bccf7bbb739fa1597e8f418dafa2caa0"
|
|
31
31
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [3.0.0-beta.15](https://github.com/midwayjs/midway/compare/v3.0.0-beta.14...v3.0.0-beta.15) (2022-01-07)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Features
|
|
10
|
-
|
|
11
|
-
* compatible with @File/@Files/@Fields ([#1527](https://github.com/midwayjs/midway/issues/1527)) ([3fe983f](https://github.com/midwayjs/midway/commit/3fe983f2a67c366af370c41df98510adf5dab289))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# [3.0.0-beta.14](https://github.com/midwayjs/midway/compare/v3.0.0-beta.13...v3.0.0-beta.14) (2022-01-04)
|
|
18
|
-
|
|
19
|
-
**Note:** Version bump only for package @midwayjs/swagger
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# [3.0.0-beta.13](https://github.com/midwayjs/midway/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-12-30)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Features
|
|
29
|
-
|
|
30
|
-
* add custom decorator filter ([#1477](https://github.com/midwayjs/midway/issues/1477)) ([97501a9](https://github.com/midwayjs/midway/commit/97501a989abc211b0c7400b1df45e050bb237c6a))
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### Bug Fixes
|
|
40
|
-
|
|
41
|
-
* 3.x copy all properties ([#1444](https://github.com/midwayjs/midway/issues/1444)) ([21ec8b6](https://github.com/midwayjs/midway/commit/21ec8b6a85b6ba3f4fbff0c8a571484aaa078788))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
### Features
|
|
45
|
-
|
|
46
|
-
* add fileupload support ([#1439](https://github.com/midwayjs/midway/issues/1439)) ([0a81e72](https://github.com/midwayjs/midway/commit/0a81e720f525ddab0718301f44f80fce376f9bfe))
|
|
47
|
-
* support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
|
|
54
|
-
|
|
55
|
-
**Note:** Version bump only for package @midwayjs/swagger
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
# [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
### Features
|
|
65
|
-
|
|
66
|
-
* 3.x swagger ([#1409](https://github.com/midwayjs/midway/issues/1409)) ([e00fbbf](https://github.com/midwayjs/midway/commit/e00fbbf7a494f300a53f3bd8635966364cfd96a9))
|
|
67
|
-
* add swagger doc & fix bug ([#1427](https://github.com/midwayjs/midway/issues/1427)) ([82dc6f1](https://github.com/midwayjs/midway/commit/82dc6f10f7244a75f58922edda1b0625fc6cb90e))
|
|
68
|
-
* support express ([61e73db](https://github.com/midwayjs/midway/commit/61e73db509bfea21c8251855fccb02a4ce09988f))
|