@midwayjs/swagger 4.0.0-beta.1 → 4.0.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/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.
package/README.md CHANGED
@@ -8,4 +8,4 @@ Document: [https://midwayjs.org](https://midwayjs.org)
8
8
 
9
9
  ## License
10
10
 
11
- [MIT]((https://github.com/midwayjs/midway/blob/master/LICENSE))
11
+ [MIT](https://github.com/midwayjs/midway/blob/master/LICENSE)
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEnumMetadata = exports.isEnumDefined = exports.isEnumArray = exports.addEnumSchema = exports.addEnumArraySchema = exports.getEnumType = exports.getEnumValues = void 0;
3
+ exports.isEnumMetadata = exports.isEnumDefined = exports.isEnumArray = void 0;
4
+ exports.getEnumValues = getEnumValues;
5
+ exports.getEnumType = getEnumType;
6
+ exports.addEnumArraySchema = addEnumArraySchema;
7
+ exports.addEnumSchema = addEnumSchema;
4
8
  function getEnumValues(enumType) {
5
9
  if (Array.isArray(enumType)) {
6
10
  return enumType;
@@ -13,12 +17,10 @@ function getEnumValues(enumType) {
13
17
  .map(key => enumType[key]);
14
18
  return Array.from(new Set(values));
15
19
  }
16
- exports.getEnumValues = getEnumValues;
17
20
  function getEnumType(values) {
18
21
  const hasString = values.filter(s => typeof s === 'string').length > 0;
19
22
  return hasString ? 'string' : 'number';
20
23
  }
21
- exports.getEnumType = getEnumType;
22
24
  function addEnumArraySchema(paramDefinition, decoratorOptions) {
23
25
  const paramSchema = paramDefinition.schema || {};
24
26
  paramDefinition.schema = paramSchema;
@@ -33,7 +35,6 @@ function addEnumArraySchema(paramDefinition, decoratorOptions) {
33
35
  paramDefinition.enumName = decoratorOptions.enumName;
34
36
  }
35
37
  }
36
- exports.addEnumArraySchema = addEnumArraySchema;
37
38
  function addEnumSchema(paramDefinition, decoratorOptions) {
38
39
  const paramSchema = paramDefinition.schema || {};
39
40
  const enumValues = getEnumValues(decoratorOptions.enum);
@@ -44,7 +45,6 @@ function addEnumSchema(paramDefinition, decoratorOptions) {
44
45
  paramDefinition.enumName = decoratorOptions.enumName;
45
46
  }
46
47
  }
47
- exports.addEnumSchema = addEnumSchema;
48
48
  const isEnumArray = (obj) => obj.isArray && obj.enum;
49
49
  exports.isEnumArray = isEnumArray;
50
50
  const isEnumDefined = (obj) => obj.enum;
@@ -14,6 +14,8 @@ const core_1 = require("@midwayjs/core");
14
14
  const _1 = require(".");
15
15
  const DefaultConfig = require("./config/config.default");
16
16
  let SwaggerConfiguration = class SwaggerConfiguration {
17
+ applicationManager;
18
+ configService;
17
19
  async onReady(container) {
18
20
  const apps = this.applicationManager.getApplications([
19
21
  'express',
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiBasicAuth = void 0;
3
+ exports.ApiBasicAuth = ApiBasicAuth;
4
4
  const api_security_decorator_1 = require("./api-security.decorator");
5
5
  function ApiBasicAuth(name = 'basic') {
6
6
  return (0, api_security_decorator_1.ApiSecurity)(name);
7
7
  }
8
- exports.ApiBasicAuth = ApiBasicAuth;
9
8
  //# sourceMappingURL=api-basic.decorator.js.map
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiBearerAuth = void 0;
3
+ exports.ApiBearerAuth = ApiBearerAuth;
4
4
  const api_security_decorator_1 = require("./api-security.decorator");
5
5
  function ApiBearerAuth(name = 'bearer') {
6
6
  return (0, api_security_decorator_1.ApiSecurity)(name);
7
7
  }
8
- exports.ApiBearerAuth = ApiBearerAuth;
9
8
  //# sourceMappingURL=api-bearer.decorator.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiBody = exports.BodyContentType = void 0;
3
+ exports.BodyContentType = void 0;
4
+ exports.ApiBody = ApiBody;
4
5
  const enum_utils_1 = require("../common/enum.utils");
5
6
  const helpers_1 = require("./helpers");
6
7
  var BodyContentType;
@@ -31,5 +32,4 @@ function ApiBody(options) {
31
32
  }
32
33
  return (0, helpers_1.createParamDecorator)(param, defaultBodyMetadata);
33
34
  }
34
- exports.ApiBody = ApiBody;
35
35
  //# sourceMappingURL=api-body.decorator.js.map
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiCookieAuth = void 0;
3
+ exports.ApiCookieAuth = ApiCookieAuth;
4
4
  const api_security_decorator_1 = require("./api-security.decorator");
5
5
  function ApiCookieAuth(name = 'cookie') {
6
6
  return (0, api_security_decorator_1.ApiSecurity)(name);
7
7
  }
8
- exports.ApiCookieAuth = ApiCookieAuth;
9
8
  //# sourceMappingURL=api-cookie.decorator.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExcludeController = void 0;
3
+ exports.ApiExcludeController = ApiExcludeController;
4
4
  const core_1 = require("@midwayjs/core");
5
5
  const constants_1 = require("../constants");
6
6
  function ApiExcludeController(disable = true) {
@@ -8,5 +8,4 @@ function ApiExcludeController(disable = true) {
8
8
  core_1.MetadataManager.defineMetadata(constants_1.DECORATORS.API_EXCLUDE_CONTROLLER, { disable }, target);
9
9
  };
10
10
  }
11
- exports.ApiExcludeController = ApiExcludeController;
12
11
  //# sourceMappingURL=api-exclude-controller.decorator.js.map
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExcludeEndpoint = void 0;
3
+ exports.ApiExcludeEndpoint = ApiExcludeEndpoint;
4
4
  const constants_1 = require("../constants");
5
5
  const helpers_1 = require("./helpers");
6
6
  function ApiExcludeEndpoint(disable = true) {
7
7
  return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_EXCLUDE_ENDPOINT, true);
8
8
  }
9
- exports.ApiExcludeEndpoint = ApiExcludeEndpoint;
10
9
  //# sourceMappingURL=api-exclude-endpoint.decorator.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExtension = void 0;
3
+ exports.ApiExtension = ApiExtension;
4
4
  const constants_1 = require("../constants");
5
5
  const helpers_1 = require("./helpers");
6
6
  function ApiExtension(extensionKey, extensionProperties) {
@@ -12,5 +12,4 @@ function ApiExtension(extensionKey, extensionProperties) {
12
12
  };
13
13
  return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_EXTENSION, extensionObject);
14
14
  }
15
- exports.ApiExtension = ApiExtension;
16
15
  //# sourceMappingURL=api-extension.decorator.js.map
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExtraModel = void 0;
3
+ exports.ApiExtraModel = ApiExtraModel;
4
4
  const constants_1 = require("../constants");
5
5
  const helpers_1 = require("./helpers");
6
6
  function ApiExtraModel(models) {
7
7
  return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_EXTRA_MODEL, models);
8
8
  }
9
- exports.ApiExtraModel = ApiExtraModel;
10
9
  //# sourceMappingURL=api-extra-model.decorator.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiHeaders = exports.ApiHeader = void 0;
3
+ exports.ApiHeaders = void 0;
4
+ exports.ApiHeader = ApiHeader;
4
5
  const constants_1 = require("../constants");
5
6
  const enum_utils_1 = require("../common/enum.utils");
6
7
  const helpers_1 = require("./helpers");
@@ -32,7 +33,6 @@ function ApiHeader(options) {
32
33
  return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_HEADERS, param)(target, undefined, undefined);
33
34
  };
34
35
  }
35
- exports.ApiHeader = ApiHeader;
36
36
  const ApiHeaders = (headers) => {
37
37
  return (target, key, descriptor) => {
38
38
  headers.forEach(options => ApiHeader(options)(target, key, descriptor));
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiOAuth2 = void 0;
3
+ exports.ApiOAuth2 = ApiOAuth2;
4
4
  const api_security_decorator_1 = require("./api-security.decorator");
5
5
  function ApiOAuth2(scopes, name = 'oauth2') {
6
6
  return (0, api_security_decorator_1.ApiSecurity)(name, scopes);
7
7
  }
8
- exports.ApiOAuth2 = ApiOAuth2;
9
8
  //# sourceMappingURL=api-oauth2.decorator.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiOperation = void 0;
3
+ exports.ApiOperation = ApiOperation;
4
4
  const constants_1 = require("../constants");
5
5
  const helpers_1 = require("./helpers");
6
6
  const defaultOperationOptions = {
@@ -12,5 +12,4 @@ function ApiOperation(options) {
12
12
  ...options,
13
13
  });
14
14
  }
15
- exports.ApiOperation = ApiOperation;
16
15
  //# sourceMappingURL=api-operation.decorator.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiParam = void 0;
3
+ exports.ApiParam = ApiParam;
4
4
  const helpers_1 = require("./helpers");
5
5
  const enum_utils_1 = require("../common/enum.utils");
6
6
  const defaultParamOptions = {
@@ -26,5 +26,4 @@ function ApiParam(options) {
26
26
  }
27
27
  return (0, helpers_1.createParamDecorator)(param, defaultParamOptions);
28
28
  }
29
- exports.ApiParam = ApiParam;
30
29
  //# sourceMappingURL=api-param.decorator.js.map
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiResponseProperty = exports.ApiPropertyOptional = exports.createApiPropertyDecorator = exports.ApiProperty = void 0;
3
+ exports.ApiProperty = ApiProperty;
4
+ exports.createApiPropertyDecorator = createApiPropertyDecorator;
5
+ exports.ApiPropertyOptional = ApiPropertyOptional;
6
+ exports.ApiResponseProperty = ApiResponseProperty;
4
7
  const constants_1 = require("../constants");
5
8
  const enum_utils_1 = require("../common/enum.utils");
6
9
  const helpers_1 = require("./helpers");
@@ -8,7 +11,6 @@ const isEnumArray = (obj) => obj.isArray && !!obj.enum;
8
11
  function ApiProperty(options = {}) {
9
12
  return createApiPropertyDecorator(options);
10
13
  }
11
- exports.ApiProperty = ApiProperty;
12
14
  function createApiPropertyDecorator(options = {}) {
13
15
  const [type, isArray] = (0, helpers_1.getTypeIsArrayTuple)(options.type, options.isArray);
14
16
  options = {
@@ -37,19 +39,16 @@ function createApiPropertyDecorator(options = {}) {
37
39
  }
38
40
  return (0, helpers_1.createPropertyDecorator)(constants_1.DECORATORS.API_MODEL_PROPERTIES, options);
39
41
  }
40
- exports.createApiPropertyDecorator = createApiPropertyDecorator;
41
42
  function ApiPropertyOptional(options = {}) {
42
43
  return ApiProperty({
43
44
  ...options,
44
45
  required: false,
45
46
  });
46
47
  }
47
- exports.ApiPropertyOptional = ApiPropertyOptional;
48
48
  function ApiResponseProperty(options = {}) {
49
49
  return ApiProperty({
50
50
  readOnly: true,
51
51
  ...options,
52
52
  });
53
53
  }
54
- exports.ApiResponseProperty = ApiResponseProperty;
55
54
  //# sourceMappingURL=api-property.decorator.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiQuery = void 0;
3
+ exports.ApiQuery = ApiQuery;
4
4
  const enum_utils_1 = require("../common/enum.utils");
5
5
  const helpers_1 = require("./helpers");
6
6
  const defaultQueryOptions = {
@@ -27,5 +27,4 @@ function ApiQuery(options) {
27
27
  }
28
28
  return (0, helpers_1.createParamDecorator)(param, defaultQueryOptions);
29
29
  }
30
- exports.ApiQuery = ApiQuery;
31
30
  //# sourceMappingURL=api-query.decorator.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiDefaultResponse = exports.ApiUnsupportedMediaTypeResponse = exports.ApiUnprocessableEntityResponse = exports.ApiServiceUnavailableResponse = exports.ApiRequestTimeoutResponse = exports.ApiPayloadTooLargeResponse = exports.ApiPreconditionFailedResponse = exports.ApiNotImplementedResponse = exports.ApiNotAcceptableResponse = exports.ApiMethodNotAllowedResponse = exports.ApiGoneResponse = exports.ApiGatewayTimeoutResponse = exports.ApiForbiddenResponse = exports.ApiConflictResponse = exports.ApiBadGatewayResponse = exports.ApiInternalServerErrorResponse = exports.ApiNotFoundResponse = exports.ApiTooManyRequestsResponse = exports.ApiUnauthorizedResponse = exports.ApiBadRequestResponse = exports.ApiFoundResponse = exports.ApiMovedPermanentlyResponse = exports.ApiNoContentResponse = exports.ApiAcceptedResponse = exports.ApiCreatedResponse = exports.ApiOkResponse = exports.ApiResponse = void 0;
3
+ exports.ApiDefaultResponse = exports.ApiUnsupportedMediaTypeResponse = exports.ApiUnprocessableEntityResponse = exports.ApiServiceUnavailableResponse = exports.ApiRequestTimeoutResponse = exports.ApiPayloadTooLargeResponse = exports.ApiPreconditionFailedResponse = exports.ApiNotImplementedResponse = exports.ApiNotAcceptableResponse = exports.ApiMethodNotAllowedResponse = exports.ApiGoneResponse = exports.ApiGatewayTimeoutResponse = exports.ApiForbiddenResponse = exports.ApiConflictResponse = exports.ApiBadGatewayResponse = exports.ApiInternalServerErrorResponse = exports.ApiNotFoundResponse = exports.ApiTooManyRequestsResponse = exports.ApiUnauthorizedResponse = exports.ApiBadRequestResponse = exports.ApiFoundResponse = exports.ApiMovedPermanentlyResponse = exports.ApiNoContentResponse = exports.ApiAcceptedResponse = exports.ApiCreatedResponse = exports.ApiOkResponse = void 0;
4
+ exports.ApiResponse = ApiResponse;
4
5
  const constants_1 = require("../constants");
5
6
  const helpers_1 = require("./helpers");
6
7
  const httpStatus_1 = require("../common/httpStatus");
@@ -14,7 +15,6 @@ function ApiResponse(options) {
14
15
  };
15
16
  return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_RESPONSE, groupedMetadata);
16
17
  }
17
- exports.ApiResponse = ApiResponse;
18
18
  const ApiOkResponse = (options = {}) => ApiResponse({
19
19
  ...options,
20
20
  status: httpStatus_1.HttpStatus.OK,
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExcludeSecurity = exports.ApiSecurity = void 0;
3
+ exports.ApiSecurity = ApiSecurity;
4
+ exports.ApiExcludeSecurity = ApiExcludeSecurity;
4
5
  const constants_1 = require("../constants");
5
6
  const helpers_1 = require("./helpers");
6
7
  function ApiSecurity(name, requirements = []) {
@@ -13,9 +14,7 @@ function ApiSecurity(name, requirements = []) {
13
14
  }
14
15
  return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_SECURITY, metadata);
15
16
  }
16
- exports.ApiSecurity = ApiSecurity;
17
17
  function ApiExcludeSecurity() {
18
18
  return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_EXCLUDE_SECURITY, true);
19
19
  }
20
- exports.ApiExcludeSecurity = ApiExcludeSecurity;
21
20
  //# sourceMappingURL=api-security.decorator.js.map
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiTags = void 0;
3
+ exports.ApiTags = ApiTags;
4
4
  const constants_1 = require("../constants");
5
5
  const helpers_1 = require("./helpers");
6
6
  function ApiTags(tags) {
7
7
  return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_TAGS, tags);
8
8
  }
9
- exports.ApiTags = ApiTags;
10
9
  //# sourceMappingURL=api-tags.decorator.js.map
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSchemaPath = exports.getTypeIsArrayTuple = exports.createParamDecorator = exports.createMixedDecorator = exports.createPropertyDecorator = void 0;
3
+ exports.createPropertyDecorator = createPropertyDecorator;
4
+ exports.createMixedDecorator = createMixedDecorator;
5
+ exports.createParamDecorator = createParamDecorator;
6
+ exports.getTypeIsArrayTuple = getTypeIsArrayTuple;
7
+ exports.getSchemaPath = getSchemaPath;
4
8
  const core_1 = require("@midwayjs/core");
5
9
  const constants_1 = require("../constants");
6
10
  function createPropertyDecorator(metakey, metadata) {
7
11
  return core_1.DecoratorManager.createCustomPropertyDecorator(metakey, metadata, false);
8
12
  }
9
- exports.createPropertyDecorator = createPropertyDecorator;
10
13
  function createMixedDecorator(metakey, metadata) {
11
14
  return (target, methodName) => {
12
15
  if (methodName) {
@@ -24,14 +27,12 @@ function createMixedDecorator(metakey, metadata) {
24
27
  }
25
28
  };
26
29
  }
27
- exports.createMixedDecorator = createMixedDecorator;
28
30
  function createParamDecorator(metadata, initial) {
29
31
  return createMixedDecorator(constants_1.DECORATORS.API_PARAMETERS, {
30
32
  ...initial,
31
33
  ...metadata,
32
34
  });
33
35
  }
34
- exports.createParamDecorator = createParamDecorator;
35
36
  function getTypeIsArrayTuple(input, isArrayFlag) {
36
37
  if (!input) {
37
38
  return [input, isArrayFlag];
@@ -43,7 +44,6 @@ function getTypeIsArrayTuple(input, isArrayFlag) {
43
44
  const type = isInputArray ? input[0] : input;
44
45
  return [type, isInputArray];
45
46
  }
46
- exports.getTypeIsArrayTuple = getTypeIsArrayTuple;
47
47
  function getSchemaPath(clzz) {
48
48
  let str = clzz;
49
49
  if (typeof clzz !== 'string') {
@@ -51,5 +51,4 @@ function getSchemaPath(clzz) {
51
51
  }
52
52
  return `#/components/schemas/${str}`;
53
53
  }
54
- exports.getSchemaPath = getSchemaPath;
55
54
  //# sourceMappingURL=helpers.js.map
@@ -2,21 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentBuilder = void 0;
4
4
  class DocumentBuilder {
5
- constructor() {
6
- this.document = {
7
- openapi: '3.0.1',
8
- info: {
9
- title: '',
10
- description: '',
11
- version: '1.0.0',
12
- contact: {},
13
- },
14
- tags: [],
15
- servers: [],
16
- components: {},
17
- paths: {},
18
- };
19
- }
5
+ document = {
6
+ openapi: '3.0.1',
7
+ info: {
8
+ title: '',
9
+ description: '',
10
+ version: '1.0.0',
11
+ contact: {},
12
+ },
13
+ tags: [],
14
+ servers: [],
15
+ components: {},
16
+ paths: {},
17
+ };
20
18
  setTitle(title) {
21
19
  this.document.info.title = title;
22
20
  return this;
@@ -16,11 +16,9 @@ const documentBuilder_1 = require("./documentBuilder");
16
16
  const _1 = require(".");
17
17
  const enum_utils_1 = require("./common/enum.utils");
18
18
  let SwaggerExplorer = class SwaggerExplorer {
19
- constructor() {
20
- this.swaggerConfig = {};
21
- this.documentBuilder = new documentBuilder_1.DocumentBuilder();
22
- this.operationIdFactory = (controllerKey, webRouter) => `${controllerKey.toLowerCase()}_${webRouter.method.toLocaleLowerCase()}`;
23
- }
19
+ swaggerConfig = {};
20
+ documentBuilder = new documentBuilder_1.DocumentBuilder();
21
+ operationIdFactory = (controllerKey, webRouter) => `${controllerKey.toLowerCase()}_${webRouter.method.toLocaleLowerCase()}`;
24
22
  async init() {
25
23
  this.documentBuilder.setTitle(this.swaggerConfig.title);
26
24
  this.documentBuilder.setVersion(this.swaggerConfig.version);
@@ -13,6 +13,10 @@ exports.SwaggerMiddleware = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  const swaggerExplorer_1 = require("./swaggerExplorer");
15
15
  let SwaggerMiddleware = class SwaggerMiddleware {
16
+ swaggerConfig;
17
+ swaggerRender;
18
+ swaggerExplorer;
19
+ environmentService;
16
20
  async init() {
17
21
  if (typeof this.swaggerConfig.swaggerUIRender !== 'function') {
18
22
  throw new core_1.MidwayInvalidConfigPropertyError('swagger.swaggerRender');
package/dist/ui/render.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderSwaggerUIRemote = exports.renderJSON = exports.renderSwaggerUIDist = void 0;
3
+ exports.renderSwaggerUIDist = renderSwaggerUIDist;
4
+ exports.renderJSON = renderJSON;
5
+ exports.renderSwaggerUIRemote = renderSwaggerUIRemote;
4
6
  const core_1 = require("@midwayjs/core");
5
7
  const fs_1 = require("fs");
6
8
  const path_1 = require("path");
@@ -21,8 +23,9 @@ function renderSwaggerUIDist(swaggerConfig, swaggerExplorer) {
21
23
  function replaceInfo(content) {
22
24
  let str = `location.href.replace('${swaggerConfig.swaggerPath}/index.html', '${swaggerConfig.swaggerPath}/index.json'),\n validatorUrl: null,`;
23
25
  if (swaggerConfig.displayOptions) {
24
- Object.keys(swaggerConfig.displayOptions).forEach(key => {
25
- str += `\n${key}: ${swaggerConfig.displayOptions[key]},`;
26
+ Object.entries(swaggerConfig.displayOptions).forEach(([key, value]) => {
27
+ const variable = typeof value === 'string' ? `'${value}'` : value;
28
+ str += `\n${key}: ${variable},`;
26
29
  });
27
30
  }
28
31
  return content.replace('"https://petstore.swagger.io/v2/swagger.json",', str);
@@ -54,7 +57,6 @@ function renderSwaggerUIDist(swaggerConfig, swaggerExplorer) {
54
57
  return { ext, content };
55
58
  };
56
59
  }
57
- exports.renderSwaggerUIDist = renderSwaggerUIDist;
58
60
  function renderJSON(swaggerConfig, swaggerExplorer) {
59
61
  return async (pathname) => {
60
62
  if (pathname.indexOf(swaggerConfig.swaggerPath) === -1) {
@@ -68,7 +70,6 @@ function renderJSON(swaggerConfig, swaggerExplorer) {
68
70
  return;
69
71
  };
70
72
  }
71
- exports.renderJSON = renderJSON;
72
73
  function renderSwaggerUIRemote(swaggerConfig, swaggerExplorer) {
73
74
  const swaggerRenderOptions = swaggerConfig.swaggerUIRenderOptions || {};
74
75
  const indexPagePath = swaggerRenderOptions?.indexPagePath || (0, path_1.join)(__dirname, '../../index.html');
@@ -91,5 +92,4 @@ function renderSwaggerUIRemote(swaggerConfig, swaggerExplorer) {
91
92
  return;
92
93
  };
93
94
  }
94
- exports.renderSwaggerUIRemote = renderSwaggerUIRemote;
95
95
  //# sourceMappingURL=render.js.map
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@midwayjs/swagger",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.10",
4
+ "description": "Midway Component for Swagger API Documentation",
4
5
  "main": "dist/index.js",
5
6
  "typings": "index.d.ts",
6
7
  "files": [
@@ -11,10 +12,10 @@
11
12
  ],
12
13
  "devDependencies": {
13
14
  "@apidevtools/swagger-parser": "11.0.1",
14
- "@midwayjs/core": "^4.0.0-beta.1",
15
- "@midwayjs/koa": "^4.0.0-beta.1",
16
- "@midwayjs/mock": "^4.0.0-beta.1",
17
- "@midwayjs/validate": "^4.0.0-beta.1",
15
+ "@midwayjs/core": "^4.0.0-beta.10",
16
+ "@midwayjs/koa": "^4.0.0-beta.10",
17
+ "@midwayjs/mock": "^4.0.0-beta.10",
18
+ "@midwayjs/validate": "^4.0.0-beta.10",
18
19
  "swagger-ui-dist": "5.18.3"
19
20
  },
20
21
  "author": "Kurten Chan <chinkurten@gmail.com>",
@@ -29,5 +30,5 @@
29
30
  "type": "git",
30
31
  "url": "https://github.com/midwayjs/midway.git"
31
32
  },
32
- "gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
33
+ "gitHead": "1b1856629913703f67304155aaf611ec936a81ac"
33
34
  }