@midwayjs/swagger 3.0.0-beta.10 → 3.0.0-beta.14

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/CHANGELOG.md CHANGED
@@ -3,6 +3,50 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.14](https://github.com/midwayjs/midway/compare/v3.0.0-beta.13...v3.0.0-beta.14) (2022-01-04)
7
+
8
+ **Note:** Version bump only for package @midwayjs/swagger
9
+
10
+
11
+
12
+
13
+
14
+ # [3.0.0-beta.13](https://github.com/midwayjs/midway/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-12-30)
15
+
16
+
17
+ ### Features
18
+
19
+ * add custom decorator filter ([#1477](https://github.com/midwayjs/midway/issues/1477)) ([97501a9](https://github.com/midwayjs/midway/commit/97501a989abc211b0c7400b1df45e050bb237c6a))
20
+
21
+
22
+
23
+
24
+
25
+ # [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * 3.x copy all properties ([#1444](https://github.com/midwayjs/midway/issues/1444)) ([21ec8b6](https://github.com/midwayjs/midway/commit/21ec8b6a85b6ba3f4fbff0c8a571484aaa078788))
31
+
32
+
33
+ ### Features
34
+
35
+ * add fileupload support ([#1439](https://github.com/midwayjs/midway/issues/1439)) ([0a81e72](https://github.com/midwayjs/midway/commit/0a81e720f525ddab0718301f44f80fce376f9bfe))
36
+ * support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
37
+
38
+
39
+
40
+
41
+
42
+ # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
43
+
44
+ **Note:** Version bump only for package @midwayjs/swagger
45
+
46
+
47
+
48
+
49
+
6
50
  # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
7
51
 
8
52
 
@@ -1,10 +1,18 @@
1
1
  import { ContentObject, ExamplesObject, ReferenceObject, RequestBodyObject, SchemaObject, SwaggerEnumType } from '../interfaces';
2
2
  declare type RequestBodyOptions = Omit<RequestBodyObject, 'content'>;
3
+ export declare enum BodyContentType {
4
+ FormUrlEncoded = "application/x-www-form-urlencoded",
5
+ JSON = "application/json",
6
+ Multipart = "multipart/form-data",
7
+ MultipartMixed = "multipart/mixed",
8
+ OctetStream = "application/octet-stream"
9
+ }
3
10
  interface ApiBodyMetadata extends RequestBodyOptions {
4
11
  type?: any;
5
12
  isArray?: boolean;
6
13
  enum?: SwaggerEnumType;
7
14
  content?: ContentObject;
15
+ contentType?: BodyContentType;
8
16
  }
9
17
  interface ApiBodySchemaHost extends RequestBodyOptions {
10
18
  schema: SchemaObject | ReferenceObject;
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiBody = void 0;
3
+ exports.ApiBody = exports.BodyContentType = void 0;
4
4
  const enum_utils_1 = require("../common/enum.utils");
5
5
  const helpers_1 = require("./helpers");
6
+ var BodyContentType;
7
+ (function (BodyContentType) {
8
+ BodyContentType["FormUrlEncoded"] = "application/x-www-form-urlencoded";
9
+ BodyContentType["JSON"] = "application/json";
10
+ BodyContentType["Multipart"] = "multipart/form-data";
11
+ BodyContentType["MultipartMixed"] = "multipart/mixed";
12
+ BodyContentType["OctetStream"] = "application/octet-stream";
13
+ })(BodyContentType = exports.BodyContentType || (exports.BodyContentType = {}));
6
14
  const defaultBodyMetadata = {
7
15
  type: String,
8
16
  required: true,
@@ -4,9 +4,7 @@ exports.ApiExcludeController = void 0;
4
4
  const decorator_1 = require("@midwayjs/decorator");
5
5
  const constants_1 = require("../constants");
6
6
  function ApiExcludeController(disable = true) {
7
- return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_EXCLUDE_CONTROLLER, [
8
- disable,
9
- ]);
7
+ return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_EXCLUDE_CONTROLLER, [disable], false);
10
8
  }
11
9
  exports.ApiExcludeController = ApiExcludeController;
12
10
  //# sourceMappingURL=api-exclude-controller.decorator.js.map
@@ -6,7 +6,7 @@ const constants_1 = require("../constants");
6
6
  function ApiExcludeEndpoint(disable = true) {
7
7
  return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_EXCLUDE_ENDPOINT, {
8
8
  disable,
9
- });
9
+ }, false);
10
10
  }
11
11
  exports.ApiExcludeEndpoint = ApiExcludeEndpoint;
12
12
  //# sourceMappingURL=api-exclude-endpoint.decorator.js.map
@@ -30,7 +30,7 @@ function ApiHeader(options) {
30
30
  if (descriptor) {
31
31
  return (0, helpers_1.createParamDecorator)(param, defaultHeaderOptions)(target, key, descriptor);
32
32
  }
33
- return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_HEADERS, param)(target, undefined, undefined);
33
+ return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_HEADERS, param, false)(target, undefined, undefined);
34
34
  };
