@midwayjs/swagger 3.0.0-beta.9 → 3.0.3

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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/common/enum.utils.js.map +1 -0
  4. package/dist/common/httpStatus.js.map +1 -0
  5. package/dist/config/config.default.js.map +1 -0
  6. package/dist/configuration.js.map +1 -0
  7. package/dist/constants.js.map +1 -0
  8. package/dist/decorators/api-basic.decorator.js.map +1 -0
  9. package/dist/decorators/api-bearer.decorator.js.map +1 -0
  10. package/dist/decorators/api-body.decorator.d.ts +8 -0
  11. package/dist/decorators/api-body.decorator.js +9 -1
  12. package/dist/decorators/api-body.decorator.js.map +1 -0
  13. package/dist/decorators/api-cookie.decorator.js.map +1 -0
  14. package/dist/decorators/api-exclude-controller.decorator.js +1 -3
  15. package/dist/decorators/api-exclude-controller.decorator.js.map +1 -0
  16. package/dist/decorators/api-exclude-endpoint.decorator.js +1 -1
  17. package/dist/decorators/api-exclude-endpoint.decorator.js.map +1 -0
  18. package/dist/decorators/api-extension.decorator.js.map +1 -0
  19. package/dist/decorators/api-header.decorator.js +1 -1
  20. package/dist/decorators/api-header.decorator.js.map +1 -0
  21. package/dist/decorators/api-oauth2.decorator.js.map +1 -0
  22. package/dist/decorators/api-operation.decorator.js +1 -1
  23. package/dist/decorators/api-operation.decorator.js.map +1 -0
  24. package/dist/decorators/api-param.decorator.js.map +1 -0
  25. package/dist/decorators/api-property.decorator.js +2 -3
  26. package/dist/decorators/api-property.decorator.js.map +1 -0
  27. package/dist/decorators/api-query.decorator.js.map +1 -0
  28. package/dist/decorators/api-response.decorator.js +1 -1
  29. package/dist/decorators/api-response.decorator.js.map +1 -0
  30. package/dist/decorators/api-security.decorator.js +1 -1
  31. package/dist/decorators/api-security.decorator.js.map +1 -0
  32. package/dist/decorators/api-tags.decorator.js.map +1 -0
  33. package/dist/decorators/helpers.js +3 -3
  34. package/dist/decorators/helpers.js.map +1 -0
  35. package/dist/decorators/index.js.map +1 -0
  36. package/dist/documentBuilder.d.ts +3 -1
  37. package/dist/documentBuilder.js +24 -0
  38. package/dist/documentBuilder.js.map +1 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/interfaces/index.d.ts +80 -4
  41. package/dist/interfaces/index.js.map +1 -0
  42. package/dist/swaggerExplorer.js +147 -54
  43. package/dist/swaggerExplorer.js.map +1 -0
  44. package/dist/swaggerMiddleware.d.ts +1 -0
  45. package/dist/swaggerMiddleware.js +3 -0
  46. package/dist/swaggerMiddleware.js.map +1 -0
  47. package/index.d.ts +1 -1
  48. package/package.json +12 -11
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
@@ -1,5 +1,7 @@
1
1
  # midwayjs swagger module
2
2
 
