@midwayjs/swagger 3.0.4 → 3.0.8
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/swaggerExplorer.d.ts +1 -0
- package/dist/swaggerExplorer.js +33 -16
- package/package.json +6 -6
package/dist/swaggerExplorer.js
CHANGED
|
@@ -177,7 +177,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
177
177
|
* 构造 router 提取方法
|
|
178
178
|
*/
|
|
179
179
|
generateRouteMethod(url, webRouter, paths, metaForMethods, routerArgs, header, target) {
|
|
180
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
180
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
181
181
|
const operMeta = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_OPERATION &&
|
|
182
182
|
item.propertyName === webRouter.method)[0];
|
|
183
183
|
let opts = paths[url];
|
|
@@ -188,8 +188,8 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
188
188
|
opts[webRouter.requestMethod] = {
|
|
189
189
|
summary: (_a = operMeta === null || operMeta === void 0 ? void 0 : operMeta.metadata) === null || _a === void 0 ? void 0 : _a.summary,
|
|
190
190
|
description: (_b = operMeta === null || operMeta === void 0 ? void 0 : operMeta.metadata) === null || _b === void 0 ? void 0 : _b.description,
|
|
191
|
-
operationId: (
|
|
192
|
-
tags: ((
|
|
191
|
+
// operationId: `${webRouter.requestMethod}_${(operMeta?.metadata?.operationId || webRouter.method)}`,
|
|
192
|
+
tags: ((_c = operMeta === null || operMeta === void 0 ? void 0 : operMeta.metadata) === null || _c === void 0 ? void 0 : _c.tags) || [],
|
|
193
193
|
};
|
|
194
194
|
/**
|
|
195
195
|
* [{"key":"web:router_param","parameterIndex":1,"propertyName":"create","metadata":{"type":2}},
|
|
@@ -203,8 +203,8 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
203
203
|
for (const arg of args) {
|
|
204
204
|
const currentType = types[arg.parameterIndex];
|
|
205
205
|
const p = {
|
|
206
|
-
name: (
|
|
207
|
-
in: convertTypeToString((
|
|
206
|
+
name: (_e = (_d = arg === null || arg === void 0 ? void 0 : arg.metadata) === null || _d === void 0 ? void 0 : _d.propertyData) !== null && _e !== void 0 ? _e : '',
|
|
207
|
+
in: convertTypeToString((_f = arg.metadata) === null || _f === void 0 ? void 0 : _f.type),
|
|
208
208
|
required: false,
|
|
209
209
|
};
|
|
210
210
|
if (p.in === 'path') {
|
|
@@ -221,13 +221,16 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
221
221
|
}
|
|
222
222
|
else {
|
|
223
223
|
p.schema = {
|
|
224
|
-
type: convertSchemaType((
|
|
224
|
+
type: convertSchemaType((_g = currentType === null || currentType === void 0 ? void 0 : currentType.name) !== null && _g !== void 0 ? _g : currentType),
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
227
|
this.parseFromParamsToP(params[params.length - 1 - arg.parameterIndex], p);
|
|
228
228
|
if (p.in === 'body') {
|
|
229
|
+
if (webRouter.requestMethod === decorator_1.RequestMethod.GET) {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
229
232
|
// 这里兼容一下 @File()、@Files()、@Fields() 装饰器
|
|
230
|
-
if (((
|
|
233
|
+
if (((_h = arg.metadata) === null || _h === void 0 ? void 0 : _h.type) === decorator_1.RouteParamTypes.FILESSTREAM) {
|
|
231
234
|
p.schema = {
|
|
232
235
|
type: 'object',
|
|
233
236
|
properties: {
|
|
@@ -243,7 +246,7 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
243
246
|
};
|
|
244
247
|
p.contentType = _1.BodyContentType.Multipart;
|
|
245
248
|
}
|
|
246
|
-
if (((
|
|
249
|
+
if (((_j = arg.metadata) === null || _j === void 0 ? void 0 : _j.type) === decorator_1.RouteParamTypes.FILESTREAM) {
|
|
247
250
|
p.schema = {
|
|
248
251
|
type: 'object',
|
|
249
252
|
properties: {
|
|
@@ -256,14 +259,8 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
256
259
|
};
|
|
257
260
|
p.contentType = _1.BodyContentType.Multipart;
|
|
258
261
|
}
|
|
259
|
-
if (((
|
|
260
|
-
|
|
261
|
-
// 展开各个字段属性
|
|
262
|
-
const name = p.schema['$ref'].replace('#/components/schemas/', '');
|
|
263
|
-
const schema = this.documentBuilder.getSchema(name);
|
|
264
|
-
delete p.schema['$ref'];
|
|
265
|
-
p.schema = JSON.parse(JSON.stringify(schema));
|
|
266
|
-
}
|
|
262
|
+
if (((_k = arg.metadata) === null || _k === void 0 ? void 0 : _k.type) === decorator_1.RouteParamTypes.FIELDS) {
|
|
263
|
+
this.expandSchemaRef(p);
|
|
267
264
|
p.contentType = _1.BodyContentType.Multipart;
|
|
268
265
|
}
|
|
269
266
|
if (!p.content) {
|
|
@@ -360,6 +357,23 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
360
357
|
}
|
|
361
358
|
paths[url] = opts;
|
|
362
359
|
}
|
|
360
|
+
expandSchemaRef(p, name) {
|
|
361
|
+
let schemaName = name;
|
|
362
|
+
if (p.schema['$ref']) {
|
|
363
|
+
// 展开各个字段属性
|
|
364
|
+
schemaName = p.schema['$ref'].replace('#/components/schemas/', '');
|
|
365
|
+
delete p.schema['$ref'];
|
|
366
|
+
}
|
|
367
|
+
const schema = this.documentBuilder.getSchema(schemaName);
|
|
368
|
+
const ss = JSON.parse(JSON.stringify(schema));
|
|
369
|
+
if (p.schema.properties) {
|
|
370
|
+
Object.assign(p.schema.properties, ss.properties);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
p.schema = JSON.parse(JSON.stringify(schema));
|
|
374
|
+
}
|
|
375
|
+
return p;
|
|
376
|
+
}
|
|
363
377
|
/**
|
|
364
378
|
* 提取参数
|
|
365
379
|
* @param params
|
|
@@ -371,6 +385,9 @@ let SwaggerExplorer = class SwaggerExplorer {
|
|
|
371
385
|
const param = paramMeta.metadata;
|
|
372
386
|
if (param) {
|
|
373
387
|
p.description = param.description;
|
|
388
|
+
if (!p.name && param.name) {
|
|
389
|
+
p.name = param.name;
|
|
390
|
+
}
|
|
374
391
|
if (param.in === 'query') {
|
|
375
392
|
p.allowEmptyValue = param.allowEmptyValue || false;
|
|
376
393
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/swagger",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"index.d.ts"
|
|
10
10
|
],
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@midwayjs/core": "^3.0.
|
|
13
|
-
"@midwayjs/decorator": "^3.0.
|
|
14
|
-
"@midwayjs/koa": "^3.0.
|
|
15
|
-
"@midwayjs/mock": "^3.0.
|
|
12
|
+
"@midwayjs/core": "^3.0.7",
|
|
13
|
+
"@midwayjs/decorator": "^3.0.7",
|
|
14
|
+
"@midwayjs/koa": "^3.0.8",
|
|
15
|
+
"@midwayjs/mock": "^3.0.7",
|
|
16
16
|
"swagger-ui-dist": "4.5.0"
|
|
17
17
|
},
|
|
18
18
|
"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": "5e58d30e217ef06096cebf588e19b8ce020a3d96"
|
|
31
31
|
}
|