35
35
  }
36
36
  exports.ApiHeader = ApiHeader;
@@ -10,7 +10,7 @@ function ApiOperation(options) {
10
10
  return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_OPERATION, {
11
11
  ...defaultOperationOptions,
12
12
  ...options,
13
- });
13
+ }, false);
14
14
  }
15
15
  exports.ApiOperation = ApiOperation;
16
16
  //# sourceMappingURL=api-operation.decorator.js.map
@@ -14,7 +14,6 @@ function createApiPropertyDecorator(options = {}) {
14
14
  options = {
15
15
  ...options,
16
16
  type,
17
- isArray,
18
17
  };
19
18
  if (isEnumArray(options)) {
20
19
  options.type = 'array';
@@ -13,7 +13,7 @@ function ApiResponse(options) {
13
13
  const groupedMetadata = {
14
14
  [options.status || 'default']: options,
15
15
  };
16
- return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_RESPONSE, groupedMetadata);
16
+ return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_RESPONSE, groupedMetadata, false);
17
17
  }
18
18
  exports.ApiResponse = ApiResponse;
19
19
  const ApiOkResponse = (options = {}) => ApiResponse({
@@ -11,7 +11,7 @@ function ApiSecurity(name, requirements = []) {
11
11
  else {
12
12
  metadata = name;
13
13
  }
14
- return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_SECURITY, metadata);
14
+ return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_SECURITY, metadata, false);
15
15
  }
16
16
  exports.ApiSecurity = ApiSecurity;
17
17
  //# sourceMappingURL=api-security.decorator.js.map
@@ -4,18 +4,18 @@ exports.getSchemaPath = exports.getTypeIsArrayTuple = exports.createParamDecorat
4
4
  const decorator_1 = require("@midwayjs/decorator");
5
5
  const constants_1 = require("../constants");
6
6
  function createPropertyDecorator(metakey, metadata) {
7
- return (0, decorator_1.createCustomPropertyDecorator)(metakey, metadata);
7
+ return (0, decorator_1.createCustomPropertyDecorator)(metakey, metadata, false);
8
8
  }
9
9
  exports.createPropertyDecorator = createPropertyDecorator;
10
10
  function createMixedDecorator(metakey, metadata) {
11
- return (0, decorator_1.createCustomMethodDecorator)(metakey, metadata);
11
+ return (0, decorator_1.createCustomMethodDecorator)(metakey, metadata, false);
12
12
  }
13
13
  exports.createMixedDecorator = createMixedDecorator;
14
14
  function createParamDecorator(metadata, initial) {
15
15
  return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_PARAMETERS, {
16
16
  ...initial,
17
17
  ...metadata,
18
- });
18
+ }, false);
19
19
  }
20
20
  exports.createParamDecorator = createParamDecorator;