3
+ ## Thanks to [@nestjs/swagger](https://github.com/nestjs/swagger)
4
+
3
5
  [![Package Quality](http://npm.packagequality.com/shield/midway-core.svg)](http://packagequality.com/#?package=midway-core)
4
6
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
5
7
 
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.utils.js","sourceRoot":"","sources":["../../src/common/enum.utils.ts"],"names":[],"mappings":";;;AAMA,SAAgB,aAAa,CAAC,QAAyB;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,OAAO,QAAoB,CAAC;KAC7B;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,OAAO,EAAE,CAAC;KACX;IAED,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,MAAM,YAAY,GAAG,EAAE,CAAC;IAExB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;QAC1B,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC5B,0CAA0C;QAC1C,sEAAsE;QACtE,IACE,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,CAAC;YACnC,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,EACjC;YACA,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,YAAY,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;SAC7B;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAxBD,sCAwBC;AAED,SAAgB,WAAW,CAAC,MAA2B;IACrD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACvE,OAAO,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;AACzC,CAAC;AAHD,kCAGC;AAED,SAAgB,kBAAk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AAc,GAAG,CAAC,QAA8B,EAAE,EAAE,WAC/D,OAAA,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,KAAI,MAAA,QAAQ,CAAC,KAAK,0CAAG,MAAM,CAAC,CAAA,CAAC,CAAA,EAAA,CAAC;AADrD,QAAA,cAAc,kBACuC","sourcesContent":["import {\n SchemaObject,\n SchemaObjectMetadata,\n SwaggerEnumType,\n} from '../interfaces';\n\nexport function getEnumValues(enumType: SwaggerEnumType): string[] | number[] {\n if (Array.isArray(enumType)) {\n return enumType as string[];\n }\n if (typeof enumType !== 'object') {\n return [];\n }\n\n const values = [];\n const uniqueValues = {};\n\n for (const key in enumType) {\n const value = enumType[key];\n /* eslint-disable no-prototype-builtins */\n // filter out cases where enum key also becomes its value (A: B, B: A)\n if (\n !uniqueValues.hasOwnProperty(value) &&\n !uniqueValues.hasOwnProperty(key)\n ) {\n values.push(value);\n uniqueValues[value] = value;\n }\n }\n return values;\n}\n\nexport function getEnumType(values: (string | number)[]): 'string' | 'number' {\n const hasString = values.filter(s => typeof s === 'string').length > 0;\n return hasString ? 'string' : 'number';\n}\n\nexport function addEnumArraySchema(\n paramDefinition: Partial<Record<'schema' | 'isArray' | 'enumName', any>>,\n decoratorOptions: Partial<Record<'enum' | 'enumName', any>>\n) {\n const paramSchema: SchemaObject = paramDefinition.schema || {};\n paramDefinition.schema = paramSchema;\n paramSchema.type = 'array';\n delete paramDefinition.isArray;\n\n const enumValues = getEnumValues(decoratorOptions.enum);\n paramSchema.items = {\n type: getEnumType(enumValues),\n enum: enumValues,\n };\n\n if (decoratorOptions.enumName) {\n paramDefinition.enumName = decoratorOptions.enumName;\n }\n}\n\nexport function addEnumSchema(\n paramDefinition: Partial<Record<string, any>>,\n decoratorOptions: Partial<Record<string, any>>\n) {\n const paramSchema: SchemaObject = paramDefinition.schema || {};\n const enumValues = getEnumValues(decoratorOptions.enum);\n\n paramDefinition.schema = paramSchema;\n paramSchema.enum = enumValues;\n paramSchema.type = getEnumType(enumValues);\n\n if (decoratorOptions.enumName) {\n paramDefinition.enumName = decoratorOptions.enumName;\n }\n}\n\nexport const isEnumArray = <T extends Partial<Record<'isArray' | 'enum', any>>>(\n obj: Record<string, any>\n): obj is T => obj.isArray && obj.enum;\n\nexport const isEnumDefined = <T extends Partial<Record<'enum', any>>>(\n obj: Record<string, any>\n): obj is T => obj.enum;\n\nexport const isEnumMetadata = (metadata: SchemaObjectMetadata) =>\n metadata.enum || (metadata.isArray && metadata.items?.['enum']);\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpStatus.js","sourceRoot":"","sources":["../../src/common/httpStatus.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAiDX;AAjDD,WAAY,UAAU;IACpB,qDAAc,CAAA;IACd,2EAAyB,CAAA;IACzB,yDAAgB,CAAA;IAChB,yDAAgB,CAAA;IAChB,yCAAQ,CAAA;IACR,mDAAa,CAAA;IACb,qDAAc,CAAA;IACd,+FAAmC,CAAA;IACnC,yDAAgB,CAAA;IAChB,+DAAmB,CAAA;IACnB,mEAAqB,CAAA;IACrB,uDAAe,CAAA;IACf,uEAAuB,CAAA;IACvB,+CAAW,CAAA;IACX,uDAAe,CAAA;IACf,6DAAkB,CAAA;IAClB,yEAAwB,CAAA;IACxB,yEAAwB,CAAA;IACxB,2DAAiB,CAAA;IACjB,6DAAkB,CAAA;IAClB,qEAAsB,CAAA;IACtB,uDAAe,CAAA;IACf,uDAAe,CAAA;IACf,yEAAwB,CAAA;IACxB,iEAAoB,CAAA;IACpB,+FAAmC,CAAA;IACnC,mEAAqB,CAAA;IACrB,qDAAc,CAAA;IACd,6CAAU,CAAA;IACV,mEAAqB,CAAA;IACrB,2EAAyB,CAAA;IACzB,uEAAuB,CAAA;IACvB,6DAAkB,CAAA;IAClB,iFAA4B,CAAA;IAC5B,mGAAqC,CAAA;IACrC,yEAAwB,CAAA;IACxB,+DAAmB,CAAA;IACnB,2DAAiB,CAAA;IACjB,6EAA0B,CAAA;IAC1B,uEAAuB,CAAA;IACvB,+EAA2B,CAAA;IAC3B,uEAAuB,CAAA;IACvB,+EAA2B,CAAA;IAC3B,mEAAqB,CAAA;IACrB,2DAAiB,CAAA;IACjB,2EAAyB,CAAA;IACzB,mEAAqB,CAAA;IACrB,yFAAgC,CAAA;AAClC,CAAC,EAjDW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAiDrB","sourcesContent":["export enum HttpStatus {\n CONTINUE = 100,\n SWITCHING_PROTOCOLS = 101,\n PROCESSING = 102,\n EARLYHINTS = 103,\n OK = 200,\n CREATED = 201,\n ACCEPTED = 202,\n NON_AUTHORITATIVE_INFORMATION = 203,\n NO_CONTENT = 204,\n RESET_CONTENT = 205,\n PARTIAL_CONTENT = 206,\n AMBIGUOUS = 300,\n MOVED_PERMANENTLY = 301,\n FOUND = 302,\n SEE_OTHER = 303,\n NOT_MODIFIED = 304,\n TEMPORARY_REDIRECT = 307,\n PERMANENT_REDIRECT = 308,\n BAD_REQUEST = 400,\n UNAUTHORIZED = 401,\n PAYMENT_REQUIRED = 402,\n FORBIDDEN = 403,\n NOT_FOUND = 404,\n METHOD_NOT_ALLOWED = 405,\n NOT_ACCEPTABLE = 406,\n PROXY_AUTHENTICATION_REQUIRED = 407,\n REQUEST_TIMEOUT = 408,\n CONFLICT = 409,\n GONE = 410,\n LENGTH_REQUIRED = 411,\n PRECONDITION_FAILED = 412,\n PAYLOAD_TOO_LARGE = 413,\n URI_TOO_LONG = 414,\n UNSUPPORTED_MEDIA_TYPE = 415,\n REQUESTED_RANGE_NOT_SATISFIABLE = 416,\n EXPECTATION_FAILED = 417,\n I_AM_A_TEAPOT = 418,\n MISDIRECTED = 421,\n UNPROCESSABLE_ENTITY = 422,\n FAILED_DEPENDENCY = 424,\n PRECONDITION_REQUIRED = 428,\n TOO_MANY_REQUESTS = 429,\n INTERNAL_SERVER_ERROR = 500,\n NOT_IMPLEMENTED = 501,\n BAD_GATEWAY = 502,\n SERVICE_UNAVAILABLE = 503,\n GATEWAY_TIMEOUT = 504,\n HTTP_VERSION_NOT_SUPPORTED = 505,\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.default.js","sourceRoot":"","sources":["../../src/config/config.default.ts"],"names":[],"mappings":";;;AAEa,QAAA,OAAO,GAAmB;IACrC,KAAK,EAAE,YAAY;IACnB,WAAW,EAAE,2CAA2C;IACxD,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,aAAa;CAC3B,CAAC","sourcesContent":["import { SwaggerOptions } from '../interfaces';\n\nexport const swagger: SwaggerOptions = {\n title: 'My Project',\n description: 'This is a swagger-ui for midwayjs project',\n version: '1.0.0',\n swaggerPath: '/swagger-ui',\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAIwB;AACxB,mDAA4D;AAC5D,wBAAuD;AACvD,yDAAyD;AAUzD,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAI/B,KAAK,CAAC,OAAO,CAAC,SAA2B;QACvC,IAAI,CAAC,kBAAkB;aACpB,eAAe,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;aAClD,OAAO,CAAC,GAAG,CAAC,EAAE;YACb,GAAG,CAAC,aAAa,CAAC,oBAAiB,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;QAEL,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,kBAAe,CAAC,CAAC;QAC3D,QAAQ,CAAC,OAAO,EAAE,CAAC;IACrB,CAAC;CACF,CAAA;AAZC;IADC,IAAA,kBAAM,GAAE;8BACW,+BAAwB;gEAAC;AAFlC,oBAAoB;IARhC,IAAA,yBAAa,EAAC;QACb,aAAa,EAAE;YACb;gBACE,OAAO,EAAE,aAAa;aACvB;SACF;QACD,SAAS,EAAE,SAAS;KACrB,CAAC;GACW,oBAAoB,CAchC;AAdY,oDAAoB","sourcesContent":["import {\n ILifeCycle,\n IMidwayContainer,\n MidwayApplicationManager,\n} from '@midwayjs/core';\nimport { Inject, Configuration } from '@midwayjs/decorator';\nimport { SwaggerExplorer, SwaggerMiddleware } from '.';\nimport * as DefaultConfig from './config/config.default';\n\n@Configuration({\n importConfigs: [\n {\n default: DefaultConfig,\n },\n ],\n namespace: 'swagger',\n})\nexport class SwaggerConfiguration implements ILifeCycle {\n @Inject()\n applicationManager: MidwayApplicationManager;\n\n async onReady(container: IMidwayContainer) {\n this.applicationManager\n .getApplications(['express', 'koa', 'egg', 'faas'])\n .forEach(app => {\n app.useMiddleware(SwaggerMiddleware);\n });\n\n const explorer = await container.getAsync(SwaggerExplorer);\n explorer.scanApp();\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAC9B,QAAA,UAAU,GAAG;IACxB,aAAa,EAAE,GAAG,yBAAiB,eAAe;IAClD,YAAY,EAAE,GAAG,yBAAiB,cAAc;IAChD,QAAQ,EAAE,GAAG,yBAAiB,aAAa;IAC3C,cAAc,EAAE,GAAG,yBAAiB,gBAAgB;IACpD,WAAW,EAAE,GAAG,yBAAiB,aAAa;IAC9C,oBAAoB,EAAE,GAAG,yBAAiB,qBAAqB;IAC/D,0BAA0B,EAAE,GAAG,yBAAiB,0BAA0B;IAC1E,YAAY,EAAE,GAAG,yBAAiB,cAAc;IAChD,oBAAoB,EAAE,GAAG,yBAAiB,qBAAqB;IAC/D,sBAAsB,EAAE,GAAG,yBAAiB,uBAAuB;IACnE,aAAa,EAAE,GAAG,yBAAiB,eAAe;CACnD,CAAC","sourcesContent":["export const DECORATORS_PREFIX = 'swagger';\nexport const DECORATORS = {\n API_OPERATION: `${DECORATORS_PREFIX}/apiOperation`,\n API_RESPONSE: `${DECORATORS_PREFIX}/apiResponse`,\n API_TAGS: `${DECORATORS_PREFIX}/apiUseTags`,\n API_PARAMETERS: `${DECORATORS_PREFIX}/apiParameters`,\n API_HEADERS: `${DECORATORS_PREFIX}/apiHeaders`,\n API_MODEL_PROPERTIES: `${DECORATORS_PREFIX}/apiModelProperties`,\n API_MODEL_PROPERTIES_ARRAY: `${DECORATORS_PREFIX}/apiModelPropertiesArray`,\n API_SECURITY: `${DECORATORS_PREFIX}/apiSecurity`,\n API_EXCLUDE_ENDPOINT: `${DECORATORS_PREFIX}/apiExcludeEndpoint`,\n API_EXCLUDE_CONTROLLER: `${DECORATORS_PREFIX}/apiExcludeController`,\n API_EXTENSION: `${DECORATORS_PREFIX}/apiExtension`,\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-basic.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-basic.decorator.ts"],"names":[],"mappings":";;;AAAA,qEAAuD;AAEvD,SAAgB,YAAY,CAAC,IAAI,GAAG,OAAO;IACzC,OAAO,IAAA,oCAAW,EAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAFD,oCAEC","sourcesContent":["import { ApiSecurity } from './api-security.decorator';\n\nexport function ApiBasicAuth(name = 'basic') {\n return ApiSecurity(name);\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-bearer.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-bearer.decorator.ts"],"names":[],"mappings":";;;AAAA,qEAAuD;AAEvD,SAAgB,aAAa,CAAC,IAAI,GAAG,QAAQ;IAC3C,OAAO,IAAA,oCAAW,EAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAFD,sCAEC","sourcesContent":["import { ApiSecurity } from './api-security.decorator';\n\nexport function ApiBearerAuth(name = 'bearer') {\n return ApiSecurity(name);\n}\n"]}
@@ -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,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-body.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-body.decorator.ts"],"names":[],"mappings":";;;AASA,qDAK8B;AAC9B,uCAAsE;AAItE,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,uEAAoD,CAAA;IACpD,4CAAyB,CAAA;IACzB,oDAAiC,CAAA;IACjC,qDAAkC,CAAA;IAClC,2DAAwC,CAAA;AAC1C,CAAC,EANW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAM1B;AAiBD,MAAM,mBAAmB,GAAoB;IAC3C,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF,SAAgB,OAAO,CAAC,OAAuB;IAC7C,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,6BAAmB,EACxC,OAA2B,CAAC,IAAI,EAChC,OAA2B,CAAC,OAAO,CACrC,CAAC;IACF,MAAM,KAAK,GAA0C;QACnD,EAAE,EAAE,MAAM;QACV,GAAG,OAAO;QACV,IAAI;QACJ,OAAO;KACR,CAAC;IAEF,IAAI,IAAA,wBAAW,EAAC,OAAO,CAAC,EAAE;QACxB,IAAA,+BAAkB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KACpC;SAAM,IAAI,IAAA,0BAAa,EAAC,OAAO,CAAC,EAAE;QACjC,IAAA,0BAAa,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KAC/B;IACD,OAAO,IAAA,8BAAoB,EAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;AAC1D,CAAC;AAlBD,0BAkBC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\nimport {\n ContentObject,\n ExamplesObject,\n ReferenceObject,\n RequestBodyObject,\n SchemaObject,\n SwaggerEnumType,\n} from '../interfaces';\nimport {\n addEnumArraySchema,\n addEnumSchema,\n isEnumArray,\n isEnumDefined,\n} from '../common/enum.utils';\nimport { createParamDecorator, getTypeIsArrayTuple } from './helpers';\n\ntype RequestBodyOptions = Omit<RequestBodyObject, 'content'>;\n\nexport enum BodyContentType {\n FormUrlEncoded = 'application/x-www-form-urlencoded',\n JSON = 'application/json',\n Multipart = 'multipart/form-data',\n MultipartMixed = 'multipart/mixed',\n OctetStream = 'application/octet-stream',\n}\n\ninterface ApiBodyMetadata extends RequestBodyOptions {\n type?: any;\n isArray?: boolean;\n enum?: SwaggerEnumType;\n content?: ContentObject;\n contentType?: BodyContentType;\n}\n\ninterface ApiBodySchemaHost extends RequestBodyOptions {\n schema: SchemaObject | ReferenceObject;\n examples?: ExamplesObject;\n}\n\nexport type ApiBodyOptions = ApiBodyMetadata | ApiBodySchemaHost;\n\nconst defaultBodyMetadata: ApiBodyMetadata = {\n type: String,\n required: true,\n};\n\nexport function ApiBody(options: ApiBodyOptions): MethodDecorator {\n const [type, isArray] = getTypeIsArrayTuple(\n (options as ApiBodyMetadata).type,\n (options as ApiBodyMetadata).isArray\n );\n const param: ApiBodyMetadata & Record<string, any> = {\n in: 'body',\n ...options,\n type,\n isArray,\n };\n\n if (isEnumArray(options)) {\n addEnumArraySchema(param, options);\n } else if (isEnumDefined(options)) {\n addEnumSchema(param, options);\n }\n return createParamDecorator(param, defaultBodyMetadata);\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-cookie.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-cookie.decorator.ts"],"names":[],"mappings":";;;AAAA,qEAAuD;AAEvD,SAAgB,aAAa,CAAC,IAAI,GAAG,QAAQ;IAC3C,OAAO,IAAA,oCAAW,EAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAFD,sCAEC","sourcesContent":["import { ApiSecurity } from './api-security.decorator';\n\nexport function ApiCookieAuth(name = 'cookie') {\n return ApiSecurity(name);\n}\n"]}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-exclude-controller.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-exclude-controller.decorator.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAClE,4CAA0C;AAE1C,SAAgB,oBAAoB,CAAC,OAAO,GAAG,IAAI;IACjD,OAAO,IAAA,uCAA2B,EAChC,sBAAU,CAAC,sBAAsB,EACjC,CAAC,OAAO,CAAC,EACT,KAAK,CACN,CAAC;AACJ,CAAC;AAND,oDAMC","sourcesContent":["import { createCustomMethodDecorator } from '@midwayjs/decorator';\nimport { DECORATORS } from '../constants';\n\nexport function ApiExcludeController(disable = true): any {\n return createCustomMethodDecorator(\n DECORATORS.API_EXCLUDE_CONTROLLER,\n [disable],\n false\n );\n}\n"]}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-exclude-endpoint.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-exclude-endpoint.decorator.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAClE,4CAA0C;AAE1C,SAAgB,kBAAkB,CAAC,OAAO,GAAG,IAAI;IAC/C,OAAO,IAAA,uCAA2B,EAChC,sBAAU,CAAC,oBAAoB,EAC/B;QACE,OAAO;KACR,EACD,KAAK,CACN,CAAC;AACJ,CAAC;AARD,gDAQC","sourcesContent":["import { createCustomMethodDecorator } from '@midwayjs/decorator';\nimport { DECORATORS } from '../constants';\n\nexport function ApiExcludeEndpoint(disable = true): MethodDecorator {\n return createCustomMethodDecorator(\n DECORATORS.API_EXCLUDE_ENDPOINT,\n {\n disable,\n },\n false\n );\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-extension.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-extension.decorator.ts"],"names":[],"mappings":";;;AAAA,4CAA0C;AAC1C,uCAAiD;AAEjD,SAAgB,YAAY,CAAC,YAAoB,EAAE,mBAAwB;IACzE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAClC,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAC;KACH;IAED,MAAM,eAAe,GAAG;QACtB,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;KAChE,CAAC;IAEF,OAAO,IAAA,8BAAoB,EAAC,sBAAU,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;AACzE,CAAC;AAZD,oCAYC","sourcesContent":["import { DECORATORS } from '../constants';\nimport { createMixedDecorator } from './helpers';\n\nexport function ApiExtension(extensionKey: string, extensionProperties: any) {\n if (!extensionKey.startsWith('x-')) {\n throw new Error(\n 'Extension key is not prefixed. Please ensure you prefix it with `x-`.'\n );\n }\n\n const extensionObject = {\n [extensionKey]: JSON.parse(JSON.stringify(extensionProperties)),\n };\n\n return createMixedDecorator(DECORATORS.API_EXTENSION, extensionObject);\n}\n"]}
@@ -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;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-header.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-header.decorator.ts"],"names":[],"mappings":";;;AAAA,4CAA0C;AAE1C,qDAAkE;AAClE,uCAAiD;AACjD,mDAAkE;AAMlE,MAAM,oBAAoB,GAA8B;IACtD,IAAI,EAAE,EAAE;CACT,CAAC;AAEF,SAAgB,SAAS,CAAC,OAAy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AVW,QAAA,UAAU,cAUrB","sourcesContent":["import { DECORATORS } from '../constants';\nimport { SwaggerEnumType, ParameterObject, Type } from '../interfaces';\nimport { getEnumType, getEnumValues } from '../common/enum.utils';\nimport { createParamDecorator } from './helpers';\nimport { createCustomMethodDecorator } from '@midwayjs/decorator';\n\nexport interface ApiHeaderOptions extends Omit<ParameterObject, 'in'> {\n enum?: SwaggerEnumType;\n}\n\nconst defaultHeaderOptions: Partial<ApiHeaderOptions> = {\n name: '',\n};\n\nexport function ApiHeader(options: ApiHeaderOptions): any {\n const param = {\n name: !options.name ? defaultHeaderOptions.name : options.name,\n in: 'header',\n description: options.description,\n required: options.required,\n schema: {\n ...(options.schema || {}),\n type: 'string',\n },\n };\n\n if (options.enum) {\n const enumValues = getEnumValues(options.enum);\n param.schema = {\n enum: enumValues,\n type: getEnumType(enumValues),\n };\n }\n\n return (\n target: object | Type,\n key?: string | symbol,\n descriptor?: TypedPropertyDescriptor<any>\n ): any => {\n if (descriptor) {\n return createParamDecorator(param, defaultHeaderOptions as any)(\n target,\n key,\n descriptor\n );\n }\n return createCustomMethodDecorator(DECORATORS.API_HEADERS, param, false)(\n target,\n undefined,\n undefined\n );\n };\n}\n\nexport const ApiHeaders = (\n headers: ApiHeaderOptions[]\n): MethodDecorator & ClassDecorator => {\n return (\n target: object | Type,\n key?: string | symbol,\n descriptor?: TypedPropertyDescriptor<any>\n ): any => {\n headers.forEach(options => ApiHeader(options)(target, key, descriptor));\n };\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-oauth2.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-oauth2.decorator.ts"],"names":[],"mappings":";;;AAAA,qEAAuD;AAEvD,SAAgB,SAAS,CAAC,MAAgB,EAAE,IAAI,GAAG,QAAQ;IACzD,OAAO,IAAA,oCAAW,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC;AAFD,8BAEC","sourcesContent":["import { ApiSecurity } from './api-security.decorator';\n\nexport function ApiOAuth2(scopes: string[], name = 'oauth2') {\n return ApiSecurity(name, scopes);\n}\n"]}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-operation.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-operation.decorator.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAClE,4CAA0C;AAK1C,MAAM,uBAAuB,GAAwB;IACnD,OAAO,EAAE,EAAE;CACZ,CAAC;AAEF,SAAgB,YAAY,CAAC,OAA4B;IACvD,OAAO,IAAA,uCAA2B,EAChC,sBAAU,CAAC,aAAa,EACxB;QACE,GAAG,uBAAuB;QAC1B,GAAG,OAAO;KACY,EACxB,KAAK,CACN,CAAC;AACJ,CAAC;AATD,oCASC","sourcesContent":["import { createCustomMethodDecorator } from '@midwayjs/decorator';\nimport { DECORATORS } from '../constants';\nimport { OperationObject } from '../interfaces';\n\nexport type ApiOperationOptions = Partial<OperationObject>;\n\nconst defaultOperationOptions: ApiOperationOptions = {\n summary: '',\n};\n\nexport function ApiOperation(options: ApiOperationOptions): MethodDecorator {\n return createCustomMethodDecorator(\n DECORATORS.API_OPERATION,\n {\n ...defaultOperationOptions,\n ...options,\n } as ApiOperationOptions,\n false\n );\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-param.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-param.decorator.ts"],"names":[],"mappings":";;;AAMA,uCAAiD;AACjD,qDAAkE;AAiBlE,MAAM,mBAAmB,GAAoB;IAC3C,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF,SAAgB,QAAQ,CAAC,OAAwB;IAC/C,MAAM,KAAK,GAAwB;QACjC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI;QAC7D,EAAE,EAAE,MAAM;QACV,GAAG,OAAO;KACX,CAAC;IAEF,MAAM,gBAAgB,GAAG,OAA2B,CAAC;IACrD,IAAI,gBAAgB,CAAC,IAAI,EAAE;QACzB,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAK,EAAmB,CAAC;QAEpD,MAAM,WAAW,GAAG,KAAK,CAAC,MAAsB,CAAC;QACjD,MAAM,UAAU,GAAG,IAAA,0BAAa,EAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACxD,WAAW,CAAC,IAAI,GAAG,IAAA,wBAAW,EAAC,UAAU,CAAC,CAAC;QAC3C,WAAW,CAAC,IAAI,GAAG,UAAU,CAAC;QAE9B,IAAI,gBAAgB,CAAC,QAAQ,EAAE;YAC7B,KAAK,CAAC,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC;SAC5C;KACF;IAED,OAAO,IAAA,8BAAoB,EAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;AAC1D,CAAC;AAtBD,4BAsBC","sourcesContent":["import {\n Type,\n ParameterObject,\n SchemaObject,\n SwaggerEnumType,\n} from '../interfaces';\nimport { createParamDecorator } from './helpers';\nimport { getEnumValues, getEnumType } from '../common/enum.utils';\n\ntype ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;\n\ninterface ApiParamMetadata extends ParameterOptions {\n type?: Type | string;\n format?: string;\n enum?: SwaggerEnumType;\n enumName?: string;\n}\n\ninterface ApiParamSchemaHost extends ParameterOptions {\n schema: SchemaObject;\n}\n\nexport type ApiParamOptions = ApiParamMetadata | ApiParamSchemaHost;\n\nconst defaultParamOptions: ApiParamOptions = {\n name: '',\n required: true,\n};\n\nexport function ApiParam(options: ApiParamOptions): MethodDecorator {\n const param: Record<string, any> = {\n name: !options.name ? defaultParamOptions.name : options.name,\n in: 'path',\n ...options,\n };\n\n const apiParamMetadata = options as ApiParamMetadata;\n if (apiParamMetadata.enum) {\n param.schema = param.schema || ({} as SchemaObject);\n\n const paramSchema = param.schema as SchemaObject;\n const enumValues = getEnumValues(apiParamMetadata.enum);\n paramSchema.type = getEnumType(enumValues);\n paramSchema.enum = enumValues;\n\n if (apiParamMetadata.enumName) {\n param.enumName = apiParamMetadata.enumName;\n }\n }\n\n return createParamDecorator(param, defaultParamOptions);\n}\n"]}
@@ -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';
@@ -30,10 +29,10 @@ function createApiPropertyDecorator(options = {}) {
30
29
  options.enum = enumValues;
31
30
  options.type = (0, enum_utils_1.getEnumType)(enumValues);
32
31
  }
33
- if (Array.isArray(options.type)) {
32
+ if (isArray) {
34
33
  options.type = 'array';
35
34
  options.items = {
36
- type: options.type[0],
35
+ type: type,
37
36
  };
38
37
  }
39
38
  return (0, helpers_1.createPropertyDecorator)(constants_1.DECORATORS.API_MODEL_PROPERTIES, options);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-property.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-property.decorator.ts"],"names":[],"mappings":";;;AAAA,4CAA0C;AAE1C,qDAAkE;AAClE,uCAAyE;AASzE,MAAM,WAAW,GAAG,CAAC,GAAuB,EAAW,EAAE,CACvD,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;AAE5B,SAAgB,WAAW,CACzB,UAA8B,EAAE;IAEhC,OAAO,0BAA0B,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AAJD,kCAIC;AAED,SAAgB,0BAA0B,CACxC,UAA8B,EAAE;IAEhC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,6BAAmB,EAAC,OAAO,CA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../interfaces';\nimport { getEnumType, getEnumValues } from '../common/enum.utils';\nimport { createPropertyDecorator, getTypeIsArrayTuple } from './helpers';\n\nexport interface ApiPropertyOptions\n extends Omit<SchemaObjectMetadata, 'name' | 'enum'> {\n name?: string;\n enum?: any[] | Record<string, any>;\n enumName?: string;\n}\n\nconst isEnumArray = (obj: ApiPropertyOptions): boolean =>\n obj.isArray && !!obj.enum;\n\nexport function ApiProperty(\n options: ApiPropertyOptions = {}\n): PropertyDecorator {\n return createApiPropertyDecorator(options);\n}\n\nexport function createApiPropertyDecorator(\n options: ApiPropertyOptions = {}\n): PropertyDecorator {\n const [type, isArray] = getTypeIsArrayTuple(options.type, options.isArray);\n options = {\n ...options,\n type,\n };\n\n if (isEnumArray(options)) {\n options.type = 'array';\n\n const enumValues = getEnumValues(options.enum);\n options.items = {\n type: getEnumType(enumValues),\n enum: enumValues,\n };\n delete options.enum;\n } else if (options.enum) {\n const enumValues = getEnumValues(options.enum);\n\n options.enum = enumValues;\n options.type = getEnumType(enumValues);\n }\n\n if (isArray) {\n options.type = 'array';\n options.items = {\n type: type as any,\n };\n }\n\n return createPropertyDecorator(DECORATORS.API_MODEL_PROPERTIES, options);\n}\n\nexport function ApiPropertyOptional(\n options: ApiPropertyOptions = {}\n): PropertyDecorator {\n return ApiProperty({\n ...options,\n required: false,\n });\n}\n\nexport function ApiResponseProperty(\n options: Pick<\n ApiPropertyOptions,\n 'type' | 'example' | 'format' | 'enum' | 'deprecated'\n > = {}\n): PropertyDecorator {\n return ApiProperty({\n readOnly: true,\n ...options,\n });\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-query.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-query.decorator.ts"],"names":[],"mappings":";;;AAOA,qDAK8B;AAC9B,uCAAsE;AAmBtE,MAAM,mBAAmB,GAAoB;IAC3C,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF,SAAgB,QAAQ,CAAC,OAAwB;IAC/C,MAAM,gBAAgB,GAAG,OAA2B,CAAC;IACrD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,6BAAmB,EACzC,gBAAgB,CAAC,IAAI,EACrB,gBAAgB,CAAC,OAAO,CACzB,CAAC;IACF,MAAM,KAAK,GAAQ;QACjB,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI;QAC7D,EAAE,EAAE,OAAO;QACX,GAAG,OAAO;QACV,IAAI;KACL,CAAC;IAEF,IAAI,IAAA,wBAAW,EAAC,OAAO,CAAC,EAAE;QACxB,IAAA,+BAAkB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KACpC;SAAM,IAAI,IAAA,0BAAa,EAAC,OAAO,CAAC,EAAE;QACjC,IAAA,0BAAa,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KAC/B;IAED,IAAI,OAAO,EAAE;QACX,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;KACzB;IAED,OAAO,IAAA,8BAAoB,EAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;AAC1D,CAAC;AAxBD,4BAwBC","sourcesContent":["import {\n Type,\n ParameterObject,\n ReferenceObject,\n SchemaObject,\n SwaggerEnumType,\n} from '../interfaces';\nimport {\n addEnumSchema,\n addEnumArraySchema,\n isEnumArray,\n isEnumDefined,\n} from '../common/enum.utils';\nimport { createParamDecorator, getTypeIsArrayTuple } from './helpers';\n\ntype ParameterOptions = Omit<ParameterObject, 'in' | 'schema' | 'name'>;\n\ninterface ApiQueryMetadata extends ParameterOptions {\n name?: string;\n type?: Type | string;\n isArray?: boolean;\n enum?: SwaggerEnumType;\n enumName?: string;\n}\n\ninterface ApiQuerySchemaHost extends ParameterOptions {\n name?: string;\n schema: SchemaObject | ReferenceObject;\n}\n\nexport type ApiQueryOptions = ApiQueryMetadata | ApiQuerySchemaHost;\n\nconst defaultQueryOptions: ApiQueryOptions = {\n name: '',\n required: true,\n};\n\nexport function ApiQuery(options: ApiQueryOptions): MethodDecorator {\n const apiQueryMetadata = options as ApiQueryMetadata;\n const [type, isArray] = getTypeIsArrayTuple(\n apiQueryMetadata.type,\n apiQueryMetadata.isArray\n );\n const param: any = {\n name: !options.name ? defaultQueryOptions.name : options.name,\n in: 'query',\n ...options,\n type,\n };\n\n if (isEnumArray(options)) {\n addEnumArraySchema(param, options);\n } else if (isEnumDefined(options)) {\n addEnumSchema(param, options);\n }\n\n if (isArray) {\n param.isArray = isArray;\n }\n\n return createParamDecorator(param, defaultQueryOptions);\n}\n"]}
@@ -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({
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-response.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-response.decorator.ts"],"names":[],"mappings":";;;AAAA,4CAA0C;AAO1C,uCAAgD;AAChD,qDAAkD;AAClD,mDAAkE;AAmBlE,SAAgB,WAAW,CAAC,OAA2B;IACrD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,6BAAmB,EACxC,OAA+B,CAAC,IAAI,EACpC,OAA+B,CAAC,OAAO,CACzC,CAAC;IAED,OAA+B,CAAC,IAAI,GAAG,IAAI,CAAC;IAC5C,OAA+B,CAAC,OAAO,GAAG,OAAO,CAAC;IACnD,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IAErE,MAAM,eAAe,GAA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CACvC,CAAC,CAAC;AANQ,QAAA,6BAA6B,iCAMrC;AAEE,MAAM,0BAA0B,GAAG,CAAC,UAA8B,EAAE,EAAE,EAAE,CAC7E,WAAW,CAAC;IACV,GAAG,OAAO;IACV,MAAM,EAAE,uBAAU,CAAC,iBAAiB;CACrC,CAAC,CAAC;AAJQ,QAAA,0BAA0B,8BAIlC;AAEE,MAAM,yBAAyB,GAAG,CAAC,UAA8B,EAAE,EAAE,EAAE,CAC5E,WAAW,CAAC;IACV,GAAG,OAAO;IACV,MAAM,EAAE,uBAAU,CAAC,eAAe;CACnC,CAAC,CAAC;AAJQ,QAAA,yBAAyB,6BAIjC;AAEE,MAAM,6BAA6B,GAAG,CAC3C,UAA8B,EAAE,EAChC,EAAE,CACF,WAAW,CAAC;IACV,GAAG,OAAO;IACV,MAAM,EAAE,uBAAU,CAAC,mBAAmB;CACvC,CAAC,CAAC;AANQ,QAAA,6BAA6B,iCAMrC;AAEE,MAAM,8BAA8B,GAAG,CAC5C,UAA8B,EAAE,EAChC,EAAE,CACF,WAAW,CAAC;IACV,GAAG,OAAO;IACV,MAAM,EAAE,uBAAU,CAAC,oBAAoB;CACxC,CAAC,CAAC;AANQ,QAAA,8BAA8B,kCAMtC;AAEE,MAAM,+BAA+B,GAAG,CAC7C,UAA8B,EAAE,EAChC,EAAE,CACF,WAAW,CAAC;IACV,GAAG,OAAO;IACV,MAAM,EAAE,uBAAU,CAAC,sBAAsB;CAC1C,CAAC,CAAC;AANQ,QAAA,+BAA+B,mCAMvC;AAEE,MAAM,kBAAkB,GAAG,CAAC,UAA8B,EAAE,EAAE,EAAE,CACrE,WAAW,CAAC;IACV,GAAG,OAAO;IACV,MAAM,EAAE,SAAS;CAClB,CAAC,CAAC;AAJQ,QAAA,kBAAkB,sBAI1B","sourcesContent":["import { DECORATORS } from '../constants';\nimport {\n ResponseObject,\n SchemaObject,\n ReferenceObject,\n Type,\n} from '../interfaces';\nimport { getTypeIsArrayTuple } from './helpers';\nimport { HttpStatus } from '../common/httpStatus';\nimport { createCustomMethodDecorator } from '@midwayjs/decorator';\n\nexport interface ApiResponseMetadata\n extends Omit<ResponseObject, 'description'> {\n status?: number | 'default';\n type?: Type | string | Record<string, any>;\n isArray?: boolean;\n description?: string;\n}\n\nexport interface ApiResponseSchemaHost\n extends Omit<ResponseObject, 'description'> {\n schema: SchemaObject & Partial<ReferenceObject>;\n status?: number;\n description?: string;\n}\n\nexport type ApiResponseOptions = ApiResponseMetadata | ApiResponseSchemaHost;\n\nexport function ApiResponse(options: ApiResponseOptions): any {\n const [type, isArray] = getTypeIsArrayTuple(\n (options as ApiResponseMetadata).type,\n (options as ApiResponseMetadata).isArray\n );\n\n (options as ApiResponseMetadata).type = type;\n (options as ApiResponseMetadata).isArray = isArray;\n options.description = options.description ? options.description : '';\n\n const groupedMetadata = {\n [options.status || 'default']: options,\n };\n\n return createCustomMethodDecorator(\n DECORATORS.API_RESPONSE,\n groupedMetadata,\n false\n );\n}\n\nexport const ApiOkResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.OK,\n });\n\nexport const ApiCreatedResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.CREATED,\n });\n\nexport const ApiAcceptedResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.ACCEPTED,\n });\n\nexport const ApiNoContentResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.NO_CONTENT,\n });\n\nexport const ApiMovedPermanentlyResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.MOVED_PERMANENTLY,\n });\n\nexport const ApiFoundResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.FOUND,\n });\n\nexport const ApiBadRequestResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.BAD_REQUEST,\n });\n\nexport const ApiUnauthorizedResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.UNAUTHORIZED,\n });\n\nexport const ApiTooManyRequestsResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.TOO_MANY_REQUESTS,\n });\n\nexport const ApiNotFoundResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.NOT_FOUND,\n });\n\nexport const ApiInternalServerErrorResponse = (\n options: ApiResponseOptions = {}\n) =>\n ApiResponse({\n ...options,\n status: HttpStatus.INTERNAL_SERVER_ERROR,\n });\n\nexport const ApiBadGatewayResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.BAD_GATEWAY,\n });\n\nexport const ApiConflictResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.CONFLICT,\n });\n\nexport const ApiForbiddenResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.FORBIDDEN,\n });\n\nexport const ApiGatewayTimeoutResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.GATEWAY_TIMEOUT,\n });\n\nexport const ApiGoneResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.GONE,\n });\n\nexport const ApiMethodNotAllowedResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.METHOD_NOT_ALLOWED,\n });\n\nexport const ApiNotAcceptableResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.NOT_ACCEPTABLE,\n });\n\nexport const ApiNotImplementedResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.NOT_IMPLEMENTED,\n });\n\nexport const ApiPreconditionFailedResponse = (\n options: ApiResponseOptions = {}\n) =>\n ApiResponse({\n ...options,\n status: HttpStatus.PRECONDITION_FAILED,\n });\n\nexport const ApiPayloadTooLargeResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.PAYLOAD_TOO_LARGE,\n });\n\nexport const ApiRequestTimeoutResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: HttpStatus.REQUEST_TIMEOUT,\n });\n\nexport const ApiServiceUnavailableResponse = (\n options: ApiResponseOptions = {}\n) =>\n ApiResponse({\n ...options,\n status: HttpStatus.SERVICE_UNAVAILABLE,\n });\n\nexport const ApiUnprocessableEntityResponse = (\n options: ApiResponseOptions = {}\n) =>\n ApiResponse({\n ...options,\n status: HttpStatus.UNPROCESSABLE_ENTITY,\n });\n\nexport const ApiUnsupportedMediaTypeResponse = (\n options: ApiResponseOptions = {}\n) =>\n ApiResponse({\n ...options,\n status: HttpStatus.UNSUPPORTED_MEDIA_TYPE,\n });\n\nexport const ApiDefaultResponse = (options: ApiResponseOptions = {}) =>\n ApiResponse({\n ...options,\n status: 'default',\n });\n"]}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-security.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-security.decorator.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAClE,4CAA0C;AAG1C,SAAgB,WAAW,CACzB,IAAwC,EACxC,eAAyB,EAAE;IAE3B,IAAI,QAAmC,CAAC;IAExC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,QAAQ,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,YAAY,IAAI,EAAE,EAAE,CAAC;KAC3C;SAAM;QACL,QAAQ,GAAG,IAAI,CAAC;KACjB;IAED,OAAO,IAAA,uCAA2B,EAAC,sBAAU,CAAC,YAAY,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC/E,CAAC;AAbD,kCAaC","sourcesContent":["import { createCustomMethodDecorator } from '@midwayjs/decorator';\nimport { DECORATORS } from '../constants';\nimport { SecurityRequirementObject } from '../interfaces';\n\nexport function ApiSecurity(\n name: string | SecurityRequirementObject,\n requirements: string[] = []\n): any {\n let metadata: SecurityRequirementObject;\n\n if (typeof name === 'string') {\n metadata = { [name]: requirements || [] };\n } else {\n metadata = name;\n }\n\n return createCustomMethodDecorator(DECORATORS.API_SECURITY, metadata, false);\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-tags.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-tags.decorator.ts"],"names":[],"mappings":";;;AAAA,4CAA0C;AAC1C,uCAAiD;AAEjD,SAAgB,OAAO,CAAC,GAAG,IAAc;IACvC,OAAO,IAAA,8BAAoB,EAAC,sBAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC;AAFD,0BAEC","sourcesContent":["import { DECORATORS } from '../constants';\nimport { createMixedDecorator } from './helpers';\n\nexport function ApiTags(...tags: string[]) {\n return createMixedDecorator(DECORATORS.API_TAGS, tags);\n}\n"]}
@@ -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) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/decorators/helpers.ts"],"names":[],"mappings":";;;AAAA,mDAG6B;AAC7B,4CAA0C;AAG1C,SAAgB,uBAAuB,CACrC,OAAe,EACf,QAAW;IAEX,OAAO,IAAA,yCAA6B,EAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AACjE,CAAC;AALD,0DAKC;AAED,SAAgB,oBAAoB,CAClC,OAAe,EACf,QAAW;IAEX,OAAO,IAAA,uCAA2B,EAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC;AALD,oDAKC;AAED,SAAgB,oBAAoB,CAClC,QAAW,EACX,OAAmB;IAEnB,OAAO,IAAA,uCAA2B,EAChC,sBAAU,CAAC,cAAc,EACzB;QACE,GAAG,OAAO;QACV,GAAG,QAAQ;KACZ,EACD,KAAK,CACN,CAAC;AACJ,CAAC;AAZD,oDAYC;AAED,SAAgB,mBAAmB,CACjC,KAAsD,EACtD,WAAoB;IAEpB,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,CAAC,KAAkB,EAAE,WAAW,CAAC,CAAC;KAC1C;IACD,IAAI,WAAW,EAAE;QACf,OAAO,CAAC,KAAa,EAAE,WAAW,CAAC,CAAC;KACrC;IACD,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7C,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAC9B,CAAC;AAbD,kDAaC;AAED,SAAgB,aAAa,CAAC,IAAmB;IAC/C,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,GAAG,GAAG,IAAI,CAAC,CAAC,CAAE,IAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;KACxC;IACD,OAAO,wBAAwB,GAAG,EAAE,CAAC;AACvC,CAAC;AAND,sCAMC","sourcesContent":["import {\n createCustomMethodDecorator,\n createCustomPropertyDecorator,\n} from '@midwayjs/decorator';\nimport { DECORATORS } from '../constants';\nimport type { Type } from '../interfaces';\n\nexport function createPropertyDecorator<T extends Record<string, any> = any>(\n metakey: string,\n metadata: T\n): PropertyDecorator {\n return createCustomPropertyDecorator(metakey, metadata, false);\n}\n\nexport function createMixedDecorator<T = any>(\n metakey: string,\n metadata: T\n): any {\n return createCustomMethodDecorator(metakey, metadata, false);\n}\n\nexport function createParamDecorator<T extends Record<string, any> = any>(\n metadata: T,\n initial: Partial<T>\n): MethodDecorator {\n return createCustomMethodDecorator(\n DECORATORS.API_PARAMETERS,\n {\n ...initial,\n ...metadata,\n },\n false\n );\n}\n\nexport function getTypeIsArrayTuple(\n input: Type | undefined | string | Record<string, any>,\n isArrayFlag: boolean\n): [Type | undefined | string | Record<string, any>, boolean] {\n if (!input) {\n return [input as undefined, isArrayFlag];\n }\n if (isArrayFlag) {\n return [input as Type, isArrayFlag];\n }\n const isInputArray = Array.isArray(input);\n const type = isInputArray ? input[0] : input;\n return [type, isInputArray];\n}\n\nexport function getSchemaPath(clzz: Type | string) {\n let str = clzz;\n if (typeof clzz === 'object') {\n str = clzz ? (clzz as any).name : clzz;\n }\n return `#/components/schemas/${str}`;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,uDAAqC;AACrC,mEAAiD;AACjD,qEAAmD;AACnD,yDAAuC;AACvC,4DAA0C;AAC1C,wDAAsC;AACtC,mEAKkC;AAJhC,qHAAA,WAAW,OAAA;AACX,6HAAA,mBAAmB,OAAA;AAEnB,6HAAA,mBAAmB,OAAA;AAErB,wDAAsC;AACtC,2DAAyC;AACzC,uDAAqC;AACrC,4DAA0C;AAC1C,wDAAsC;AACtC,yDAAuC;AACvC,yDAAuC;AACvC,yDAAuC;AACvC,2DAAyC;AACzC,qCAA0C;AAAjC,wGAAA,aAAa,OAAA","sourcesContent":["export * from './api-body.decorator';\nexport * from './api-exclude-endpoint.decorator';\nexport * from './api-exclude-controller.decorator';\nexport * from './api-header.decorator';\nexport * from './api-operation.decorator';\nexport * from './api-param.decorator';\nexport {\n ApiProperty,\n ApiPropertyOptional,\n ApiPropertyOptions,\n ApiResponseProperty,\n} from './api-property.decorator';\nexport * from './api-query.decorator';\nexport * from './api-response.decorator';\nexport * from './api-tags.decorator';\nexport * from './api-extension.decorator';\nexport * from './api-basic.decorator';\nexport * from './api-bearer.decorator';\nexport * from './api-cookie.decorator';\nexport * from './api-oauth2.decorator';\nexport * from './api-security.decorator';\nexport { getSchemaPath } from './helpers';\n"]}
@@ -9,9 +9,10 @@ export declare class DocumentBuilder {
9
9
  setLicense(name: string, url: string): this;
10
10
  addServer(url: string, description?: string, variables?: Record<string, ServerVariableObject>): this;
11
11
  setExternalDoc(description: string, url: string): this;
12
- setBasePath(path: string): this;
12
+ setBasePath(path: string | string[]): this;
13
13
  addPaths(paths: Record<string, PathItemObject>): this;
14
14
  addSchema(schema: Record<string, SchemaObject>): this;
15
+ getSchema(name: string): SchemaObject;
15
16
  addTag(name: string, description?: string, externalDocs?: ExternalDocumentationObject): this;
16
17
  addSecurity(name: string, options: SecuritySchemeObject): this;
17
18
  addSecurityRequirements(name: string | SecurityRequirementObject, requirements?: string[]): this;
@@ -20,6 +21,7 @@ export declare class DocumentBuilder {
20
21
  addApiKey(options?: SecuritySchemeObject, name?: string): this;
21
22
  addBasicAuth(options?: SecuritySchemeObject, name?: string): this;
22
23
  addCookieAuth(cookieName?: string, options?: SecuritySchemeObject, securityName?: string): this;
24
+ sortTags(): void;
23
25
  build(): Omit<OpenAPIObject, 'paths'>;
24
26
  }
25
27
  //# sourceMappingURL=documentBuilder.d.ts.map
@@ -77,6 +77,13 @@ class DocumentBuilder {
77
77
  Object.assign(this.document.components.schemas, schema);
78
78
  return this;
79
79
  }
80
+ getSchema(name) {
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;
86
+ }
80
87
  addTag(name, description = '', externalDocs) {
81
88
  if (Array.isArray(name)) {
82
89
  const arr = name;
@@ -184,6 +191,23 @@ class DocumentBuilder {
184
191
  });
185
192
  return this;
186
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
+ }
187
211
  build() {
188
212
  return this.document;
189
213
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentBuilder.js","sourceRoot":"","sources":["../src/documentBuilder.ts"],"names":[],"mappings":";;;AAWA,MAAa,eAAe;IAA5B;QACmB,aAAQ,GAAkB;YACzC,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE;gBACJ,KAAK,EAAE,EAAE;gBACT,WAAW,EAAE,EAAE;gBACf,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE,EAAE;aAC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AAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAhQD,0CAgQC","sourcesContent":["import {\n OpenAPIObject,\n ExternalDocumentationObject,\n SecurityRequirementObject,\n SecuritySchemeObject,\n ServerVariableObject,\n PathItemObject,\n SchemaObject,\n TagObject,\n} from './interfaces';\n\nexport class DocumentBuilder {\n private readonly document: OpenAPIObject = {\n openapi: '3.0.1',\n info: {\n title: '',\n description: '',\n version: '1.0.0',\n contact: {},\n },\n tags: [],\n servers: [],\n components: {},\n paths: {},\n };\n\n public setTitle(title: string): this {\n this.document.info.title = title;\n return this;\n }\n\n public setDescription(description: string): this {\n this.document.info.description = description;\n return this;\n }\n\n public setVersion(version: string): this {\n this.document.info.version = version;\n return this;\n }\n\n public setTermsOfService(termsOfService: string): this {\n this.document.info.termsOfService = termsOfService;\n return this;\n }\n\n public setContact(name: string, url: string, email: string): this {\n this.document.info.contact = { name, url, email };\n return this;\n }\n\n public setLicense(name: string, url: string): this {\n this.document.info.license = { name, url };\n return this;\n }\n\n public addServer(\n url: string,\n description?: string,\n variables?: Record<string, ServerVariableObject>\n ): this {\n this.document.servers.push({ url, description, variables });\n return this;\n }\n\n public setExternalDoc(description: string, url: string): this {\n this.document.externalDocs = { description, url };\n return this;\n }\n\n public setBasePath(path: string | string[]) {\n if ((this.document as any).basePath) {\n if (Array.isArray((this.document as any).basePath)) {\n (this.document as any).basePath.push(path);\n } else {\n (this.document as any).basePath = [\n (this.document as any).basePath,\n path,\n ];\n }\n } else {\n (this.document as any).basePath = path;\n }\n return this;\n }\n\n public addPaths(paths: Record<string, PathItemObject>) {\n Object.assign(this.document.paths, paths);\n return this;\n }\n\n public addSchema(schema: Record<string, SchemaObject>) {\n if (!this.document.components.schemas) {\n this.document.components.schemas = {};\n }\n Object.assign(this.document.components.schemas, schema);\n return this;\n }\n\n public getSchema(name: string): SchemaObject {\n if (this.document.components?.schemas) {\n return this.document.components?.schemas[name] as SchemaObject;\n }\n return undefined;\n }\n\n public addTag(\n name: string,\n description = '',\n externalDocs?: ExternalDocumentationObject\n ): this {\n if (Array.isArray(name)) {\n const arr = name as Array<string>;\n for (const s of arr) {\n this.document.tags.push({\n name: s,\n description: '',\n });\n }\n return this;\n }\n this.document.tags.push({\n name,\n description,\n externalDocs,\n });\n return this;\n }\n\n public addSecurity(name: string, options: SecuritySchemeObject): this {\n this.document.components.securitySchemes = {\n ...(this.document.components.securitySchemes || {}),\n [name]: options,\n };\n return this;\n }\n\n public addSecurityRequirements(\n name: string | SecurityRequirementObject,\n requirements: string[] = []\n ): this {\n let securityRequirement: SecurityRequirementObject;\n\n if (typeof name === 'string') {\n securityRequirement = { [name as string]: requirements };\n } else {\n securityRequirement = name as SecurityRequirementObject;\n }\n\n this.document.security = (this.document.security || []).concat({\n ...securityRequirement,\n });\n return this;\n }\n\n public addBearerAuth(\n options: SecuritySchemeObject = {\n type: 'http',\n },\n name = 'bearer'\n ): this {\n this.addSecurity(name, {\n type: 'http',\n scheme: 'bearer',\n bearerFormat: 'JWT',\n ...options,\n });\n return this;\n }\n\n public addOAuth2(\n options: SecuritySchemeObject = {\n type: 'oauth2',\n },\n name = 'oauth2'\n ): this {\n if (!name) {\n name = 'oauth2';\n }\n this.addSecurity(name, {\n type: 'oauth2',\n flows: {\n ...options?.flows,\n },\n });\n return this;\n }\n\n public addApiKey(\n options: SecuritySchemeObject = {\n type: 'apiKey',\n },\n name = 'api_key'\n ): this {\n if (!name) {\n name = 'api_key';\n }\n this.addSecurity(name, {\n type: 'apiKey',\n in: 'header',\n name,\n ...options,\n });\n return this;\n }\n\n public addBasicAuth(\n options: SecuritySchemeObject = {\n type: 'http',\n },\n name = 'basic'\n ): this {\n if (!name) {\n name = 'basic';\n }\n this.addSecurity(name, {\n type: 'http',\n scheme: 'basic',\n ...options,\n });\n return this;\n }\n\n public addCookieAuth(\n cookieName = 'connect.sid',\n options: SecuritySchemeObject = {\n type: 'apiKey',\n },\n securityName = 'cookie'\n ): this {\n if (!cookieName) {\n cookieName = 'connect.sid';\n }\n if (!securityName) {\n securityName = 'cookie';\n }\n this.addSecurity(securityName, {\n type: 'apiKey',\n in: 'cookie',\n name: cookieName,\n ...options,\n });\n return this;\n }\n\n public sortTags(): void {\n const tags = this.document.tags;\n this.document.tags = tags.sort((a: TagObject, b: TagObject): number => {\n const s1 = a.name;\n const s2 = b.name;\n\n const len = s1.length > s2.length ? s2.length : s1.length;\n for (let i = 0; i < len; i++) {\n if (s1.charCodeAt(i) > s2.charCodeAt(i)) {\n return 1;\n } else if (s1.charCodeAt(i) < s2.charCodeAt(i)) {\n return -1;\n }\n }\n\n return 0;\n });\n }\n\n public build(): Omit<OpenAPIObject, 'paths'> {\n return this.document;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,iDAAwE;AAA/D,8GAAA,oBAAoB,OAAiB;AAC9C,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA","sourcesContent":["export * from './decorators';\nexport * from './interfaces';\nexport { SwaggerConfiguration as Configuration } from './configuration';\nexport { SwaggerExplorer } from './swaggerExplorer';\nexport { SwaggerMiddleware } from './swaggerMiddleware';\n"]}
@@ -251,18 +251,94 @@ export interface SchemaObjectMetadata extends Omit<SchemaObject, 'type' | 'requi
251
251
  name?: string;
252
252
  enumName?: string;
253
253
  }
254
+ export declare type AuthType = 'basic' | 'bearer' | 'cookie' | 'oauth2' | 'apikey' | 'custom';
255
+ /**
256
+ * 继承自 https://swagger.io/specification/#security-scheme-object
257
+ */
258
+ export interface AuthOptions extends Omit<SecuritySchemeObject, 'type'> {
259
+ /**
260
+ * 验权类型
261
+ * basic => http basic 验证
262
+ * bearer => http jwt 验证
263
+ * cookie => cookie 方式验证
264
+ * oauth2 => 使用 oauth2
265
+ * apikey => apiKey
266
+ * custom => 自定义方式
267
+ */
268
+ authType: AuthType;
269
+ /**
270
+ * https://swagger.io/specification/#security-scheme-object type 字段
271
+ */
272
+ type?: SecuritySchemeType;
273
+ /**
274
+ * authType = cookie 时可以修改,通过 ApiCookie 装饰器关联的名称
275
+ */
276
+ securityName?: string;
277
+ /**
278
+ * authType = cookie 时可以修改,cookie 的名称
279
+ */
280
+ cookieName?: string;
281
+ }
282
+ /**
283
+ * see https://swagger.io/specification/
284
+ */
254
285
  export interface SwaggerOptions {
286
+ /**
287
+ * 默认值: My Project
288
+ * https://swagger.io/specification/#info-object title 字段
289
+ */
255
290
  title?: string;
291
+ /**
292
+ * 默认值: This is a swagger-ui for midwayjs project
293
+ * https://swagger.io/specification/#info-object description 字段
294
+ */
256
295
  description?: string;
296
+ /**
297
+ * 默认值: 1.0.0
298
+ * https://swagger.io/specification/#info-object version 字段
299
+ */
257
300
  version?: string;
258
- swaggerPath?: string;
301
+ /**
302
+ * https://swagger.io/specification/#info-object contact 字段
303
+ */
259
304
  contact?: ContactObject;
305
+ /**
306
+ * https://swagger.io/specification/#info-object license 字段
307
+ */
260
308
  license?: LicenseObject;
261
- basePath?: string;
309
+ /**
310
+ * https://swagger.io/specification/#info-object termsOfService 字段
311
+ */
262
312
  termsOfService?: string;
263
- externalDoc?: ExternalDocumentationObject;
313
+ /**
314
+ * https://swagger.io/specification/#openapi-object externalDocs 字段
315
+ */
316
+ externalDocs?: ExternalDocumentationObject;
317
+ /**
318
+ * https://swagger.io/specification/#openapi-object servers 字段
319
+ */
264
320
  servers?: Array<ServerObject>;
321
+ /**
322
+ * https://swagger.io/specification/#openapi-object tags 字段
323
+ */
265
324
  tags?: Array<TagObject>;
266
- auth?: SecuritySchemeObject;
325
+ /**
326
+ * 可以参考 https://swagger.io/specification/#security-scheme-object
327
+ */
328
+ auth?: AuthOptions | AuthOptions[];
329
+ /**
330
+ * api 的 根路径
331
+ */
332
+ basePath?: string | string[];
333
+ /**
334
+ * 默认值: /swagger-ui
335
+ * 访问 swagger ui 的路径
336
+ */
337
+ swaggerPath?: string;
338
+ /**
339
+ * 对路由 tag 进行 ascii 排序
340
+ * 可以使用 1-xxx、2-xxx、3-xxx 来定义 tag
341
+ */
342
+ tagSortable?: boolean;
267
343
  }
268
344
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * inspired by https://github.com/metadevpro/openapi3-ts\n * @see https://github.com/OAI/OpenAPI-Specification/blob/3.0.0-rc0/versions/3.0.md\n */\n\nexport interface OpenAPIObject {\n openapi: string;\n info: InfoObject;\n servers?: ServerObject[];\n paths: PathsObject;\n components?: ComponentsObject;\n security?: SecurityRequirementObject[];\n tags?: TagObject[];\n externalDocs?: ExternalDocumentationObject;\n}\n\nexport interface InfoObject {\n title: string;\n description?: string;\n termsOfService?: string;\n contact?: ContactObject;\n license?: LicenseObject;\n version: string;\n}\n\nexport interface ContactObject {\n name?: string;\n url?: string;\n email?: string;\n}\n\nexport interface LicenseObject {\n name: string;\n url?: string;\n}\n\nexport interface ServerObject {\n url: string;\n description?: string;\n variables?: Record<string, ServerVariableObject>;\n}\n\nexport interface ServerVariableObject {\n enum?: string[] | boolean[] | number[];\n default: string | boolean | number;\n description?: string;\n}\n\nexport interface ComponentsObject {\n schemas?: Record<string, SchemaObject | ReferenceObject>;\n responses?: Record<string, ResponseObject | ReferenceObject>;\n parameters?: Record<string, ParameterObject | ReferenceObject>;\n examples?: Record<string, ExampleObject | ReferenceObject>;\n requestBodies?: Record<string, RequestBodyObject | ReferenceObject>;\n headers?: Record<string, HeaderObject | ReferenceObject>;\n securitySchemes?: Record<string, SecuritySchemeObject | ReferenceObject>;\n links?: Record<string, LinkObject | ReferenceObject>;\n callbacks?: Record<string, CallbackObject | ReferenceObject>;\n}\n\nexport type PathsObject = Record<string, PathItemObject>;\nexport interface PathItemObject {\n $ref?: string;\n summary?: string;\n description?: string;\n get?: OperationObject;\n put?: OperationObject;\n post?: OperationObject;\n delete?: OperationObject;\n options?: OperationObject;\n head?: OperationObject;\n patch?: OperationObject;\n trace?: OperationObject;\n servers?: ServerObject[];\n parameters?: (ParameterObject | ReferenceObject)[];\n}\n\nexport interface OperationObject {\n tags?: string[];\n summary?: string;\n description?: string;\n externalDocs?: ExternalDocumentationObject;\n operationId?: string;\n parameters?: (ParameterObject | ReferenceObject)[];\n requestBody?: RequestBodyObject | ReferenceObject;\n responses: ResponsesObject;\n callbacks?: CallbacksObject;\n deprecated?: boolean;\n security?: SecurityRequirementObject[];\n servers?: ServerObject[];\n}\n\nexport interface ExternalDocumentationObject {\n description?: string;\n url: string;\n}\n\nexport type ParameterLocation = 'query' | 'header' | 'path' | 'cookie';\nexport type ParameterStyle =\n | 'matrix'\n | 'label'\n | 'form'\n | 'simple'\n | 'spaceDelimited'\n | 'pipeDelimited'\n | 'deepObject';\n\nexport interface BaseParameterObject {\n description?: string;\n required?: boolean;\n deprecated?: boolean;\n allowEmptyValue?: boolean;\n style?: ParameterStyle;\n explode?: boolean;\n allowReserved?: boolean;\n schema?: SchemaObject | ReferenceObject;\n examples?: Record<string, ExampleObject | ReferenceObject>;\n example?: any;\n content?: ContentObject;\n}\n\nexport interface ParameterObject extends BaseParameterObject {\n name: string;\n in: ParameterLocation;\n}\n\nexport interface RequestBodyObject {\n description?: string;\n content: ContentObject;\n required?: boolean;\n}\n\nexport type ContentObject = Record<string, MediaTypeObject>;\nexport interface MediaTypeObject {\n schema?: SchemaObject | ReferenceObject;\n examples?: ExamplesObject;\n example?: any;\n encoding?: EncodingObject;\n}\n\nexport type EncodingObject = Record<string, EncodingPropertyObject>;\nexport interface EncodingPropertyObject {\n contentType?: string;\n headers?: Record<string, HeaderObject | ReferenceObject>;\n style?: string;\n explode?: boolean;\n allowReserved?: boolean;\n}\n\nexport interface ResponsesObject\n extends Record<string, ResponseObject | ReferenceObject | undefined> {\n default?: ResponseObject | ReferenceObject;\n}\n\nexport interface ResponseObject {\n description: string;\n headers?: HeadersObject;\n content?: ContentObject;\n links?: LinksObject;\n}\n\nexport type CallbacksObject = Record<string, CallbackObject | ReferenceObject>;\nexport type CallbackObject = Record<string, PathItemObject>;\nexport type HeadersObject = Record<string, HeaderObject | ReferenceObject>;\n\nexport interface ExampleObject {\n summary?: string;\n description?: string;\n value?: any;\n externalValue?: string;\n}\n\nexport type LinksObject = Record<string, LinkObject | ReferenceObject>;\nexport interface LinkObject {\n operationRef?: string;\n operationId?: string;\n parameters?: LinkParametersObject;\n requestBody?: any | string;\n description?: string;\n server?: ServerObject;\n}\n\nexport type LinkParametersObject = Record<string, any>;\nexport type HeaderObject = BaseParameterObject;\nexport interface TagObject {\n name: string;\n description?: string;\n externalDocs?: ExternalDocumentationObject;\n}\n\nexport type ExamplesObject = Record<string, ExampleObject | ReferenceObject>;\n\nexport interface ReferenceObject {\n $ref: string;\n}\n\nexport interface SchemaObject {\n nullable?: boolean;\n discriminator?: DiscriminatorObject;\n readOnly?: boolean;\n writeOnly?: boolean;\n xml?: XmlObject;\n externalDocs?: ExternalDocumentationObject;\n example?: any;\n examples?: any[] | Record<string, any>;\n deprecated?: boolean;\n type?: string;\n allOf?: (SchemaObject | ReferenceObject)[];\n oneOf?: (SchemaObject | ReferenceObject)[];\n anyOf?: (SchemaObject | ReferenceObject)[];\n not?: SchemaObject | ReferenceObject;\n items?: SchemaObject | ReferenceObject;\n properties?: Record<string, SchemaObject | ReferenceObject>;\n additionalProperties?: SchemaObject | ReferenceObject | boolean;\n patternProperties?: SchemaObject | ReferenceObject | any;\n description?: string;\n format?: string;\n default?: any;\n title?: string;\n multipleOf?: number;\n maximum?: number;\n exclusiveMaximum?: boolean;\n minimum?: number;\n exclusiveMinimum?: boolean;\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n maxItems?: number;\n minItems?: number;\n uniqueItems?: boolean;\n maxProperties?: number;\n minProperties?: number;\n required?: string[];\n enum?: any[];\n}\n\nexport type SchemasObject = Record<string, SchemaObject>;\n\nexport interface DiscriminatorObject {\n propertyName: string;\n mapping?: Record<string, string>;\n}\n\nexport interface XmlObject {\n name?: string;\n namespace?: string;\n prefix?: string;\n attribute?: boolean;\n wrapped?: boolean;\n}\n\nexport type SecuritySchemeType = 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';\n\nexport interface SecuritySchemeObject {\n type: SecuritySchemeType;\n description?: string;\n name?: string;\n in?: string;\n scheme?: string;\n bearerFormat?: string;\n flows?: OAuthFlowsObject;\n openIdConnectUrl?: string;\n}\n\nexport interface OAuthFlowsObject {\n implicit?: OAuthFlowObject;\n password?: OAuthFlowObject;\n clientCredentials?: OAuthFlowObject;\n authorizationCode?: OAuthFlowObject;\n}\n\nexport interface OAuthFlowObject {\n authorizationUrl?: string;\n tokenUrl?: string;\n refreshUrl?: string;\n scopes: ScopesObject;\n}\n\nexport type ScopesObject = Record<string, any>;\nexport type SecurityRequirementObject = Record<string, string[]>;\n\n/**\n * 非 open api spec\n */\nexport type SwaggerEnumType =\n | string[]\n | number[]\n | (string | number)[]\n | Record<number, string>;\n\nexport interface Type<T = any> extends Function {\n new (...args: any[]): T;\n}\n\nexport interface SchemaObjectMetadata\n extends Omit<SchemaObject, 'type' | 'required'> {\n type?: Type<unknown> | [Type] | string | Record<string, any>;\n isArray?: boolean;\n required?: boolean;\n name?: string;\n enumName?: string;\n}\n\nexport type AuthType =\n | 'basic'\n | 'bearer'\n | 'cookie'\n | 'oauth2'\n | 'apikey'\n | 'custom';\n\n/**\n * 继承自 https://swagger.io/specification/#security-scheme-object\n */\nexport interface AuthOptions extends Omit<SecuritySchemeObject, 'type'> {\n /**\n * 验权类型\n * basic => http basic 验证\n * bearer => http jwt 验证\n * cookie => cookie 方式验证\n * oauth2 => 使用 oauth2\n * apikey => apiKey\n * custom => 自定义方式\n */\n authType: AuthType;\n /**\n * https://swagger.io/specification/#security-scheme-object type 字段\n */\n type?: SecuritySchemeType;\n /**\n * authType = cookie 时可以修改,通过 ApiCookie 装饰器关联的名称\n */\n securityName?: string;\n /**\n * authType = cookie 时可以修改,cookie 的名称\n */\n cookieName?: string;\n}\n/**\n * see https://swagger.io/specification/\n */\nexport interface SwaggerOptions {\n /**\n * 默认值: My Project\n * https://swagger.io/specification/#info-object title 字段\n */\n title?: string;\n /**\n * 默认值: This is a swagger-ui for midwayjs project\n * https://swagger.io/specification/#info-object description 字段\n */\n description?: string;\n /**\n * 默认值: 1.0.0\n * https://swagger.io/specification/#info-object version 字段\n */\n version?: string;\n /**\n * https://swagger.io/specification/#info-object contact 字段\n */\n contact?: ContactObject;\n /**\n * https://swagger.io/specification/#info-object license 字段\n */\n license?: LicenseObject;\n /**\n * https://swagger.io/specification/#info-object termsOfService 字段\n */\n termsOfService?: string;\n /**\n * https://swagger.io/specification/#openapi-object externalDocs 字段\n */\n externalDocs?: ExternalDocumentationObject;\n /**\n * https://swagger.io/specification/#openapi-object servers 字段\n */\n servers?: Array<ServerObject>;\n /**\n * https://swagger.io/specification/#openapi-object tags 字段\n */\n tags?: Array<TagObject>;\n /**\n * 可以参考 https://swagger.io/specification/#security-scheme-object\n */\n auth?: AuthOptions | AuthOptions[];\n /**\n * api 的 根路径\n */\n basePath?: string | string[];\n /**\n * 默认值: /swagger-ui\n * 访问 swagger ui 的路径\n */\n swaggerPath?: string;\n /**\n * 对路由 tag 进行 ascii 排序\n * 可以使用 1-xxx、2-xxx、3-xxx 来定义 tag\n */\n tagSortable?: boolean;\n}\n"]}
@@ -13,12 +13,13 @@ exports.SwaggerExplorer = void 0;
13
13
  const decorator_1 = require("@midwayjs/decorator");
14
14
  const constants_1 = require("./constants");
15
15
  const documentBuilder_1 = require("./documentBuilder");
16
+ const _1 = require(".");
16
17
  let SwaggerExplorer = class SwaggerExplorer {
17
18
  constructor() {
18
19
  this.documentBuilder = new documentBuilder_1.DocumentBuilder();
19
20
  }
20
21
  async init() {
21
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
22
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _2, _3, _4, _5;
22
23
  this.documentBuilder.setTitle(this.swaggerConfig.title);
23
24
  this.documentBuilder.setVersion(this.swaggerConfig.version);
24
25
  this.documentBuilder.setDescription(this.swaggerConfig.description);
@@ -36,9 +37,9 @@ let SwaggerExplorer = class SwaggerExplorer {
36
37
  if (this.swaggerConfig.termsOfService) {
37
38
  this.documentBuilder.setTermsOfService(this.swaggerConfig.termsOfService);
38
39
  }
39
- if (((_q = this.swaggerConfig) === null || _q === void 0 ? void 0 : _q.externalDoc) &&
40
- typeof ((_r = this.swaggerConfig) === null || _r === void 0 ? void 0 : _r.externalDoc) === 'object') {
41
- this.documentBuilder.setExternalDoc((_t = (_s = this.swaggerConfig) === null || _s === void 0 ? void 0 : _s.externalDoc) === null || _t === void 0 ? void 0 : _t.description, (_v = (_u = this.swaggerConfig) === null || _u === void 0 ? void 0 : _u.externalDoc) === null || _v === void 0 ? void 0 : _v.url);
40
+ if (((_q = this.swaggerConfig) === null || _q === void 0 ? void 0 : _q.externalDocs) &&
41
+ typeof ((_r = this.swaggerConfig) === null || _r === void 0 ? void 0 : _r.externalDocs) === 'object') {
42
+ this.documentBuilder.setExternalDoc((_t = (_s = this.swaggerConfig) === null || _s === void 0 ? void 0 : _s.externalDocs) === null || _t === void 0 ? void 0 : _t.description, (_v = (_u = this.swaggerConfig) === null || _u === void 0 ? void 0 : _u.externalDocs) === null || _v === void 0 ? void 0 : _v.url);
42
43
  }
43
44
  if (((_w = this.swaggerConfig) === null || _w === void 0 ? void 0 : _w.servers) &&
44
45
  Array.isArray((_x = this.swaggerConfig) === null || _x === void 0 ? void 0 : _x.servers)) {
@@ -47,25 +48,29 @@ let SwaggerExplorer = class SwaggerExplorer {
47
48
  }
48
49
  }
49
50
  if (((_z = this.swaggerConfig) === null || _z === void 0 ? void 0 : _z.tags) && Array.isArray((_0 = this.swaggerConfig) === null || _0 === void 0 ? void 0 : _0.tags)) {
50
- for (const t of (_1 = this.swaggerConfig) === null || _1 === void 0 ? void 0 : _1.tags) {
51
+ for (const t of (_2 = this.swaggerConfig) === null || _2 === void 0 ? void 0 : _2.tags) {
51
52
  this.documentBuilder.addTag(t.name, t.description, t.externalDocs);
52
53
  }
53
54
  }
54
55
  // 设置 auth 类型
55
- if (Array.isArray((_2 = this.swaggerConfig) === null || _2 === void 0 ? void 0 : _2.auth)) {
56
- for (const a of (_3 = this.swaggerConfig) === null || _3 === void 0 ? void 0 : _3.auth) {
56
+ if (Array.isArray((_3 = this.swaggerConfig) === null || _3 === void 0 ? void 0 : _3.auth)) {
57
+ for (const a of (_4 = this.swaggerConfig) === null || _4 === void 0 ? void 0 : _4.auth) {
57
58
  this.setAuth(a);
58
59
  }
59
60
  }
60
61
  else {
61
- this.setAuth((_4 = this.swaggerConfig) === null || _4 === void 0 ? void 0 : _4.auth);
62
+ this.setAuth((_5 = this.swaggerConfig) === null || _5 === void 0 ? void 0 : _5.auth);
62
63
  }
63
64
  }
64
65
  scanApp() {
66
+ var _a;
65
67
  const routes = (0, decorator_1.listModule)(decorator_1.CONTROLLER_KEY);
66
68
  for (const route of routes) {
67
69
  this.generatePath(route);
68
70
  }
71
+ if ((_a = this.swaggerConfig) === null || _a === void 0 ? void 0 : _a.tagSortable) {
72
+ this.documentBuilder.sortTags();
73
+ }
69
74
  }
70
75
  getData() {
71
76
  return this.documentBuilder.build();
@@ -98,11 +103,12 @@ let SwaggerExplorer = class SwaggerExplorer {
98
103
  (controllerOption === null || controllerOption === void 0 ? void 0 : controllerOption.routerOptions.description) || tag.name;
99
104
  }
100
105
  else {
101
- tag.name = (controllerOption === null || controllerOption === void 0 ? void 0 : controllerOption.routerOptions.tagName) || 'default';
106
+ tag.name = controllerOption === null || controllerOption === void 0 ? void 0 : controllerOption.routerOptions.tagName;
102
107
  tag.description =
103
108
  (controllerOption === null || controllerOption === void 0 ? void 0 : controllerOption.routerOptions.description) || tag.name;
104
109
  }
105
110
  if (tag.name) {
111
+ strTags.push(tag.name);
106
112
  this.documentBuilder.addTag(tag.name, tag.description);
107
113
  }
108
114
  }
@@ -158,7 +164,7 @@ let SwaggerExplorer = class SwaggerExplorer {
158
164
  * 构造 router 提取方法
159
165
  */
160
166
  generateRouteMethod(url, webRouter, paths, metaForMethods, metaForParams, header, target) {
161
- var _a, _b, _c, _d, _e, _f, _g, _h;
167
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
162
168
  const operMeta = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_OPERATION &&
163
169
  item.propertyName === webRouter.method)[0];
164
170
  let opts = paths[url];
@@ -196,7 +202,7 @@ let SwaggerExplorer = class SwaggerExplorer {
196
202
  continue;
197
203
  }
198
204
  }
199
- if ((0, decorator_1.isClass)(currentType)) {
205
+ if (decorator_1.Types.isClass(currentType)) {
200
206
  this.parseClzz(currentType);
201
207
  p.schema = {
202
208
  $ref: '#/components/schemas/' + currentType.name,
@@ -209,16 +215,66 @@ let SwaggerExplorer = class SwaggerExplorer {
209
215
  }
210
216
  this.parseFromParamsToP(params[params.length - 1 - arg.parameterIndex], p);
211
217
  if (p.in === 'body') {
212
- const requestBody = {
213
- required: true,
214
- description: p.description || p.name,
215
- content: p.content || {
216
- 'application/json': {
217
- schema: p.schema,
218
+ // 这里兼容一下 @File()、@Files()、@Fields() 装饰器
219
+ if (((_j = arg.metadata) === null || _j === void 0 ? void 0 : _j.type) === decorator_1.RouteParamTypes.FILESSTREAM) {
220
+ p.schema = {
221
+ type: 'object',
222
+ properties: {
223
+ files: {
224
+ type: 'array',
225
+ items: {
226
+ type: 'string',
227
+ format: 'binary',
228
+ },
229
+ description: p.description,
230
+ },
218
231
  },
219
- },
220
- };
221
- opts[webRouter.requestMethod].requestBody = requestBody;
232
+ };
233
+ p.contentType = _1.BodyContentType.Multipart;
234
+ }
235
+ if (((_k = arg.metadata) === null || _k === void 0 ? void 0 : _k.type) === decorator_1.RouteParamTypes.FILESTREAM) {
236
+ p.schema = {
237
+ type: 'object',
238
+ properties: {
239
+ file: {
240
+ type: 'string',
241
+ format: 'binary',
242
+ description: p.description,
243
+ },
244
+ },
245
+ };
246
+ p.contentType = _1.BodyContentType.Multipart;
247
+ }
248
+ if (((_l = arg.metadata) === null || _l === void 0 ? void 0 : _l.type) === decorator_1.RouteParamTypes.FIELDS) {
249
+ if (p.schema['$ref']) {
250
+ // 展开各个字段属性
251
+ const name = p.schema['$ref'].replace('#/components/schemas/', '');
252
+ const schema = this.documentBuilder.getSchema(name);
253
+ delete p.schema['$ref'];
254
+ p.schema = JSON.parse(JSON.stringify(schema));
255
+ }
256
+ p.contentType = _1.BodyContentType.Multipart;
257
+ }
258
+ if (!p.content) {
259
+ p.content = {};
260
+ p.content[p.contentType || 'application/json'] = {
261
+ schema: p.schema,
262
+ };
263
+ }
264
+ if (!opts[webRouter.requestMethod].requestBody) {
265
+ const requestBody = {
266
+ required: true,
267
+ description: p.description || p.name,
268
+ content: p.content,
269
+ };
270
+ opts[webRouter.requestMethod].requestBody = requestBody;
271
+ }
272
+ else {
273
+ // 这里拼 schema properties 时肯定存在
274
+ Object.assign(opts[webRouter.requestMethod].requestBody.content[p.contentType]
275
+ .schema.properties, p.schema.properties);
276
+ }
277
+ delete p.contentType;
222
278
  delete p.content;
223
279
  // in body 不需要处理
224
280
  continue;
@@ -230,9 +286,9 @@ let SwaggerExplorer = class SwaggerExplorer {
230
286
  parameters.unshift(header);
231
287
  }
232
288
  opts[webRouter.requestMethod].parameters = parameters;
233
- opts[webRouter.requestMethod].responses = {};
234
289
  const responses = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_RESPONSE &&
235
290
  item.propertyName === webRouter.method);
291
+ const returnResponses = {};
236
292
  for (const r of responses) {
237
293
  const resp = r.metadata;
238
294
  const keys = Object.keys(resp);
@@ -240,7 +296,7 @@ let SwaggerExplorer = class SwaggerExplorer {
240
296
  // 这里是引用,赋值可以直接更改
241
297
  const tt = resp[k];
242
298
  if (tt.type) {
243
- if ((0, decorator_1.isClass)(tt.type)) {
299
+ if (decorator_1.Types.isClass(tt.type)) {
244
300
  this.parseClzz(tt.type);
245
301
  if (tt.isArray) {
246
302
  tt.content = {
@@ -279,7 +335,17 @@ let SwaggerExplorer = class SwaggerExplorer {
279
335
  delete tt.isArray;
280
336
  delete tt.format;
281
337
  }
282
- Object.assign(opts[webRouter.requestMethod].responses, resp);
338
+ Object.assign(returnResponses, resp);
339
+ }
340
+ if (Object.keys(returnResponses).length > 0) {
341
+ opts[webRouter.requestMethod].responses = returnResponses;
342
+ }
343
+ else {
344
+ opts[webRouter.requestMethod].responses = {
345
+ 200: {
346
+ description: 'OK',
347
+ },
348
+ };
283
349
  }
284
350
  paths[url] = opts;
285
351
  }
@@ -306,6 +372,9 @@ let SwaggerExplorer = class SwaggerExplorer {
306
372
  if (param.deprecated) {
307
373
  p.deprecated = param.deprecated;
308
374
  }
375
+ if (param.contentType) {
376
+ p.contentType = param.contentType;
377
+ }
309
378
  p.in = (_a = param === null || param === void 0 ? void 0 : param.in) !== null && _a !== void 0 ? _a : p.in;
310
379
  p.required = (_b = param === null || param === void 0 ? void 0 : param.required) !== null && _b !== void 0 ? _b : p.required;
311
380
  if (p.in === 'query') {
@@ -327,7 +396,7 @@ let SwaggerExplorer = class SwaggerExplorer {
327
396
  }
328
397
  else {
329
398
  if (param.type) {
330
- if ((0, decorator_1.isClass)(param.type)) {
399
+ if (decorator_1.Types.isClass(param.type)) {
331
400
  this.parseClzz(param.type);
332
401
  p.schema = {
333
402
  $ref: '#/components/schemas/' + param.type.name,
@@ -363,45 +432,65 @@ let SwaggerExplorer = class SwaggerExplorer {
363
432
  * @param clzz
364
433
  */
365
434
  parseClzz(clzz) {
435
+ if (this.documentBuilder.getSchema(clzz.name)) {
436
+ return;
437
+ }
366
438
  const props = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_PROPERTY, clzz);
439
+ const tt = {
440
+ type: 'object',
441
+ properties: {},
442
+ };
367
443
  if (props) {
368
- const tt = {
369
- type: 'object',
370
- properties: {},
371
- required: [],
372
- example: {},
373
- };
374
444
  Object.keys(props).forEach(key => {
375
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
376
- if ((_a = props[key].metadata) === null || _a === void 0 ? void 0 : _a.example) {
377
- tt.example[key] = (_b = props[key].metadata) === null || _b === void 0 ? void 0 : _b.example;
445
+ var _a, _b;
446
+ const metadata = props[key].metadata;
447
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.example) {
448
+ if (!tt.example) {
449
+ tt.example = {};
450
+ }
451
+ tt.example[key] = metadata === null || metadata === void 0 ? void 0 : metadata.example;
452
+ delete metadata.example;
378
453
  }
379
- if (((_c = props[key].metadata) === null || _c === void 0 ? void 0 : _c.required) !== false) {
454
+ if ((metadata === null || metadata === void 0 ? void 0 : metadata.required) !== false) {
455
+ if (!tt.required) {
456
+ tt.required = [];
457
+ }
380
458
  tt.required.push(key);
459
+ delete metadata.required;
381
460
  }
382
- if ((_d = props[key].metadata) === null || _d === void 0 ? void 0 : _d.enum) {
461
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.enum) {
383
462
  tt.properties[key] = {
384
- type: (_e = props[key].metadata) === null || _e === void 0 ? void 0 : _e.type,
385
- enum: (_f = props[key].metadata) === null || _f === void 0 ? void 0 : _f.enum,
386
- default: (_g = props[key].metadata) === null || _g === void 0 ? void 0 : _g.default,
463
+ type: metadata === null || metadata === void 0 ? void 0 : metadata.type,
464
+ enum: metadata === null || metadata === void 0 ? void 0 : metadata.enum,
465
+ default: metadata === null || metadata === void 0 ? void 0 : metadata.default,
387
466
  };
467
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.description) {
468
+ tt.properties[key].description = metadata === null || metadata === void 0 ? void 0 : metadata.description;
469
+ }
388
470
  return;
389
471
  }
390
- if ((_j = (_h = props[key].metadata) === null || _h === void 0 ? void 0 : _h.items) === null || _j === void 0 ? void 0 : _j.enum) {
472
+ if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _a === void 0 ? void 0 : _a.enum) {
391
473
  tt.properties[key] = {
392
- type: (_k = props[key].metadata) === null || _k === void 0 ? void 0 : _k.type,
393
- items: (_l = props[key].metadata) === null || _l === void 0 ? void 0 : _l.items,
394
- default: (_m = props[key].metadata) === null || _m === void 0 ? void 0 : _m.default,
474
+ type: metadata === null || metadata === void 0 ? void 0 : metadata.type,
475
+ items: metadata === null || metadata === void 0 ? void 0 : metadata.items,
476
+ default: metadata === null || metadata === void 0 ? void 0 : metadata.default,
395
477
  };
478
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.description) {
479
+ tt.properties[key].description = metadata === null || metadata === void 0 ? void 0 : metadata.description;
480
+ }
396
481
  return;
397
482
  }
398
- let currentType = (_o = props[key].metadata) === null || _o === void 0 ? void 0 : _o.type;
483
+ let isArray = false;
484
+ let currentType = metadata === null || metadata === void 0 ? void 0 : metadata.type;
485
+ metadata === null || metadata === void 0 ? true : delete metadata.type;
399
486
  if (currentType === 'array') {
400
- currentType = (_q = (_p = props[key].metadata) === null || _p === void 0 ? void 0 : _p.items) === null || _q === void 0 ? void 0 : _q.type;
487
+ isArray = true;
488
+ currentType = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _b === void 0 ? void 0 : _b.type;
489
+ delete metadata.items;
401
490
  }
402
- if ((0, decorator_1.isClass)(currentType)) {
491
+ if (decorator_1.Types.isClass(currentType)) {
403
492
  this.parseClzz(currentType);
404
- if (((_r = props[key].metadata) === null || _r === void 0 ? void 0 : _r.type) === 'array') {
493
+ if (isArray) {
405
494
  tt.properties[key] = {
406
495
  type: 'array',
407
496
  items: {
@@ -416,27 +505,28 @@ let SwaggerExplorer = class SwaggerExplorer {
416
505
  }
417
506
  }
418
507
  else {
419
- if (((_s = props[key].metadata) === null || _s === void 0 ? void 0 : _s.type) === 'array') {
508
+ if (isArray) {
420
509
  tt.properties[key] = {
421
510
  type: 'array',
422
511
  items: {
423
- type: (0, decorator_1.getPropertyType)(clzz.prototype, key).name,
424
- format: (_t = props[key].metadata) === null || _t === void 0 ? void 0 : _t.format,
512
+ type: convertSchemaType((currentType === null || currentType === void 0 ? void 0 : currentType.name) || currentType),
425
513
  },
426
514
  };
427
515
  }
428
516
  else {
429
517
  tt.properties[key] = {
430
518
  type: (0, decorator_1.getPropertyType)(clzz.prototype, key).name,
431
- format: (_u = props[key].metadata) === null || _u === void 0 ? void 0 : _u.format,
519
+ format: metadata === null || metadata === void 0 ? void 0 : metadata.format,
432
520
  };
521
+ delete metadata.format;
433
522
  }
434
523
  }
435
- });
436
- this.documentBuilder.addSchema({
437
- [clzz.name]: tt,
524
+ Object.assign(tt.properties[key], metadata);
438
525
  });
439
526
  }
527
+ this.documentBuilder.addSchema({
528
+ [clzz.name]: tt,
529
+ });
440
530
  }
441
531
  /**
442
532
  * 授权验证
@@ -545,6 +635,9 @@ function convertTypeToString(type) {
545
635
  case decorator_1.RouteParamTypes.PARAM:
546
636
  return 'path';
547
637
  case decorator_1.RouteParamTypes.BODY:
638
+ case decorator_1.RouteParamTypes.FIELDS:
639
+ case decorator_1.RouteParamTypes.FILESSTREAM:
640
+ case decorator_1.RouteParamTypes.FILESTREAM:
548
641
  return 'body';
549
642
  default:
550
643
  return 'header';
@@ -561,7 +654,7 @@ function convertSchemaType(value) {
561
654
  case 'String':
562
655
  return 'string';
563
656
  default:
564
- return 'object';
657
+ return value;
565
658
  }
566
659
  }
567
660
  //# sourceMappingURL=swaggerExplorer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swaggerExplorer.js","sourceRoot":"","sources":["../src/swaggerExplorer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAoB6B;AAE7B,2CAAyC;AACzC,uDAAoD;AAMpD,wBAAoC;AAIpC,IAAa,eAAe,GAA5B,MAAa,eAAe;IAA5B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KAAK,2BAAe,CAAC,MAAM,CAAC;QAC5B,KAAK,2BAAe,CAAC,WAAW,CAAC;QACjC,KAAK,2BAAe,CAAC,UAAU;YAC7B,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,QAAQ,CAAC;KACnB;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAK;IAC9B,QAAQ,KAAK,EAAE;QACb,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,KAAK,CAAC;KAChB;AACH,CAAC","sourcesContent":["import {\n Config,\n CONTROLLER_KEY,\n listModule,\n Provide,\n ControllerOption,\n getClassMetadata,\n getMethodParamTypes,\n Types,\n RouteParamTypes,\n RouterOption,\n WEB_ROUTER_KEY,\n WEB_ROUTER_PARAM_KEY,\n Init,\n Scope,\n ScopeEnum,\n INJECT_CUSTOM_PROPERTY,\n INJECT_CUSTOM_PARAM,\n INJECT_CUSTOM_METHOD,\n getPropertyType,\n} from '@midwayjs/decorator';\nimport { PathItemObject, Type } from './interfaces';\nimport { DECORATORS } from './constants';\nimport { DocumentBuilder } from './documentBuilder';\nimport {\n SwaggerOptions,\n AuthOptions,\n SecuritySchemeObject,\n} from './interfaces/';\nimport { BodyContentType } from '.';\n\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class SwaggerExplorer {\n @Config('swagger')\n private swaggerConfig: SwaggerOptions;\n\n private documentBuilder = new DocumentBuilder();\n\n @Init()\n async init() {\n this.documentBuilder.setTitle(this.swaggerConfig.title);\n this.documentBuilder.setVersion(this.swaggerConfig.version);\n this.documentBuilder.setDescription(this.swaggerConfig.description);\n if (\n this.swaggerConfig?.contact &&\n typeof this.swaggerConfig?.contact === 'object'\n ) {\n this.documentBuilder.setContact(\n this.swaggerConfig?.contact?.name,\n this.swaggerConfig?.contact?.url,\n this.swaggerConfig?.contact?.email\n );\n }\n if (\n this.swaggerConfig?.license &&\n typeof this.swaggerConfig?.license === 'object'\n ) {\n this.documentBuilder.setLicense(\n this.swaggerConfig?.license?.name,\n this.swaggerConfig?.license?.url\n );\n }\n if (this.swaggerConfig.basePath) {\n this.documentBuilder.setBasePath(this.swaggerConfig.basePath);\n }\n if (this.swaggerConfig.termsOfService) {\n this.documentBuilder.setTermsOfService(this.swaggerConfig.termsOfService);\n }\n if (\n this.swaggerConfig?.externalDocs &&\n typeof this.swaggerConfig?.externalDocs === 'object'\n ) {\n this.documentBuilder.setExternalDoc(\n this.swaggerConfig?.externalDocs?.description,\n this.swaggerConfig?.externalDocs?.url\n );\n }\n if (\n this.swaggerConfig?.servers &&\n Array.isArray(this.swaggerConfig?.servers)\n ) {\n for (const serv of this.swaggerConfig?.servers) {\n this.documentBuilder.addServer(serv?.url, serv?.description);\n }\n }\n if (this.swaggerConfig?.tags && Array.isArray(this.swaggerConfig?.tags)) {\n for (const t of this.swaggerConfig?.tags) {\n this.documentBuilder.addTag(t.name, t.description, t.externalDocs);\n }\n }\n // 设置 auth 类型\n if (Array.isArray(this.swaggerConfig?.auth)) {\n for (const a of this.swaggerConfig?.auth) {\n this.setAuth(a);\n }\n } else {\n this.setAuth(this.swaggerConfig?.auth);\n }\n }\n\n public scanApp() {\n const routes = listModule(CONTROLLER_KEY);\n\n for (const route of routes) {\n this.generatePath(route);\n }\n\n if (this.swaggerConfig?.tagSortable) {\n this.documentBuilder.sortTags();\n }\n }\n\n public getData() {\n return this.documentBuilder.build();\n }\n\n private generatePath(target: Type) {\n const metaForMethods: any[] =\n getClassMetadata(INJECT_CUSTOM_METHOD, target) || [];\n const exs = metaForMethods.filter(\n item => item.key === DECORATORS.API_EXCLUDE_CONTROLLER\n );\n if (exs[0]) {\n return;\n }\n\n const metaForParams: any[] =\n getClassMetadata(INJECT_CUSTOM_PARAM, target) || [];\n\n const controllerOption: ControllerOption = getClassMetadata(\n CONTROLLER_KEY,\n target\n );\n\n const prefix = controllerOption.prefix;\n const tags = metaForMethods.filter(\n item => item.key === DECORATORS.API_TAGS\n );\n let strTags: string[] = [];\n if (tags.length > 0) {\n for (const t of tags) {\n // 这里 metadata => string[]\n strTags = strTags.concat(t.metadata);\n this.documentBuilder.addTag(t.metadata);\n }\n } else {\n const tag = { name: '', description: '' };\n if (prefix !== '/') {\n tag.name =\n controllerOption?.routerOptions.tagName ||\n (/^\\//.test(prefix) ? prefix.split('/')[1] : prefix);\n tag.description =\n controllerOption?.routerOptions.description || tag.name;\n } else {\n tag.name = controllerOption?.routerOptions.tagName;\n tag.description =\n controllerOption?.routerOptions.description || tag.name;\n }\n if (tag.name) {\n strTags.push(tag.name);\n this.documentBuilder.addTag(tag.name, tag.description);\n }\n }\n\n // const globalMiddleware = controllerOption.routerOptions.middleware;\n // get router info\n const webRouterInfo: RouterOption[] = getClassMetadata(\n WEB_ROUTER_KEY,\n target\n );\n\n let header = null;\n const headers = metaForMethods.filter(\n item => item.key === DECORATORS.API_HEADERS\n );\n if (headers.length > 0) {\n header = headers[0].metadata;\n }\n\n const security = metaForMethods.filter(\n item => item.key === DECORATORS.API_SECURITY\n );\n\n const paths: Record<string, PathItemObject> = {};\n if (webRouterInfo && typeof webRouterInfo[Symbol.iterator] === 'function') {\n for (const webRouter of webRouterInfo) {\n let url = (prefix + webRouter.path).replace('//', '/');\n url = replaceUrl(url, parseParamsInPath(url));\n\n // 判断是否忽略当前路由\n const endpoints = metaForMethods.filter(\n item =>\n item.key === DECORATORS.API_EXCLUDE_ENDPOINT &&\n item.propertyName === webRouter.method\n );\n if (endpoints[0]) {\n continue;\n }\n\n this.generateRouteMethod(\n url,\n webRouter,\n paths,\n metaForMethods,\n metaForParams,\n header,\n target\n );\n\n // 这里赋值 tags\n if (paths[url][webRouter.requestMethod].tags.length === 0) {\n paths[url][webRouter.requestMethod].tags = strTags;\n }\n // extension => prefix 为 x-\n const exts = metaForMethods.filter(\n item =>\n item.key === DECORATORS.API_EXTENSION &&\n item.propertyName === webRouter.method\n );\n for (const e of exts) {\n if (e.metadata) {\n Object.assign(paths[url][webRouter.requestMethod], e.metadata);\n }\n }\n\n if (security.length > 0) {\n if (!paths[url][webRouter.requestMethod].security) {\n paths[url][webRouter.requestMethod].security = [];\n }\n\n for (const s of security) {\n if (!s.metadata) {\n continue;\n }\n paths[url][webRouter.requestMethod].security.push(s.metadata);\n }\n }\n }\n }\n\n this.documentBuilder.addPaths(paths);\n }\n /**\n * 构造 router 提取方法\n */\n private generateRouteMethod(\n url: string,\n webRouter: RouterOption,\n paths: Record<string, PathItemObject>,\n metaForMethods: any[],\n metaForParams: any[],\n header: any,\n target: Type\n ) {\n const operMeta = metaForMethods.filter(\n item =>\n item.key === DECORATORS.API_OPERATION &&\n item.propertyName === webRouter.method\n )[0];\n\n let opts: PathItemObject = paths[url];\n if (!opts) {\n opts = {};\n }\n const parameters = [];\n opts[webRouter.requestMethod] = {\n summary: operMeta?.metadata?.summary,\n description: operMeta?.metadata?.description,\n operationId: operMeta?.metadata?.operationId || webRouter.method,\n tags: operMeta?.metadata?.tags || [],\n };\n /**\n * [{\"key\":\"web:router_param\",\"parameterIndex\":1,\"propertyName\":\"create\",\"metadata\":{\"type\":2}},\n * {\"key\":\"web:router_param\",\"parameterIndex\":0,\"propertyName\":\"create\",\"metadata\":{\"type\":1,\"propertyData\":\"createCatDto\"}}]\n */\n const routerArgs = metaForParams[webRouter.method] || [];\n // WEB_ROUTER_PARAM_KEY\n let args: any[] = routerArgs.filter(\n item => item.key === WEB_ROUTER_PARAM_KEY\n );\n args = args.filter(item => (item as any).key === WEB_ROUTER_PARAM_KEY);\n const types = getMethodParamTypes(target, webRouter.method);\n const params = metaForMethods.filter(\n item =>\n item.key === DECORATORS.API_PARAMETERS &&\n item.propertyName === webRouter.method\n );\n\n for (const arg of args) {\n const currentType = types[arg.parameterIndex];\n const p: any = {\n name: arg?.metadata?.propertyData ?? '',\n in: convertTypeToString(arg.metadata?.type),\n required: false,\n };\n\n if (p.in === 'path') {\n p.required = true;\n\n if (url.indexOf('{' + p.name + '}') === -1) {\n continue;\n }\n }\n\n if (Types.isClass(currentType)) {\n this.parseClzz(currentType);\n\n p.schema = {\n $ref: '#/components/schemas/' + currentType.name,\n };\n } else {\n p.schema = {\n type: convertSchemaType(currentType?.name ?? currentType),\n };\n }\n\n this.parseFromParamsToP(\n params[params.length - 1 - arg.parameterIndex],\n p\n );\n\n if (p.in === 'body') {\n // 这里兼容一下 @File()、@Files()、@Fields() 装饰器\n if (arg.metadata?.type === RouteParamTypes.FILESSTREAM) {\n p.schema = {\n type: 'object',\n properties: {\n files: {\n type: 'array',\n items: {\n type: 'string',\n format: 'binary',\n },\n description: p.description,\n },\n },\n };\n p.contentType = BodyContentType.Multipart;\n }\n if (arg.metadata?.type === RouteParamTypes.FILESTREAM) {\n p.schema = {\n type: 'object',\n properties: {\n file: {\n type: 'string',\n format: 'binary',\n description: p.description,\n },\n },\n };\n p.contentType = BodyContentType.Multipart;\n }\n if (arg.metadata?.type === RouteParamTypes.FIELDS) {\n if (p.schema['$ref']) {\n // 展开各个字段属性\n const name = p.schema['$ref'].replace('#/components/schemas/', '');\n const schema = this.documentBuilder.getSchema(name);\n delete p.schema['$ref'];\n p.schema = JSON.parse(JSON.stringify(schema));\n }\n p.contentType = BodyContentType.Multipart;\n }\n\n if (!p.content) {\n p.content = {};\n p.content[p.contentType || 'application/json'] = {\n schema: p.schema,\n };\n }\n if (!opts[webRouter.requestMethod].requestBody) {\n const requestBody = {\n required: true,\n description: p.description || p.name,\n content: p.content,\n };\n opts[webRouter.requestMethod].requestBody = requestBody;\n } else {\n // 这里拼 schema properties 时肯定存在\n Object.assign(\n opts[webRouter.requestMethod].requestBody.content[p.contentType]\n .schema.properties,\n p.schema.properties\n );\n }\n\n delete p.contentType;\n delete p.content;\n // in body 不需要处理\n continue;\n }\n\n parameters.push(p);\n }\n // class header 需要使用 ApiHeader 装饰器\n if (header) {\n parameters.unshift(header);\n }\n\n opts[webRouter.requestMethod].parameters = parameters;\n\n const responses = metaForMethods.filter(\n item =>\n item.key === DECORATORS.API_RESPONSE &&\n item.propertyName === webRouter.method\n );\n const returnResponses = {};\n for (const r of responses) {\n const resp = r.metadata;\n const keys = Object.keys(resp);\n for (const k of keys) {\n // 这里是引用,赋值可以直接更改\n const tt = resp[k];\n if (tt.type) {\n if (Types.isClass(tt.type)) {\n this.parseClzz(tt.type);\n\n if (tt.isArray) {\n tt.content = {\n 'application/json': {\n schema: {\n type: 'array',\n items: {\n $ref: '#/components/schemas/' + tt.type.name,\n },\n },\n },\n };\n } else {\n tt.content = {\n 'application/json': {\n schema: {\n $ref: '#/components/schemas/' + tt.type.name,\n },\n },\n };\n }\n } else {\n tt.content = {\n 'text/plan': {\n schema: {\n type: convertSchemaType(tt.type),\n },\n },\n };\n }\n }\n delete tt.status;\n delete tt.type;\n delete tt.isArray;\n delete tt.format;\n }\n\n Object.assign(returnResponses, resp);\n }\n\n if (Object.keys(returnResponses).length > 0) {\n opts[webRouter.requestMethod].responses = returnResponses;\n } else {\n opts[webRouter.requestMethod].responses = {\n 200: {\n description: 'OK',\n },\n };\n }\n\n paths[url] = opts;\n }\n /**\n * 提取参数\n * @param params\n * @param p\n */\n private parseFromParamsToP(paramMeta: any, p: any) {\n if (paramMeta) {\n const param = paramMeta.metadata;\n\n if (param) {\n p.description = param.description;\n if (param.in === 'query') {\n p.allowEmptyValue = param.allowEmptyValue || false;\n }\n if (param.example) {\n p.example = param.example;\n }\n if (param.examples) {\n p.examples = param.examples;\n }\n if (param.deprecated) {\n p.deprecated = param.deprecated;\n }\n if (param.contentType) {\n p.contentType = param.contentType;\n }\n p.in = param?.in ?? p.in;\n p.required = param?.required ?? p.required;\n if (p.in === 'query') {\n p.style = 'form';\n } else if (p.in === 'path' || p.in === 'header') {\n p.style = 'simple';\n } else if (p.in === 'cookie') {\n p.style = 'form';\n }\n p.explode = p.style === 'form';\n // response content\n if (param?.content) {\n p.content = param?.content;\n }\n if (param.schema) {\n p.schema = param.schema;\n } else {\n if (param.type) {\n if (Types.isClass(param.type)) {\n this.parseClzz(param.type);\n\n p.schema = {\n $ref: '#/components/schemas/' + param.type.name,\n };\n }\n\n if (param.isArray) {\n p.schema = {\n type: 'array',\n items: {\n type: p?.schema?.$ref ?? convertSchemaType(param.type),\n format: param.format,\n },\n };\n } else {\n if (!p.schema) {\n p.schema = {\n type: param.type ? convertSchemaType(param.type) : p.type,\n format: param.format || p.format,\n };\n }\n }\n } else if (param.format) {\n p.schema.format = param.format;\n }\n }\n }\n }\n }\n /**\n * 解析类型的 ApiProperty\n * @param clzz\n */\n private parseClzz(clzz: Type) {\n if (this.documentBuilder.getSchema(clzz.name)) {\n return;\n }\n\n const props = getClassMetadata(INJECT_CUSTOM_PROPERTY, clzz);\n\n const tt: any = {\n type: 'object',\n properties: {},\n };\n\n if (props) {\n Object.keys(props).forEach(key => {\n const metadata = props[key].metadata;\n\n if (metadata?.example) {\n if (!tt.example) {\n tt.example = {};\n }\n tt.example[key] = metadata?.example;\n\n delete metadata.example;\n }\n if (metadata?.required !== false) {\n if (!tt.required) {\n tt.required = [];\n }\n tt.required.push(key);\n\n delete metadata.required;\n }\n if (metadata?.enum) {\n tt.properties[key] = {\n type: metadata?.type,\n enum: metadata?.enum,\n default: metadata?.default,\n };\n\n if (metadata?.description) {\n tt.properties[key].description = metadata?.description;\n }\n return;\n }\n if (metadata?.items?.enum) {\n tt.properties[key] = {\n type: metadata?.type,\n items: metadata?.items,\n default: metadata?.default,\n };\n\n if (metadata?.description) {\n tt.properties[key].description = metadata?.description;\n }\n return;\n }\n let isArray = false;\n let currentType = metadata?.type;\n\n delete metadata?.type;\n\n if (currentType === 'array') {\n isArray = true;\n currentType = metadata?.items?.type;\n\n delete metadata.items;\n }\n\n if (Types.isClass(currentType)) {\n this.parseClzz(currentType);\n\n if (isArray) {\n tt.properties[key] = {\n type: 'array',\n items: {\n $ref: '#components/schemas/' + currentType?.name,\n },\n };\n } else {\n tt.properties[key] = {\n $ref: '#components/schemas/' + currentType?.name,\n };\n }\n } else {\n if (isArray) {\n tt.properties[key] = {\n type: 'array',\n items: {\n type: convertSchemaType(currentType?.name || currentType),\n },\n };\n } else {\n tt.properties[key] = {\n type: getPropertyType(clzz.prototype, key).name,\n format: metadata?.format,\n };\n\n delete metadata.format;\n }\n }\n\n Object.assign(tt.properties[key], metadata);\n });\n }\n\n this.documentBuilder.addSchema({\n [clzz.name]: tt,\n });\n }\n /**\n * 授权验证\n * @param opts\n * @returns\n */\n private setAuth(opts: AuthOptions) {\n if (!opts) {\n return;\n }\n const authType = opts.authType;\n delete opts.authType;\n // TODO 加 security\n switch (authType) {\n case 'basic':\n {\n const name = opts.name;\n delete opts.name;\n this.documentBuilder.addBasicAuth(opts as SecuritySchemeObject, name);\n }\n break;\n case 'bearer':\n {\n const name = opts.name;\n delete opts.name;\n this.documentBuilder.addBearerAuth(\n opts as SecuritySchemeObject,\n name\n );\n }\n break;\n case 'cookie':\n {\n const cname = opts.cookieName;\n const secName = opts.securityName;\n delete opts.cookieName;\n delete opts.securityName;\n this.documentBuilder.addCookieAuth(\n cname,\n opts as SecuritySchemeObject,\n secName\n );\n }\n break;\n case 'oauth2':\n {\n const name = opts.name;\n delete opts.name;\n this.documentBuilder.addOAuth2(opts as SecuritySchemeObject, name);\n }\n break;\n case 'apikey':\n {\n const name = opts.name;\n delete opts.name;\n this.documentBuilder.addApiKey(opts as SecuritySchemeObject, name);\n }\n break;\n case 'custom':\n {\n this.documentBuilder.addSecurity(\n opts?.name,\n opts as SecuritySchemeObject\n );\n }\n break;\n }\n }\n}\n/**\n * 解释路由上的参数\n * @param url\n */\nfunction parseParamsInPath(url: string) {\n const names: string[] = [];\n url.split('/').forEach(item => {\n if (item.startsWith(':')) {\n const paramName = item.substr(1);\n names.push(paramName);\n }\n });\n return names;\n}\n/**\n * 替换成 openapi 的url\n * @param url\n * @param names\n */\nfunction replaceUrl(url: string, names: string[]) {\n names.forEach(n => {\n url = url.replace(`:${n}`, `{${n}}`);\n });\n return url;\n}\n\nfunction convertTypeToString(type: RouteParamTypes) {\n switch (type) {\n case RouteParamTypes.HEADERS:\n return 'header';\n case RouteParamTypes.QUERY:\n return 'query';\n case RouteParamTypes.PARAM:\n return 'path';\n case RouteParamTypes.BODY:\n case RouteParamTypes.FIELDS:\n case RouteParamTypes.FILESSTREAM:\n case RouteParamTypes.FILESTREAM:\n return 'body';\n default:\n return 'header';\n }\n}\n\nfunction convertSchemaType(value) {\n switch (value) {\n case 'Object':\n return 'object';\n case 'Boolean':\n return 'boolean';\n case 'Number':\n return 'number';\n case 'String':\n return 'string';\n default:\n return value;\n }\n}\n"]}
@@ -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'),
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swaggerMiddleware.js","sourceRoot":"","sources":["../src/swaggerMiddleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,yCAA6C;AAC7C,mDAQ6B;AAC7B,2BAAkC;AAClC,+BAAqC;AACrC,uDAAoD;AAIpD,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAY5B,KAAK,CAAC,IAAI;QACR,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAA,kBAAW,EAAC,iBAAiB,CAAC,CAAC;QAC7D,IAAI,iBAAiB,EAAE;YACrB,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;SAC/C;IACH,CAAC;IAED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AAC,WAAW,kBAAkB,IAAI,CAAC,aAAa,CAAC,WAAW,eAAe,CACxH,CAAC;iBACH;gBACD,MAAM,GAAG,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;gBAC9B,IAAI,GAAG,KAAK,KAAK,EAAE;oBAChB,GAAW,CAAC,GAAG,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC;iBAC5D;qBAAM,IAAI,GAAG,KAAK,MAAM,EAAE;oBACxB,GAAW,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;iBACtD;qBAAM,IAAI,GAAG,KAAK,MAAM,EAAE;oBACxB,GAAW,CAAC,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;iBAC9C;qBAAM,IAAI,GAAG,KAAK,MAAM,EAAE;oBACxB,GAAW,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;iBAC/C;gBAEA,GAAW,CAAC,IAAI,GAAG,OAAO,CAAC;YAC9B,CAAC,CAAC;SACH;IACH,CAAC;IAED,MAAM,CAAC,OAAO;QACZ,OAAO,SAAS,CAAC;IACnB,CAAC;CACF,CAAA;AAxGC;IADC,IAAA,kBAAM,EAAC,SAAS,CAAC;;wDACS;AAK3B;IADC,IAAA,kBAAM,GAAE;8BACgB,iCAAe;0DAAC;AAGzC;IADC,IAAA,gBAAI,GAAE;;;;6CAMN;AAjBU,iBAAiB;IAF7B,IAAA,mBAAO,GAAE;IACT,IAAA,iBAAK,EAAC,qBAAS,CAAC,SAAS,CAAC;GACd,iBAAiB,CA4G7B;AA5GY,8CAAiB","sourcesContent":["import type {\n IMiddleware,\n IMidwayApplication,\n IMidwayContext,\n NextFunction,\n} from '@midwayjs/core';\nimport { safeRequire } from '@midwayjs/core';\nimport {\n Config,\n Init,\n Inject,\n Provide,\n Scope,\n ScopeEnum,\n MidwayFrameworkType,\n} from '@midwayjs/decorator';\nimport { readFileSync } from 'fs';\nimport { join, extname } from 'path';\nimport { SwaggerExplorer } from './swaggerExplorer';\n\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class SwaggerMiddleware\n implements IMiddleware<IMidwayContext, NextFunction, unknown>\n{\n @Config('swagger')\n private swaggerConfig: any;\n\n private swaggerUiAssetPath: string;\n\n @Inject()\n private swaggerExplorer: SwaggerExplorer;\n\n @Init()\n async init() {\n const { getAbsoluteFSPath } = safeRequire('swagger-ui-dist');\n if (getAbsoluteFSPath) {\n this.swaggerUiAssetPath = getAbsoluteFSPath();\n }\n }\n\n resolve(app: IMidwayApplication) {\n if (app.getFrameworkType() === MidwayFrameworkType.WEB_EXPRESS) {\n return async (req: any, res: any, next: NextFunction) => {\n const pathname = req.path;\n if (\n !this.swaggerUiAssetPath ||\n pathname.indexOf(this.swaggerConfig.swaggerPath) === -1\n ) {\n return next();\n }\n const arr = pathname.split('/');\n let lastName = arr.pop();\n if (lastName === 'index.json') {\n res.send(this.swaggerExplorer.getData());\n return;\n }\n if (!lastName) {\n lastName = 'index.html';\n }\n\n let content = readFileSync(join(this.swaggerUiAssetPath, lastName), {\n encoding: 'utf-8',\n });\n if (lastName === 'index.html') {\n content = content.replace(\n '\"https://petstore.swagger.io/v2/swagger.json\"',\n `location.href.replace('${this.swaggerConfig.swaggerPath}/index.html', '${this.swaggerConfig.swaggerPath}/index.json')`\n );\n }\n const ext = extname(lastName);\n if (ext === '.js') {\n res.type('application/javascript');\n } else if (ext === '.map') {\n res.type('application/json');\n } else if (ext === '.css') {\n res.type('text/css');\n } else if (ext === '.png') {\n res.type('image/png');\n }\n\n res.send(content);\n };\n } else {\n return async (ctx: IMidwayContext, next: NextFunction) => {\n const pathname = (ctx as any).path;\n if (\n !this.swaggerUiAssetPath ||\n pathname.indexOf(this.swaggerConfig.swaggerPath) === -1\n ) {\n return next();\n }\n const arr = pathname.split('/');\n let lastName = arr.pop();\n if (lastName === 'index.json') {\n (ctx as any).body = this.swaggerExplorer.getData();\n return;\n }\n if (!lastName) {\n lastName = 'index.html';\n }\n\n let content = readFileSync(join(this.swaggerUiAssetPath, lastName), {\n encoding: 'utf-8',\n });\n if (lastName === 'index.html') {\n content = content.replace(\n '\"https://petstore.swagger.io/v2/swagger.json\"',\n `location.href.replace('${this.swaggerConfig.swaggerPath}/index.html', '${this.swaggerConfig.swaggerPath}/index.json')`\n );\n }\n const ext = extname(lastName);\n if (ext === '.js') {\n (ctx as any).set('Content-Type', 'application/javascript');\n } else if (ext === '.map') {\n (ctx as any).set('Content-Type', 'application/json');\n } else if (ext === '.css') {\n (ctx as any).set('Content-Type', 'text/css');\n } else if (ext === '.png') {\n (ctx as any).set('Content-Type', 'image/png');\n }\n\n (ctx as any).body = content;\n };\n }\n }\n\n static getName() {\n return 'swagger';\n }\n}\n"]}
package/index.d.ts CHANGED
@@ -3,6 +3,6 @@ export * from './dist/index';
3
3
 
4
4
  declare module '@midwayjs/core/dist/interface' {
5
5
  interface MidwayConfig {
6
- swagger: Partial<SwaggerOptions>;
6
+ swagger?: Partial<SwaggerOptions>;
7
7
  }
8
8
  }
package/package.json CHANGED
@@ -1,31 +1,32 @@
1
1
  {
2
2
  "name": "@midwayjs/swagger",
3
- "version": "3.0.0-beta.9",
3
+ "version": "3.0.3",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "files": [
7
7
  "dist/**/*.js",
8
8
  "dist/**/*.d.ts",
9
- "index.d.ts"
9
+ "index.d.ts",
10
+ "dist/**/*.js.map"
10
11
  ],
11
- "dependencies": { },
12
12
  "devDependencies": {
13
- "swagger-ui-dist": "^3.34.0",
14
- "@midwayjs/core": "^3.0.0-beta.9",
15
- "@midwayjs/decorator": "^3.0.0-beta.9",
16
- "@midwayjs/koa": "^3.0.0-beta.9",
17
- "@midwayjs/mock": "^3.0.0-beta.9"
13
+ "@midwayjs/core": "^3.0.2",
14
+ "@midwayjs/decorator": "^3.0.2",
15
+ "@midwayjs/koa": "^3.0.3",
16
+ "@midwayjs/mock": "^3.0.2",
17
+ "swagger-ui-dist": "4.4.0"
18
18
  },
19
19
  "author": "Kurten Chan <chinkurten@gmail.com>",
20
20
  "license": "MIT",
21
21
  "scripts": {
22
22
  "build": "tsc",
23
23
  "jest": "node --require=ts-node/register ../../node_modules/jest/bin/jest.js",
24
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest",
25
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --coverage --forceExit"
24
+ "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
25
+ "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
29
29
  "url": "https://github.com/midwayjs/midway.git"
30
- }
30
+ },
31
+ "gitHead": "43a5971b284aa918d22d191236c5664b011f8d87"
31
32
  }