@midwayjs/swagger 3.0.4 → 3.0.5

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.
@@ -10,6 +10,7 @@ export declare class SwaggerExplorer {
10
10
  * 构造 router 提取方法
11
11
  */
12
12
  private generateRouteMethod;
13
+ private expandSchemaRef;
13
14
  /**
14
15
  * 提取参数
15
16
  * @param params
@@ -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, _l;
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: ((_c = operMeta === null || operMeta === void 0 ? void 0 : operMeta.metadata) === null || _c === void 0 ? void 0 : _c.operationId) || webRouter.method,
192
- tags: ((_d = operMeta === null || operMeta === void 0 ? void 0 : operMeta.metadata) === null || _d === void 0 ? void 0 : _d.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: (_f = (_e = arg === null || arg === void 0 ? void 0 : arg.metadata) === null || _e === void 0 ? void 0 : _e.propertyData) !== null && _f !== void 0 ? _f : '',
207
- in: convertTypeToString((_g = arg.metadata) === null || _g === void 0 ? void 0 : _g.type),
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((_h = currentType === null || currentType === void 0 ? void 0 : currentType.name) !== null && _h !== void 0 ? _h : currentType),
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 (((_j = arg.metadata) === null || _j === void 0 ? void 0 : _j.type) === decorator_1.RouteParamTypes.FILESSTREAM) {
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 (((_k = arg.metadata) === null || _k === void 0 ? void 0 : _k.type) === decorator_1.RouteParamTypes.FILESTREAM) {
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 (((_l = arg.metadata) === null || _l === void 0 ? void 0 : _l.type) === decorator_1.RouteParamTypes.FIELDS) {
260
- if (p.schema['$ref']) {
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.4",
3
+ "version": "3.0.5",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "files": [
@@ -11,8 +11,8 @@
11
11
  "devDependencies": {
12
12
  "@midwayjs/core": "^3.0.4",
13
13
  "@midwayjs/decorator": "^3.0.4",
14
- "@midwayjs/koa": "^3.0.4",
15
- "@midwayjs/mock": "^3.0.4",
14
+ "@midwayjs/koa": "^3.0.5",
15
+ "@midwayjs/mock": "^3.0.5",
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": "c2a37dd026c7bf3e855f4498691f572ef61396e3"
30
+ "gitHead": "9b17898f10faeef2e7f1011eaea67f1d0b085261"
31
31
  }