21
21
  function getTypeIsArrayTuple(input, isArrayFlag) {
@@ -209,16 +209,19 @@ let SwaggerExplorer = class SwaggerExplorer {
209
209
  }
210
210
  this.parseFromParamsToP(params[params.length - 1 - arg.parameterIndex], p);
211
211
  if (p.in === 'body') {
212
+ if (!p.content) {
213
+ p.content = {};
214
+ p.content[p.contentType || 'application/json'] = {
215
+ schema: p.schema,
216
+ };
217
+ }
212
218
  const requestBody = {
213
219
  required: true,
214
220
  description: p.description || p.name,
215
- content: p.content || {
216
- 'application/json': {
217
- schema: p.schema,
218
- },
219
- },
221
+ content: p.content,
220
222
  };
221
223
  opts[webRouter.requestMethod].requestBody = requestBody;
224
+ delete p.contentType;
222
225
  delete p.content;
223
226
  // in body 不需要处理
224
227
  continue;
@@ -316,6 +319,9 @@ let SwaggerExplorer = class SwaggerExplorer {
316
319
  if (param.deprecated) {
317
320
  p.deprecated = param.deprecated;
318
321
  }
322
+ if (param.contentType) {
323
+ p.contentType = param.contentType;
324
+ }
319
325
  p.in = (_a = param === null || param === void 0 ? void 0 : param.in) !== null && _a !== void 0 ? _a : p.in;
320
326
  p.required = (_b = param === null || param === void 0 ? void 0 : param.required) !== null && _b !== void 0 ? _b : p.required;
321
327
  if (p.in === 'query') {
@@ -380,42 +386,55 @@ let SwaggerExplorer = class SwaggerExplorer {
380
386
  };
381
387
  if (props) {
382
388
  Object.keys(props).forEach(key => {
383
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
384
- if ((_a = props[key].metadata) === null || _a === void 0 ? void 0 : _a.example) {
389
+ var _a, _b;
390
+ const metadata = props[key].metadata;
391
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.example) {
385
392
  if (!tt.example) {
386
393
  tt.example = {};
387
394
  }
388
- tt.example[key] = (_b = props[key].metadata) === null || _b === void 0 ? void 0 : _b.example;
395
+ tt.example[key] = metadata === null || metadata === void 0 ? void 0 : metadata.example;
396
+ delete metadata.example;
389
397
  }
390
- if (((_c = props[key].metadata) === null || _c === void 0 ? void 0 : _c.required) !== false) {
398
+ if ((metadata === null || metadata === void 0 ? void 0 : metadata.required) !== false) {
391
399
  if (!tt.required) {
392
400
  tt.required = [];
393
401
  }
394
402
  tt.required.push(key);
403
+ delete metadata.required;
395
404
  }
396
- if ((_d = props[key].metadata) === null || _d === void 0 ? void 0 : _d.enum) {
405
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.enum) {
397
406
  tt.properties[key] = {
398
- type: (_e = props[key].metadata) === null || _e === void 0 ? void 0 : _e.type,
399
- enum: (_f = props[key].metadata) === null || _f === void 0 ? void 0 : _f.enum,
400
- default: (_g = props[key].metadata) === null || _g === void 0 ? void 0 : _g.default,
407
+ type: metadata === null || metadata === void 0 ? void 0 : metadata.type,
408
+ enum: metadata === null || metadata === void 0 ? void 0 : metadata.enum,
409
+ default: metadata === null || metadata === void 0 ? void 0 : metadata.default,
401
410
  };
411
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.description) {
412
+ tt.properties[key].description = metadata === null || metadata === void 0 ? void 0 : metadata.description;
413
+ }
402
414
  return;
403
415
  }
404
- if ((_j = (_h = props[key].metadata) === null || _h === void 0 ? void 0 : _h.items) === null || _j === void 0 ? void 0 : _j.enum) {
416
+ if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _a === void 0 ? void 0 : _a.enum) {
405
417
  tt.properties[key] = {
406
- type: (_k = props[key].metadata) === null || _k === void 0 ? void 0 : _k.type,
407
- items: (_l = props[key].metadata) === null || _l === void 0 ? void 0 : _l.items,
408
- default: (_m = props[key].metadata) === null || _m === void 0 ? void 0 : _m.default,
418
+ type: metadata === null || metadata === void 0 ? void 0 : metadata.type,
419
+ items: metadata === null || metadata === void 0 ? void 0 : metadata.items,
420
+ default: metadata === null || metadata === void 0 ? void 0 : metadata.default,
409
421
  };
422
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.description) {
423
+ tt.properties[key].description = metadata === null || metadata === void 0 ? void 0 : metadata.description;
424
+ }
410
425
  return;
411
426
  }
412
- let currentType = (_o = props[key].metadata) === null || _o === void 0 ? void 0 : _o.type;
427
+ let isArray = false;
428
+ let currentType = metadata === null || metadata === void 0 ? void 0 : metadata.type;
429
+ metadata === null || metadata === void 0 ? true : delete metadata.type;
413
430
  if (currentType === 'array') {
414
- currentType = (_q = (_p = props[key].metadata) === null || _p === void 0 ? void 0 : _p.items) === null || _q === void 0 ? void 0 : _q.type;
431
+ isArray = true;
432
+ currentType = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _b === void 0 ? void 0 : _b.type;
433
+ delete metadata.items;
415
434
  }
416
435
  if ((0, decorator_1.isClass)(currentType)) {
417
436
  this.parseClzz(currentType);
418
- if (((_r = props[key].metadata) === null || _r === void 0 ? void 0 : _r.type) === 'array') {
437
+ if (isArray) {
419
438
  tt.properties[key] = {
420
439
  type: 'array',
421
440
  items: {
@@ -430,7 +449,7 @@ let SwaggerExplorer = class SwaggerExplorer {
430
449
  }
431
450
  }
432
451
  else {
433
- if (((_s = props[key].metadata) === null || _s === void 0 ? void 0 : _s.type) === 'array') {
452
+ if (isArray) {
434
453
  tt.properties[key] = {
435
454
  type: 'array',
436
455
  items: {
@@ -441,10 +460,12 @@ let SwaggerExplorer = class SwaggerExplorer {
441
460
  else {
442
461
  tt.properties[key] = {
443
462
  type: (0, decorator_1.getPropertyType)(clzz.prototype, key).name,
444
- format: (_t = props[key].metadata) === null || _t === void 0 ? void 0 : _t.format,
463
+ format: metadata === null || metadata === void 0 ? void 0 : metadata.format,
445
464
  };
465
+ delete metadata.format;
446
466
  }
447
467
  }
468
+ Object.assign(tt.properties[key], metadata);
448
469
  });
449
470
  }
450
471
  this.documentBuilder.addSchema({
@@ -5,5 +5,6 @@ export declare class SwaggerMiddleware implements IMiddleware<IMidwayContext, Ne
5
5
  private swaggerExplorer;
6
6
  init(): Promise<void>;
7
7
  resolve(app: IMidwayApplication): (req: any, res: any, next: NextFunction) => Promise<any>;
8
+ static getName(): string;
8
9
  }
9
10
  //# sourceMappingURL=swaggerMiddleware.d.ts.map
@@ -100,6 +100,9 @@ let SwaggerMiddleware = class SwaggerMiddleware {
100
100
  };
101
101
  }
102
102
  }
103
+ static getName() {
104
+ return 'swagger';
105
+ }
103
106
  };
104
107
  __decorate([
105
108
  (0, decorator_1.Config)('swagger'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/swagger",
3
- "version": "3.0.0-beta.10",
3
+ "version": "3.0.0-beta.14",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "files": [
@@ -9,11 +9,11 @@
9
9
  "index.d.ts"
10
10
  ],
11
11
  "devDependencies": {
12
- "@midwayjs/core": "^3.0.0-beta.10",
13
- "@midwayjs/decorator": "^3.0.0-beta.10",
14
- "@midwayjs/koa": "^3.0.0-beta.10",
15
- "@midwayjs/mock": "^3.0.0-beta.10",
16
- "swagger-ui-dist": "^3.34.0"
12
+ "@midwayjs/core": "^3.0.0-beta.14",
13
+ "@midwayjs/decorator": "^3.0.0-beta.14",
14
+ "@midwayjs/koa": "^3.0.0-beta.14",
15
+ "@midwayjs/mock": "^3.0.0-beta.14",
16
+ "swagger-ui-dist": "4.1.3"
17
17
  },
18
18
  "author": "Kurten Chan <chinkurten@gmail.com>",
19
19
  "license": "MIT",
@@ -27,5 +27,5 @@
27
27
  "type": "git",
28
28
  "url": "https://github.com/midwayjs/midway.git"
29
29
  },
30
- "gitHead": "153870f2e2dd6b17673ec7591e49224a6bd51b36"
30
+ "gitHead": "95695ada36190cf376e93a1a8866b3fb6dde06bc"
31
31
  }