@tsed/swagger 6.105.4 → 6.107.1

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 (64) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/cjs/SwaggerModule.js +4 -4
  3. package/lib/cjs/SwaggerModule.js.map +1 -1
  4. package/lib/cjs/index.js +12 -2
  5. package/lib/cjs/index.js.map +1 -1
  6. package/lib/cjs/interfaces/SwaggerSettings.js.map +1 -1
  7. package/lib/cjs/interfaces/interfaces.js +3 -0
  8. package/lib/cjs/interfaces/interfaces.js.map +1 -0
  9. package/lib/cjs/services/SwaggerService.js +14 -53
  10. package/lib/cjs/services/SwaggerService.js.map +1 -1
  11. package/lib/cjs/utils/includeRoute.js +2 -2
  12. package/lib/cjs/utils/includeRoute.js.map +1 -1
  13. package/lib/esm/SwaggerModule.js +4 -4
  14. package/lib/esm/SwaggerModule.js.map +1 -1
  15. package/lib/esm/index.js +12 -2
  16. package/lib/esm/index.js.map +1 -1
  17. package/lib/esm/interfaces/SwaggerSettings.js.map +1 -1
  18. package/lib/esm/interfaces/interfaces.js +2 -0
  19. package/lib/esm/interfaces/interfaces.js.map +1 -0
  20. package/lib/esm/services/SwaggerService.js +15 -54
  21. package/lib/esm/services/SwaggerService.js.map +1 -1
  22. package/lib/esm/utils/includeRoute.js +1 -1
  23. package/lib/esm/utils/includeRoute.js.map +1 -1
  24. package/lib/types/SwaggerModule.d.ts +1 -1
  25. package/lib/types/index.d.ts +12 -2
  26. package/lib/types/interfaces/SwaggerSettings.d.ts +0 -3
  27. package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +0 -1
  28. package/lib/types/services/SwaggerService.d.ts +3 -14
  29. package/lib/types/utils/includeRoute.d.ts +1 -1
  30. package/package.json +18 -15
  31. package/lib/cjs/interfaces/index.js +0 -5
  32. package/lib/cjs/interfaces/index.js.map +0 -1
  33. package/lib/cjs/utils/getSpecType.js +0 -21
  34. package/lib/cjs/utils/getSpecType.js.map +0 -1
  35. package/lib/cjs/utils/index.js +0 -11
  36. package/lib/cjs/utils/index.js.map +0 -1
  37. package/lib/cjs/utils/mapOpenSpec.js +0 -40
  38. package/lib/cjs/utils/mapOpenSpec.js.map +0 -1
  39. package/lib/cjs/utils/mapOpenSpec2.js +0 -35
  40. package/lib/cjs/utils/mapOpenSpec2.js.map +0 -1
  41. package/lib/cjs/utils/mapOpenSpec3.js +0 -26
  42. package/lib/cjs/utils/mapOpenSpec3.js.map +0 -1
  43. package/lib/cjs/utils/mapOpenSpecInfo.js +0 -21
  44. package/lib/cjs/utils/mapOpenSpecInfo.js.map +0 -1
  45. package/lib/esm/interfaces/index.js +0 -2
  46. package/lib/esm/interfaces/index.js.map +0 -1
  47. package/lib/esm/utils/getSpecType.js +0 -16
  48. package/lib/esm/utils/getSpecType.js.map +0 -1
  49. package/lib/esm/utils/index.js +0 -8
  50. package/lib/esm/utils/index.js.map +0 -1
  51. package/lib/esm/utils/mapOpenSpec.js +0 -36
  52. package/lib/esm/utils/mapOpenSpec.js.map +0 -1
  53. package/lib/esm/utils/mapOpenSpec2.js +0 -31
  54. package/lib/esm/utils/mapOpenSpec2.js.map +0 -1
  55. package/lib/esm/utils/mapOpenSpec3.js +0 -22
  56. package/lib/esm/utils/mapOpenSpec3.js.map +0 -1
  57. package/lib/esm/utils/mapOpenSpecInfo.js +0 -17
  58. package/lib/esm/utils/mapOpenSpecInfo.js.map +0 -1
  59. package/lib/types/utils/getSpecType.d.ts +0 -12
  60. package/lib/types/utils/index.d.ts +0 -7
  61. package/lib/types/utils/mapOpenSpec.d.ts +0 -10
  62. package/lib/types/utils/mapOpenSpec2.d.ts +0 -10
  63. package/lib/types/utils/mapOpenSpec3.d.ts +0 -8
  64. package/lib/types/utils/mapOpenSpecInfo.d.ts +0 -6
package/jest.config.js ADDED
@@ -0,0 +1,14 @@
1
+ // For a detailed explanation regarding each configuration property, visit:
2
+ // https://jestjs.io/docs/en/configuration.html
3
+
4
+ module.exports = {
5
+ ...require("@tsed/jest-config")(__dirname, "swagger"),
6
+ coverageThreshold: {
7
+ global: {
8
+ statements: 98.28,
9
+ branches: 80,
10
+ functions: 96.67,
11
+ lines: 98.2
12
+ }
13
+ }
14
+ };
@@ -59,10 +59,10 @@ let SwaggerModule = class SwaggerModule {
59
59
  this.generateSpecFiles();
60
60
  }
61
61
  generateSpecFiles() {
62
- return Promise.all(this.settings.map((conf) => {
62
+ return Promise.all(this.settings.map(async (conf) => {
63
63
  const { outFile } = conf;
64
64
  if (this.env === core_1.Env.PROD || outFile) {
65
- const spec = this.swaggerService.getOpenAPISpec(conf);
65
+ const spec = await this.swaggerService.getOpenAPISpec(conf);
66
66
  if (outFile) {
67
67
  return fs_1.default.writeFile(outFile, JSON.stringify(spec, null, 2), { encoding: "utf8" }, () => { });
68
68
  }
@@ -102,8 +102,8 @@ let SwaggerModule = class SwaggerModule {
102
102
  return router;
103
103
  }
104
104
  middlewareSwaggerJson(conf) {
105
- return (ctx) => {
106
- ctx.response.status(200).body(this.swaggerService.getOpenAPISpec(conf));
105
+ return async (ctx) => {
106
+ ctx.response.status(200).body(await this.swaggerService.getOpenAPISpec(conf));
107
107
  };
108
108
  }
109
109
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SwaggerModule.js","sourceRoot":"","sources":["../../src/SwaggerModule.ts"],"names":[],"mappings":";;;;AAAA,yCAasB;AACtB,yDAAoB;AACpB,+BAA0B;AAE1B,+DAA0D;AAC1D,mEAA8D;AAC9D,6DAAwD;AACxD,yEAAoE;AACpE,8DAAyD;AACzD,qCAA+B;AAC/B,qDAA6C;AAE7C,MAAM,aAAa,GAAG,IAAA,8BAAY,GAAE,CAAC;AAErC;;GAEG;AAEH,IAAa,aAAa,GAA1B,MAAa,aAAa;IAA1B;QAgBU,WAAM,GAAG,KAAK,CAAC;IAiHzB,CAAC;IA/GC,IAAI,QAAQ;QACV,OAAQ,EAAwB,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,C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C;YAC3E,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAC,IAAI,EAAE,aAAa,EAAC,CAAC,CAAC;SAC5C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,qBAAqB,CAAC,IAAqB;QACjD,OAAO,CAAC,GAAoB,EAAE,EAAE;YAC9B,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1E,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AA/HC;IADC,IAAA,eAAM,GAAE;2CACC,wBAAe;+CAAC;AAG1B;IADC,IAAA,eAAM,GAAE;2CACJ,4BAAmB;0CAAC;AAGzB;IADC,IAAA,sBAAa,GAAE;;oDACa;AAG7B;IADC,IAAA,eAAM,GAAE;2CACO,+BAAc;qDAAC;AAG/B;IADC,IAAA,iBAAQ,EAAC,KAAK,CAAC;;0CACP;AAdE,aAAa;IADzB,IAAA,eAAM,GAAE;GACI,aAAa,CAiIzB;AAjIY,sCAAa","sourcesContent":["import {\n OnRoutesInit,\n Configuration,\n Constant,\n Inject,\n InjectorService,\n Module,\n normalizePath,\n OnReady,\n PlatformApplication,\n PlatformContext,\n PlatformRouter,\n useCtxHandler\n} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {join} from \"path\";\nimport {SwaggerSettings} from \"./interfaces\";\nimport {cssMiddleware} from \"./middlewares/cssMiddleware\";\nimport {indexMiddleware} from \"./middlewares/indexMiddleware\";\nimport {jsMiddleware} from \"./middlewares/jsMiddleware\";\nimport {redirectMiddleware} from \"./middlewares/redirectMiddleware\";\nimport {SwaggerService} from \"./services/SwaggerService\";\nimport {Env} from \"@tsed/core\";\nimport {absolutePath} from \"swagger-ui-dist\";\n\nconst swaggerUiPath = absolutePath();\n\n/**\n * @ignore\n */\n@Module()\nexport class SwaggerModule implements OnRoutesInit, OnReady {\n @Inject()\n injector: InjectorService;\n\n @Inject()\n app: PlatformApplication;\n\n @Configuration()\n configuration: Configuration;\n\n @Inject()\n swaggerService: SwaggerService;\n\n @Constant(\"env\")\n env: Env;\n\n private loaded = false;\n\n get settings() {\n return ([] as SwaggerSettings[]).concat(this.configuration.get<SwaggerSettings[]>(\"swagger\")).filter((o) => !!o);\n }\n\n /**\n *\n */\n $onRoutesInit() {\n if (this.loaded) {\n return;\n }\n\n const urls: any[] = this.getUrls();\n\n this.settings.forEach((conf: SwaggerSettings) => {\n const {path = \"/\"} = conf;\n\n this.app.get(path, useCtxHandler(redirectMiddleware(path)));\n this.app.use(path, this.createRouter(conf, urls));\n });\n\n this.loaded = true;\n }\n\n $onReady() {\n // istanbul ignore next\n if (this.configuration.getBestHost) {\n const host = this.configuration.getBestHost();\n const url = host.toString();\n\n const displayLog = (conf: SwaggerSettings) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, specVersion} = conf;\n\n this.injector.logger.info(`[${doc || \"default\"}] Swagger JSON is available on ${url}${normalizePath(path, fileName)}`);\n this.injector.logger.info(`[${doc || \"default\"}] Swagger UI is available on ${url}${path}/`);\n // istanbul ignore next\n if (specVersion === \"2.0\") {\n this.injector.logger.warn(`[${doc || \"default\"}] Swagger 2.0 is now deprecated. Please migrate to OpenSpec 3`);\n }\n };\n\n this.settings.forEach((conf) => {\n displayLog(conf);\n });\n }\n\n this.generateSpecFiles();\n }\n\n generateSpecFiles() {\n return Promise.all(\n this.settings.map((conf) => {\n const {outFile} = conf;\n\n if (this.env === Env.PROD || outFile) {\n const spec = this.swaggerService.getOpenAPISpec(conf);\n\n if (outFile) {\n return Fs.writeFile(outFile, JSON.stringify(spec, null, 2), {encoding: \"utf8\"}, () => {});\n }\n }\n })\n );\n }\n\n private getUrls() {\n return this.settings.reduce((acc: any[], conf) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, hidden} = conf;\n\n if (!hidden) {\n acc.push({url: normalizePath(path, fileName), name: doc || path});\n }\n\n return acc;\n }, []);\n }\n\n /**\n *\n * @param conf\n * @param urls\n */\n private createRouter(conf: SwaggerSettings, urls: string[]) {\n const {disableSpec = false, fileName = \"swagger.json\", cssPath, jsPath, viewPath = join(__dirname, \"../views/index.ejs\")} = conf;\n const router = PlatformRouter.create(this.injector);\n\n if (!disableSpec) {\n router.get(normalizePath(\"/\", fileName), useCtxHandler(this.middlewareSwaggerJson(conf)));\n }\n\n if (viewPath) {\n if (cssPath) {\n router.get(\"/main.css\", useCtxHandler(cssMiddleware(cssPath)));\n }\n\n if (jsPath) {\n router.get(\"/main.js\", useCtxHandler(jsMiddleware(jsPath)));\n }\n\n router.get(\"/\", useCtxHandler(indexMiddleware(viewPath, {urls, ...conf})));\n router.statics(\"/\", {root: swaggerUiPath});\n }\n\n return router;\n }\n\n private middlewareSwaggerJson(conf: SwaggerSettings) {\n return (ctx: PlatformContext) => {\n ctx.response.status(200).body(this.swaggerService.getOpenAPISpec(conf));\n };\n }\n}\n"]}
1
+ {"version":3,"file":"SwaggerModule.js","sourceRoot":"","sources":["../../src/SwaggerModule.ts"],"names":[],"mappings":";;;;AAAA,yCAasB;AACtB,yDAAoB;AACpB,+BAA0B;AAE1B,+DAA0D;AAC1D,mEAA8D;AAC9D,6DAAwD;AACxD,yEAAoE;AACpE,8DAAyD;AACzD,qCAA+B;AAC/B,qDAA6C;AAE7C,MAAM,aAAa,GAAG,IAAA,8BAAY,GAAE,CAAC;AAErC;;GAEG;AAEH,IAAa,aAAa,GAA1B,MAAa,aAAa;IAA1B;QAgBU,WAAM,GAAG,KAAK,CAAC;IAiHzB,CAAC;IA/GC,IAAI,QAAQ;QACV,OAAQ,EAAwB,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAoB,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnH,CAAC;IAED;;OAEG;IACH,aAAa;QACX,IAAI,IAAI,CAAC,MAAM,EAAE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QACjD,OAAO,KAAK,EAAE,GAAoB,EAAE,EAAE;YACpC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAChF,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AA/HC;IADC,IAAA,eAAM,GAAE;2CACC,wBAAe;+CAAC;AAG1B;IADC,IAAA,eAAM,GAAE;2CACJ,4BAAmB;0CAAC;AAGzB;IADC,IAAA,sBAAa,GAAE;;oDACa;AAG7B;IADC,IAAA,eAAM,GAAE;2CACO,+BAAc;qDAAC;AAG/B;IADC,IAAA,iBAAQ,EAAC,KAAK,CAAC;;0CACP;AAdE,aAAa;IADzB,IAAA,eAAM,GAAE;GACI,aAAa,CAiIzB;AAjIY,sCAAa","sourcesContent":["import {\n OnRoutesInit,\n Configuration,\n Constant,\n Inject,\n InjectorService,\n Module,\n normalizePath,\n OnReady,\n PlatformApplication,\n PlatformContext,\n PlatformRouter,\n useCtxHandler\n} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {join} from \"path\";\nimport {SwaggerSettings} from \"./interfaces/SwaggerSettings\";\nimport {cssMiddleware} from \"./middlewares/cssMiddleware\";\nimport {indexMiddleware} from \"./middlewares/indexMiddleware\";\nimport {jsMiddleware} from \"./middlewares/jsMiddleware\";\nimport {redirectMiddleware} from \"./middlewares/redirectMiddleware\";\nimport {SwaggerService} from \"./services/SwaggerService\";\nimport {Env} from \"@tsed/core\";\nimport {absolutePath} from \"swagger-ui-dist\";\n\nconst swaggerUiPath = absolutePath();\n\n/**\n * @ignore\n */\n@Module()\nexport class SwaggerModule implements OnRoutesInit, OnReady {\n @Inject()\n injector: InjectorService;\n\n @Inject()\n app: PlatformApplication;\n\n @Configuration()\n configuration: Configuration;\n\n @Inject()\n swaggerService: SwaggerService;\n\n @Constant(\"env\")\n env: Env;\n\n private loaded = false;\n\n get settings() {\n return ([] as SwaggerSettings[]).concat(this.configuration.get<SwaggerSettings[]>(\"swagger\")).filter((o) => !!o);\n }\n\n /**\n *\n */\n $onRoutesInit() {\n if (this.loaded) {\n return;\n }\n\n const urls: any[] = this.getUrls();\n\n this.settings.forEach((conf: SwaggerSettings) => {\n const {path = \"/\"} = conf;\n\n this.app.get(path, useCtxHandler(redirectMiddleware(path)));\n this.app.use(path, this.createRouter(conf, urls));\n });\n\n this.loaded = true;\n }\n\n $onReady() {\n // istanbul ignore next\n if (this.configuration.getBestHost) {\n const host = this.configuration.getBestHost();\n const url = host.toString();\n\n const displayLog = (conf: SwaggerSettings) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, specVersion} = conf;\n\n this.injector.logger.info(`[${doc || \"default\"}] Swagger JSON is available on ${url}${normalizePath(path, fileName)}`);\n this.injector.logger.info(`[${doc || \"default\"}] Swagger UI is available on ${url}${path}/`);\n // istanbul ignore next\n if (specVersion === \"2.0\") {\n this.injector.logger.warn(`[${doc || \"default\"}] Swagger 2.0 is now deprecated. Please migrate to OpenSpec 3`);\n }\n };\n\n this.settings.forEach((conf) => {\n displayLog(conf);\n });\n }\n\n this.generateSpecFiles();\n }\n\n generateSpecFiles() {\n return Promise.all(\n this.settings.map(async (conf) => {\n const {outFile} = conf;\n\n if (this.env === Env.PROD || outFile) {\n const spec = await this.swaggerService.getOpenAPISpec(conf);\n\n if (outFile) {\n return Fs.writeFile(outFile, JSON.stringify(spec, null, 2), {encoding: \"utf8\"}, () => {});\n }\n }\n })\n );\n }\n\n private getUrls() {\n return this.settings.reduce((acc: any[], conf) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, hidden} = conf;\n\n if (!hidden) {\n acc.push({url: normalizePath(path, fileName), name: doc || path});\n }\n\n return acc;\n }, []);\n }\n\n /**\n *\n * @param conf\n * @param urls\n */\n private createRouter(conf: SwaggerSettings, urls: string[]) {\n const {disableSpec = false, fileName = \"swagger.json\", cssPath, jsPath, viewPath = join(__dirname, \"../views/index.ejs\")} = conf;\n const router = PlatformRouter.create(this.injector);\n\n if (!disableSpec) {\n router.get(normalizePath(\"/\", fileName), useCtxHandler(this.middlewareSwaggerJson(conf)));\n }\n\n if (viewPath) {\n if (cssPath) {\n router.get(\"/main.css\", useCtxHandler(cssMiddleware(cssPath)));\n }\n\n if (jsPath) {\n router.get(\"/main.js\", useCtxHandler(jsMiddleware(jsPath)));\n }\n\n router.get(\"/\", useCtxHandler(indexMiddleware(viewPath, {urls, ...conf})));\n router.statics(\"/\", {root: swaggerUiPath});\n }\n\n return router;\n }\n\n private middlewareSwaggerJson(conf: SwaggerSettings) {\n return async (ctx: PlatformContext) => {\n ctx.response.status(200).body(await this.swaggerService.getOpenAPISpec(conf));\n };\n }\n}\n"]}
package/lib/cjs/index.js CHANGED
@@ -1,9 +1,19 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./services/SwaggerService"), exports);
5
7
  (0, tslib_1.__exportStar)(require("./SwaggerModule"), exports);
6
- (0, tslib_1.__exportStar)(require("./interfaces"), exports);
7
8
  (0, tslib_1.__exportStar)(require("./decorators/docs"), exports);
8
9
  (0, tslib_1.__exportStar)(require("./decorators/hidden"), exports);
10
+ (0, tslib_1.__exportStar)(require("./interfaces/SwaggerSettings"), exports);
11
+ (0, tslib_1.__exportStar)(require("./interfaces/interfaces"), exports);
12
+ (0, tslib_1.__exportStar)(require("./middlewares/cssMiddleware"), exports);
13
+ (0, tslib_1.__exportStar)(require("./middlewares/indexMiddleware"), exports);
14
+ (0, tslib_1.__exportStar)(require("./middlewares/jsMiddleware"), exports);
15
+ (0, tslib_1.__exportStar)(require("./middlewares/redirectMiddleware"), exports);
16
+ (0, tslib_1.__exportStar)(require("./services/SwaggerService"), exports);
17
+ (0, tslib_1.__exportStar)(require("./utils/includeRoute"), exports);
18
+ (0, tslib_1.__exportStar)(require("./utils/matchPath"), exports);
9
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yEAA0C;AAC1C,+DAAgC;AAChC,4DAA6B;AAC7B,iEAAkC;AAClC,mEAAoC","sourcesContent":["export * from \"./services/SwaggerService\";\nexport * from \"./SwaggerModule\";\nexport * from \"./interfaces\";\nexport * from \"./decorators/docs\";\nexport * from \"./decorators/hidden\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+DAAgC;AAChC,iEAAkC;AAClC,mEAAoC;AACpC,4EAA6C;AAC7C,uEAAwC;AACxC,2EAA4C;AAC5C,6EAA8C;AAC9C,0EAA2C;AAC3C,gFAAiD;AACjD,yEAA0C;AAC1C,oEAAqC;AACrC,iEAAkC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./SwaggerModule\";\nexport * from \"./decorators/docs\";\nexport * from \"./decorators/hidden\";\nexport * from \"./interfaces/SwaggerSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/cssMiddleware\";\nexport * from \"./middlewares/indexMiddleware\";\nexport * from \"./middlewares/jsMiddleware\";\nexport * from \"./middlewares/redirectMiddleware\";\nexport * from \"./services/SwaggerService\";\nexport * from \"./utils/includeRoute\";\nexport * from \"./utils/matchPath\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SwaggerSettings.js","sourceRoot":"","sources":["../../../src/interfaces/SwaggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {OpenSpec2, OpenSpec3, OpenSpecVersions, OS2Versions, OS3Versions} from \"@tsed/openspec\";\n\nexport interface SwaggerUIOptions {\n configUrl?: string;\n url?: string;\n urls?: {url: string; name: string; primaryName?: string}[];\n layout?: string;\n validatorUrl?: string;\n oauth?: any;\n authorize?: any;\n\n [key: string]: any;\n}\n\nexport interface SwaggerSettingsBase {\n /**\n * The url subpath to access to the documentation.\n */\n path: string;\n /**\n * Specify the spec version you want to generate.\n */\n specVersion?: OpenSpecVersions;\n /**\n * Swagger file name. By default swagger.json\n */\n fileName?: string;\n /**\n * Hidden documentation. Use this to hide documentation link in the dropdown.\n */\n hidden?: string;\n /**\n * The documentation key used by `@Docs` decorator to create several swagger documentations.\n */\n doc?: string;\n /**\n * The path to the CSS file.\n */\n cssPath?: string;\n /**\n * The path to the JS file.\n */\n jsPath?: string;\n /**\n * The path to the ejs file to create html page.\n */\n viewPath?: string | false;\n /**\n * SwaggerUI options. See (https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md)\n */\n options?: SwaggerUIOptions;\n /**\n * Display the search field in the navbar.\n */\n showExplorer?: boolean;\n /**\n * Load the base spec documentation from the specified path.\n */\n specPath?: string;\n /**\n * Write the `swagger.json` spec documentation on the specified path.\n */\n outFile?: string;\n /**\n * A function to generate the operationId.\n */\n operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;\n /**\n * A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name).\n */\n operationIdPattern?: string;\n /**\n *\n */\n disableSpec?: boolean;\n /**\n * Include only controllers whose paths match the pattern list provided.\n */\n pathPatterns?: string[];\n}\n\n/**\n * @deprecated Since 2021-09-03. Will be removed in v7.\n */\nexport interface SwaggerOS2Settings extends SwaggerSettingsBase {\n specVersion?: OS2Versions;\n /**\n * OpenSpec 2\n */\n spec?: Partial<OpenSpec2>;\n}\n\nexport interface SwaggerOS3Settings extends SwaggerSettingsBase {\n specVersion?: OS3Versions;\n /**\n * OpenSpec 3\n */\n spec?: Partial<OpenSpec3>;\n}\n\nexport type SwaggerSettings = SwaggerOS2Settings | SwaggerOS3Settings;\n"]}
1
+ {"version":3,"file":"SwaggerSettings.js","sourceRoot":"","sources":["../../../src/interfaces/SwaggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {OpenSpec2, OpenSpec3, OpenSpecVersions, OS2Versions, OS3Versions} from \"@tsed/openspec\";\n\nexport interface SwaggerUIOptions {\n configUrl?: string;\n url?: string;\n urls?: {url: string; name: string; primaryName?: string}[];\n layout?: string;\n validatorUrl?: string;\n oauth?: any;\n authorize?: any;\n\n [key: string]: any;\n}\n\nexport interface SwaggerSettingsBase {\n /**\n * The url subpath to access to the documentation.\n */\n path: string;\n /**\n * Specify the spec version you want to generate.\n */\n specVersion?: OpenSpecVersions;\n /**\n * Swagger file name. By default swagger.json\n */\n fileName?: string;\n /**\n * Hidden documentation. Use this to hide documentation link in the dropdown.\n */\n hidden?: string;\n /**\n * The documentation key used by `@Docs` decorator to create several swagger documentations.\n */\n doc?: string;\n /**\n * The path to the CSS file.\n */\n cssPath?: string;\n /**\n * The path to the JS file.\n */\n jsPath?: string;\n /**\n * The path to the ejs file to create html page.\n */\n viewPath?: string | false;\n /**\n * SwaggerUI options. See (https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md)\n */\n options?: SwaggerUIOptions;\n /**\n * Display the search field in the navbar.\n */\n showExplorer?: boolean;\n /**\n * Load the base spec documentation from the specified path.\n */\n specPath?: string;\n /**\n * Write the `swagger.json` spec documentation on the specified path.\n */\n outFile?: string;\n /**\n * A function to generate the operationId.\n */\n operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;\n /**\n * A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name).\n */\n operationIdPattern?: string;\n /**\n *\n */\n disableSpec?: boolean;\n /**\n * Include only controllers whose paths match the pattern list provided.\n */\n pathPatterns?: string[];\n}\n\nexport interface SwaggerOS2Settings extends SwaggerSettingsBase {\n specVersion?: OS2Versions;\n /**\n * OpenSpec 2\n */\n spec?: Partial<OpenSpec2>;\n}\n\nexport interface SwaggerOS3Settings extends SwaggerSettingsBase {\n specVersion?: OS3Versions;\n /**\n * OpenSpec 3\n */\n spec?: Partial<OpenSpec3>;\n}\n\nexport type SwaggerSettings = SwaggerOS2Settings | SwaggerOS3Settings;\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {SwaggerSettings} from \"./SwaggerSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n swagger: SwaggerSettings[];\n }\n }\n}\n"]}
@@ -4,12 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.SwaggerService = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const common_1 = require("@tsed/common");
7
- const core_1 = require("@tsed/core");
8
7
  const schema_1 = require("@tsed/schema");
9
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
10
- const getSpecType_1 = require("../utils/getSpecType");
11
8
  const includeRoute_1 = require("../utils/includeRoute");
12
- const mapOpenSpec_1 = require("../utils/mapOpenSpec");
13
9
  let SwaggerService = class SwaggerService {
14
10
  constructor(injectorService, platform, configuration) {
15
11
  this.injectorService = injectorService;
@@ -17,60 +13,25 @@ let SwaggerService = class SwaggerService {
17
13
  this.configuration = configuration;
18
14
  _SwaggerService_specs.set(this, new Map());
19
15
  }
20
- getOpenAPISpec(conf) {
16
+ async getOpenAPISpec(conf) {
21
17
  if (!(0, tslib_1.__classPrivateFieldGet)(this, _SwaggerService_specs, "f").has(conf.path)) {
22
- const defaultSpec = this.getDefaultSpec(conf);
23
- const specType = (0, getSpecType_1.getSpecTypeFromSpec)(defaultSpec);
24
- let finalSpec = {};
25
- const options = {
26
- paths: {},
27
- tags: [],
28
- schemas: {},
29
- specType,
30
- operationIdFormatter: conf.operationIdFormatter,
31
- operationIdPattern: conf.operationIdPattern,
32
- append(spec) {
33
- finalSpec = (0, schema_1.mergeSpec)(finalSpec, spec);
34
- }
35
- };
36
- this.platform.getMountedControllers().forEach(({ route, provider }) => {
37
- if ((0, includeRoute_1.includeRoute)(route, provider, conf)) {
38
- const spec = (0, schema_1.getSpec)(provider.token, {
39
- ...options,
40
- rootPath: route.replace(provider.path, "")
41
- });
42
- options.append(spec);
43
- }
18
+ const { version = "1.0.0", acceptMimes } = this.configuration;
19
+ const specPath = conf.specPath ? this.configuration.resolve(conf.specPath) : conf.specPath;
20
+ const tokens = this.platform
21
+ .getMountedControllers()
22
+ .filter(({ route, provider }) => (0, includeRoute_1.includeRoute)(route, provider, conf))
23
+ .map(({ route, provider }) => ({ token: provider.token, rootPath: route.replace(provider.path, "") }));
24
+ const spec = await (0, schema_1.generateSpec)({
25
+ tokens,
26
+ ...conf,
27
+ specPath,
28
+ version,
29
+ acceptMimes
44
30
  });
45
- (0, tslib_1.__classPrivateFieldGet)(this, _SwaggerService_specs, "f").set(conf.path, (0, schema_1.mergeSpec)(defaultSpec, finalSpec));
31
+ (0, tslib_1.__classPrivateFieldGet)(this, _SwaggerService_specs, "f").set(conf.path, spec);
46
32
  }
47
33
  return (0, tslib_1.__classPrivateFieldGet)(this, _SwaggerService_specs, "f").get(conf.path);
48
34
  }
49
- /**
50
- * Return the global api information.
51
- */
52
- getDefaultSpec(conf) {
53
- const { version = "1.0.0", acceptMimes } = this.configuration;
54
- const { specPath, specVersion } = conf;
55
- const fileSpec = specPath ? this.readSpecPath(specPath) : {};
56
- return (0, mapOpenSpec_1.mapOpenSpec)((0, core_1.getValue)(conf, "spec", {}), {
57
- fileSpec,
58
- version,
59
- specVersion,
60
- acceptMimes
61
- });
62
- }
63
- readSpecPath(path) {
64
- path = this.configuration.resolve(path);
65
- if (fs_1.default.existsSync(path)) {
66
- const json = fs_1.default.readFileSync(path, { encoding: "utf8" });
67
- /* istanbul ignore else */
68
- if (json !== "") {
69
- return JSON.parse(json);
70
- }
71
- }
72
- return {};
73
- }
74
35
  };
75
36
  _SwaggerService_specs = new WeakMap();
76
37
  SwaggerService = (0, tslib_1.__decorate)([
@@ -1 +1 @@
1
- {"version":3,"file":"SwaggerService.js","s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,KAAK,CAAC,IAAI,CAAC,CAAC;aACzB;SACF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAA;;AArFY,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAOR,wBAAA,IAAA,sBAAa,GAAE,CAAA;kDAFS,wBAAe;QACtB,iBAAQ;GALjB,cAAc,CAqF1B;AArFY,wCAAc","sourcesContent":["import {Configuration, ControllerProvider, Injectable, InjectorService, Platform} from \"@tsed/common\";\nimport {getValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {getSpec, mergeSpec, SpecSerializerOptions} from \"@tsed/schema\";\nimport Fs from \"fs\";\nimport {SwaggerOS2Settings, SwaggerOS3Settings, SwaggerSettings} from \"../interfaces/SwaggerSettings\";\nimport {getSpecTypeFromSpec} from \"../utils/getSpecType\";\nimport {includeRoute} from \"../utils/includeRoute\";\nimport {mapOpenSpec} from \"../utils/mapOpenSpec\";\n\n@Injectable()\nexport class SwaggerService {\n #specs: Map<string, OpenSpec3 | OpenSpec2> = new Map();\n\n constructor(\n private injectorService: InjectorService,\n private platform: Platform,\n @Configuration() private configuration: Configuration\n ) {}\n\n /**\n * Generate Spec for the given configuration\n * @returns {Spec}\n */\n public getOpenAPISpec(conf: SwaggerOS3Settings): OpenSpec3;\n /**\n * @deprecated\n */\n public getOpenAPISpec(conf: SwaggerOS2Settings): OpenSpec2;\n /**\n * @deprecated\n */\n public getOpenAPISpec(conf: SwaggerSettings): OpenSpec2;\n public getOpenAPISpec(conf: SwaggerSettings) {\n if (!this.#specs.has(conf.path)) {\n const defaultSpec: any = this.getDefaultSpec(conf);\n const specType = getSpecTypeFromSpec(defaultSpec);\n let finalSpec: any = {};\n\n const options: SpecSerializerOptions = {\n paths: {},\n tags: [],\n schemas: {},\n specType,\n operationIdFormatter: conf.operationIdFormatter,\n operationIdPattern: conf.operationIdPattern,\n append(spec: any) {\n finalSpec = mergeSpec(finalSpec, spec);\n }\n };\n\n this.platform.getMountedControllers().forEach(({route, provider}) => {\n if (includeRoute(route, provider, conf)) {\n const spec = getSpec(provider.token, {\n ...options,\n rootPath: route.replace(provider.path, \"\")\n });\n\n options.append(spec);\n }\n });\n\n this.#specs.set(conf.path, mergeSpec(defaultSpec, finalSpec) as any);\n }\n\n return this.#specs.get(conf.path);\n }\n\n /**\n * Return the global api information.\n */\n protected getDefaultSpec(conf: Partial<SwaggerSettings>): Partial<OpenSpec2 | OpenSpec3> {\n const {version = \"1.0.0\", acceptMimes} = this.configuration;\n const {specPath, specVersion} = conf;\n const fileSpec: Partial<OpenSpec2 | OpenSpec3> = specPath ? this.readSpecPath(specPath) : {};\n\n return mapOpenSpec(getValue(conf, \"spec\", {}), {\n fileSpec,\n version,\n specVersion,\n acceptMimes\n });\n }\n\n protected readSpecPath(path: string) {\n path = this.configuration.resolve(path);\n if (Fs.existsSync(path)) {\n const json = Fs.readFileSync(path, {encoding: \"utf8\"});\n /* istanbul ignore else */\n if (json !== \"\") {\n return JSON.parse(json);\n }\n }\n\n return {};\n }\n}\n"]}
1
+ {"version":3,"file":"SwaggerService.js","sourceRoot":"","sources":["../../../src/services/SwaggerService.ts"],"names":[],"mappings":";;;;;AAAA,yCAAkF;AAElF,yCAA0C;AAE1C,wDAAmD;AAGnD,IAAa,cAAc,GAA3B,MAAa,cAAc;IAGzB,YACU,eAAgC,EAChC,QAAkB,EACD,aAA4B;QAF7C,oBAAe,GAAf,eAAe,CAAiB;QAChC,aAAQ,GAAR,QAAQ,CAAU;QACD,kBAAa,GAAb,aAAa,CAAe;QALvD,gCAA6C,IAAI,GAAG,EAAE,EAAC;IAMpD,CAAC;IASG,KAAK,CAAC,cAAc,CAAC,IAAqB;QAC/C,IAAI,CAAC,oCAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAC/B,MAAM,EAAC,OAAO,GAAG,OAAO,EAAE,WAAW,EAAC,GAAG,IAAI,CAAC,aAAa,CAAC;YAC5D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;YAE3F,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ;iBACzB,qBAAqB,EAAE;iBACvB,MAAM,CAAC,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC,IAAA,2BAAY,EAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;iBAClE,GAAG,CAAC,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,EAAC,CAAC,CAAC,CAAC;YAErG,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAY,EAAC;gBAC9B,MAAM;gBACN,GAAG,IAAI;gBACP,QAAQ;gBACR,OAAO;gBACP,WAAW;aACZ,CAAC,CAAC;YAEH,oCAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SAClC;QAED,OAAO,oCAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;;AAvCY,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAOR,wBAAA,IAAA,sBAAa,GAAE,CAAA;kDAFS,wBAAe;QACtB,iBAAQ;GALjB,cAAc,CAuC1B;AAvCY,wCAAc","sourcesContent":["import {Configuration, Injectable, InjectorService, Platform} from \"@tsed/common\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {generateSpec} from \"@tsed/schema\";\nimport {SwaggerOS2Settings, SwaggerOS3Settings, SwaggerSettings} from \"../interfaces/SwaggerSettings\";\nimport {includeRoute} from \"../utils/includeRoute\";\n\n@Injectable()\nexport class SwaggerService {\n #specs: Map<string, OpenSpec3 | OpenSpec2> = new Map();\n\n constructor(\n private injectorService: InjectorService,\n private platform: Platform,\n @Configuration() private configuration: Configuration\n ) {}\n\n /**\n * Generate Spec for the given configuration\n * @returns {Spec}\n */\n public async getOpenAPISpec(conf: SwaggerOS3Settings): Promise<OpenSpec3>;\n public async getOpenAPISpec(conf: SwaggerOS2Settings): Promise<OpenSpec2>;\n public async getOpenAPISpec(conf: SwaggerSettings): Promise<OpenSpec2>;\n public async getOpenAPISpec(conf: SwaggerSettings) {\n if (!this.#specs.has(conf.path)) {\n const {version = \"1.0.0\", acceptMimes} = this.configuration;\n const specPath = conf.specPath ? this.configuration.resolve(conf.specPath) : conf.specPath;\n\n const tokens = this.platform\n .getMountedControllers()\n .filter(({route, provider}) => includeRoute(route, provider, conf))\n .map(({route, provider}) => ({token: provider.token, rootPath: route.replace(provider.path, \"\")}));\n\n const spec = await generateSpec({\n tokens,\n ...conf,\n specPath,\n version,\n acceptMimes\n });\n\n this.#specs.set(conf.path, spec);\n }\n\n return this.#specs.get(conf.path);\n }\n}\n"]}
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.includeRoute = void 0;
4
- const _1 = require(".");
4
+ const matchPath_1 = require("./matchPath");
5
5
  function includeRoute(route, provider, conf) {
6
6
  const hidden = provider.store.get("hidden");
7
7
  const docs = provider.store.get("docs") || [];
8
8
  const { doc, pathPatterns } = conf;
9
9
  const inDoc = doc && docs.indexOf(doc) > -1;
10
- const pathPatternMatch = pathPatterns && (0, _1.matchPath)(route, pathPatterns);
10
+ const pathPatternMatch = pathPatterns && (0, matchPath_1.matchPath)(route, pathPatterns);
11
11
  if (hidden) {
12
12
  return false;
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"includeRoute.js","sourceRoot":"","sources":["../../../src/utils/includeRoute.ts"],"names":[],"mappings":";;;AACA,wBAA4B;AAG5B,SAAgB,YAAY,CAAC,KAAa,EAAE,QAA4B,EAAE,IAAqB;IAC7F,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9C,MAAM,EAAC,GAAG,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IACjC,MAAM,KAAK,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,YAAY,IAAI,IAAA,YAAS,EAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAExE,IAAI,MAAM,EAAE;QACV,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,gBAAgB,CAAC,CAAC;AACvC,CAAC;AAhBD,oCAgBC","sourcesContent":["import {ControllerProvider} from \"@tsed/common\";\nimport {matchPath} from \".\";\nimport {SwaggerSettings} from \"..\";\n\nexport function includeRoute(route: string, provider: ControllerProvider, conf: SwaggerSettings): boolean {\n const hidden = provider.store.get(\"hidden\");\n const docs = provider.store.get(\"docs\") || [];\n const {doc, pathPatterns} = conf;\n const inDoc = doc && docs.indexOf(doc) > -1;\n const pathPatternMatch = pathPatterns && matchPath(route, pathPatterns);\n\n if (hidden) {\n return false;\n }\n\n if (!doc && !pathPatterns) {\n return true;\n }\n\n return !!(inDoc || pathPatternMatch);\n}\n"]}
1
+ {"version":3,"file":"includeRoute.js","sourceRoot":"","sources":["../../../src/utils/includeRoute.ts"],"names":[],"mappings":";;;AACA,2CAAsC;AAGtC,SAAgB,YAAY,CAAC,KAAa,EAAE,QAA4B,EAAE,IAAqB;IAC7F,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9C,MAAM,EAAC,GAAG,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IACjC,MAAM,KAAK,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,YAAY,IAAI,IAAA,qBAAS,EAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAExE,IAAI,MAAM,EAAE;QACV,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,gBAAgB,CAAC,CAAC;AACvC,CAAC;AAhBD,oCAgBC","sourcesContent":["import {ControllerProvider} from \"@tsed/common\";\nimport {matchPath} from \"./matchPath\";\nimport {SwaggerSettings} from \"../interfaces/SwaggerSettings\";\n\nexport function includeRoute(route: string, provider: ControllerProvider, conf: SwaggerSettings): boolean {\n const hidden = provider.store.get(\"hidden\");\n const docs = provider.store.get(\"docs\") || [];\n const {doc, pathPatterns} = conf;\n const inDoc = doc && docs.indexOf(doc) > -1;\n const pathPatternMatch = pathPatterns && matchPath(route, pathPatterns);\n\n if (hidden) {\n return false;\n }\n\n if (!doc && !pathPatterns) {\n return true;\n }\n\n return !!(inDoc || pathPatternMatch);\n}\n"]}
@@ -56,10 +56,10 @@ let SwaggerModule = class SwaggerModule {
56
56
  this.generateSpecFiles();
57
57
  }
58
58
  generateSpecFiles() {
59
- return Promise.all(this.settings.map((conf) => {
59
+ return Promise.all(this.settings.map(async (conf) => {
60
60
  const { outFile } = conf;
61
61
  if (this.env === Env.PROD || outFile) {
62
- const spec = this.swaggerService.getOpenAPISpec(conf);
62
+ const spec = await this.swaggerService.getOpenAPISpec(conf);
63
63
  if (outFile) {
64
64
  return Fs.writeFile(outFile, JSON.stringify(spec, null, 2), { encoding: "utf8" }, () => { });
65
65
  }
@@ -99,8 +99,8 @@ let SwaggerModule = class SwaggerModule {
99
99
  return router;
100
100
  }
101
101
  middlewareSwaggerJson(conf) {
102
- return (ctx) => {
103
- ctx.response.status(200).body(this.swaggerService.getOpenAPISpec(conf));
102
+ return async (ctx) => {
103
+ ctx.response.status(200).body(await this.swaggerService.getOpenAPISpec(conf));
104
104
  };
105
105
  }
106
106
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SwaggerModule.js","sourceRoot":"","sources":["../../src/SwaggerModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,aAAa,EACb,QAAQ,EACR,MAAM,EACN,eAAe,EACf,MAAM,EACN,aAAa,EAEb,mBAAmB,EAEnB,cAAc,EACd,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAE1B,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAC,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC;AAErC;;GAEG;AAEH,IAAa,aAAa,GAA1B,MAAa,aAAa;IAA1B;QAgBU,WAAM,GAAG,KAAK,CAAC;IAiHzB,CAAC;IA/GC,IA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M,CAAC,OAAO,CAAC,GAAG,EAAE,EAAC,IAAI,EAAE,aAAa,EAAC,CAAC,CAAC;SAC5C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,qBAAqB,CAAC,IAAqB;QACjD,OAAO,CAAC,GAAoB,EAAE,EAAE;YAC9B,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1E,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AA/HC;IADC,MAAM,EAAE;8BACC,eAAe;+CAAC;AAG1B;IADC,MAAM,EAAE;8BACJ,mBAAmB;0CAAC;AAGzB;IADC,aAAa,EAAE;;oDACa;AAG7B;IADC,MAAM,EAAE;8BACO,cAAc;qDAAC;AAG/B;IADC,QAAQ,CAAC,KAAK,CAAC;;0CACP;AAdE,aAAa;IADzB,MAAM,EAAE;GACI,aAAa,CAiIzB;SAjIY,aAAa","sourcesContent":["import {\n OnRoutesInit,\n Configuration,\n Constant,\n Inject,\n InjectorService,\n Module,\n normalizePath,\n OnReady,\n PlatformApplication,\n PlatformContext,\n PlatformRouter,\n useCtxHandler\n} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {join} from \"path\";\nimport {SwaggerSettings} from \"./interfaces\";\nimport {cssMiddleware} from \"./middlewares/cssMiddleware\";\nimport {indexMiddleware} from \"./middlewares/indexMiddleware\";\nimport {jsMiddleware} from \"./middlewares/jsMiddleware\";\nimport {redirectMiddleware} from \"./middlewares/redirectMiddleware\";\nimport {SwaggerService} from \"./services/SwaggerService\";\nimport {Env} from \"@tsed/core\";\nimport {absolutePath} from \"swagger-ui-dist\";\n\nconst swaggerUiPath = absolutePath();\n\n/**\n * @ignore\n */\n@Module()\nexport class SwaggerModule implements OnRoutesInit, OnReady {\n @Inject()\n injector: InjectorService;\n\n @Inject()\n app: PlatformApplication;\n\n @Configuration()\n configuration: Configuration;\n\n @Inject()\n swaggerService: SwaggerService;\n\n @Constant(\"env\")\n env: Env;\n\n private loaded = false;\n\n get settings() {\n return ([] as SwaggerSettings[]).concat(this.configuration.get<SwaggerSettings[]>(\"swagger\")).filter((o) => !!o);\n }\n\n /**\n *\n */\n $onRoutesInit() {\n if (this.loaded) {\n return;\n }\n\n const urls: any[] = this.getUrls();\n\n this.settings.forEach((conf: SwaggerSettings) => {\n const {path = \"/\"} = conf;\n\n this.app.get(path, useCtxHandler(redirectMiddleware(path)));\n this.app.use(path, this.createRouter(conf, urls));\n });\n\n this.loaded = true;\n }\n\n $onReady() {\n // istanbul ignore next\n if (this.configuration.getBestHost) {\n const host = this.configuration.getBestHost();\n const url = host.toString();\n\n const displayLog = (conf: SwaggerSettings) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, specVersion} = conf;\n\n this.injector.logger.info(`[${doc || \"default\"}] Swagger JSON is available on ${url}${normalizePath(path, fileName)}`);\n this.injector.logger.info(`[${doc || \"default\"}] Swagger UI is available on ${url}${path}/`);\n // istanbul ignore next\n if (specVersion === \"2.0\") {\n this.injector.logger.warn(`[${doc || \"default\"}] Swagger 2.0 is now deprecated. Please migrate to OpenSpec 3`);\n }\n };\n\n this.settings.forEach((conf) => {\n displayLog(conf);\n });\n }\n\n this.generateSpecFiles();\n }\n\n generateSpecFiles() {\n return Promise.all(\n this.settings.map((conf) => {\n const {outFile} = conf;\n\n if (this.env === Env.PROD || outFile) {\n const spec = this.swaggerService.getOpenAPISpec(conf);\n\n if (outFile) {\n return Fs.writeFile(outFile, JSON.stringify(spec, null, 2), {encoding: \"utf8\"}, () => {});\n }\n }\n })\n );\n }\n\n private getUrls() {\n return this.settings.reduce((acc: any[], conf) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, hidden} = conf;\n\n if (!hidden) {\n acc.push({url: normalizePath(path, fileName), name: doc || path});\n }\n\n return acc;\n }, []);\n }\n\n /**\n *\n * @param conf\n * @param urls\n */\n private createRouter(conf: SwaggerSettings, urls: string[]) {\n const {disableSpec = false, fileName = \"swagger.json\", cssPath, jsPath, viewPath = join(__dirname, \"../views/index.ejs\")} = conf;\n const router = PlatformRouter.create(this.injector);\n\n if (!disableSpec) {\n router.get(normalizePath(\"/\", fileName), useCtxHandler(this.middlewareSwaggerJson(conf)));\n }\n\n if (viewPath) {\n if (cssPath) {\n router.get(\"/main.css\", useCtxHandler(cssMiddleware(cssPath)));\n }\n\n if (jsPath) {\n router.get(\"/main.js\", useCtxHandler(jsMiddleware(jsPath)));\n }\n\n router.get(\"/\", useCtxHandler(indexMiddleware(viewPath, {urls, ...conf})));\n router.statics(\"/\", {root: swaggerUiPath});\n }\n\n return router;\n }\n\n private middlewareSwaggerJson(conf: SwaggerSettings) {\n return (ctx: PlatformContext) => {\n ctx.response.status(200).body(this.swaggerService.getOpenAPISpec(conf));\n };\n }\n}\n"]}
1
+ {"version":3,"file":"SwaggerModule.js","sourceRoot":"","sources":["../../src/SwaggerModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,aAAa,EACb,QAAQ,EACR,MAAM,EACN,eAAe,EACf,MAAM,EACN,aAAa,EAEb,mBAAmB,EAEnB,cAAc,EACd,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAE1B,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAC,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C,MAAM,aAAa,GAAG,YAAY,EAAE,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GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAC,IAAI,EAAE,GAAG,IAAI,EAAC,CAAC,CAAC,CAAC,CAAC;YAC3E,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAC,IAAI,EAAE,aAAa,EAAC,CAAC,CAAC;SAC5C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,qBAAqB,CAAC,IAAqB;QACjD,OAAO,KAAK,EAAE,GAAoB,EAAE,EAAE;YACpC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAChF,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AA/HC;IADC,MAAM,EAAE;8BACC,eAAe;+CAAC;AAG1B;IADC,MAAM,EAAE;8BACJ,mBAAmB;0CAAC;AAGzB;IADC,aAAa,EAAE;;oDACa;AAG7B;IADC,MAAM,EAAE;8BACO,cAAc;qDAAC;AAG/B;IADC,QAAQ,CAAC,KAAK,CAAC;;0CACP;AAdE,aAAa;IADzB,MAAM,EAAE;GACI,aAAa,CAiIzB;SAjIY,aAAa","sourcesContent":["import {\n OnRoutesInit,\n Configuration,\n Constant,\n Inject,\n InjectorService,\n Module,\n normalizePath,\n OnReady,\n PlatformApplication,\n PlatformContext,\n PlatformRouter,\n useCtxHandler\n} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {join} from \"path\";\nimport {SwaggerSettings} from \"./interfaces/SwaggerSettings\";\nimport {cssMiddleware} from \"./middlewares/cssMiddleware\";\nimport {indexMiddleware} from \"./middlewares/indexMiddleware\";\nimport {jsMiddleware} from \"./middlewares/jsMiddleware\";\nimport {redirectMiddleware} from \"./middlewares/redirectMiddleware\";\nimport {SwaggerService} from \"./services/SwaggerService\";\nimport {Env} from \"@tsed/core\";\nimport {absolutePath} from \"swagger-ui-dist\";\n\nconst swaggerUiPath = absolutePath();\n\n/**\n * @ignore\n */\n@Module()\nexport class SwaggerModule implements OnRoutesInit, OnReady {\n @Inject()\n injector: InjectorService;\n\n @Inject()\n app: PlatformApplication;\n\n @Configuration()\n configuration: Configuration;\n\n @Inject()\n swaggerService: SwaggerService;\n\n @Constant(\"env\")\n env: Env;\n\n private loaded = false;\n\n get settings() {\n return ([] as SwaggerSettings[]).concat(this.configuration.get<SwaggerSettings[]>(\"swagger\")).filter((o) => !!o);\n }\n\n /**\n *\n */\n $onRoutesInit() {\n if (this.loaded) {\n return;\n }\n\n const urls: any[] = this.getUrls();\n\n this.settings.forEach((conf: SwaggerSettings) => {\n const {path = \"/\"} = conf;\n\n this.app.get(path, useCtxHandler(redirectMiddleware(path)));\n this.app.use(path, this.createRouter(conf, urls));\n });\n\n this.loaded = true;\n }\n\n $onReady() {\n // istanbul ignore next\n if (this.configuration.getBestHost) {\n const host = this.configuration.getBestHost();\n const url = host.toString();\n\n const displayLog = (conf: SwaggerSettings) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, specVersion} = conf;\n\n this.injector.logger.info(`[${doc || \"default\"}] Swagger JSON is available on ${url}${normalizePath(path, fileName)}`);\n this.injector.logger.info(`[${doc || \"default\"}] Swagger UI is available on ${url}${path}/`);\n // istanbul ignore next\n if (specVersion === \"2.0\") {\n this.injector.logger.warn(`[${doc || \"default\"}] Swagger 2.0 is now deprecated. Please migrate to OpenSpec 3`);\n }\n };\n\n this.settings.forEach((conf) => {\n displayLog(conf);\n });\n }\n\n this.generateSpecFiles();\n }\n\n generateSpecFiles() {\n return Promise.all(\n this.settings.map(async (conf) => {\n const {outFile} = conf;\n\n if (this.env === Env.PROD || outFile) {\n const spec = await this.swaggerService.getOpenAPISpec(conf);\n\n if (outFile) {\n return Fs.writeFile(outFile, JSON.stringify(spec, null, 2), {encoding: \"utf8\"}, () => {});\n }\n }\n })\n );\n }\n\n private getUrls() {\n return this.settings.reduce((acc: any[], conf) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, hidden} = conf;\n\n if (!hidden) {\n acc.push({url: normalizePath(path, fileName), name: doc || path});\n }\n\n return acc;\n }, []);\n }\n\n /**\n *\n * @param conf\n * @param urls\n */\n private createRouter(conf: SwaggerSettings, urls: string[]) {\n const {disableSpec = false, fileName = \"swagger.json\", cssPath, jsPath, viewPath = join(__dirname, \"../views/index.ejs\")} = conf;\n const router = PlatformRouter.create(this.injector);\n\n if (!disableSpec) {\n router.get(normalizePath(\"/\", fileName), useCtxHandler(this.middlewareSwaggerJson(conf)));\n }\n\n if (viewPath) {\n if (cssPath) {\n router.get(\"/main.css\", useCtxHandler(cssMiddleware(cssPath)));\n }\n\n if (jsPath) {\n router.get(\"/main.js\", useCtxHandler(jsMiddleware(jsPath)));\n }\n\n router.get(\"/\", useCtxHandler(indexMiddleware(viewPath, {urls, ...conf})));\n router.statics(\"/\", {root: swaggerUiPath});\n }\n\n return router;\n }\n\n private middlewareSwaggerJson(conf: SwaggerSettings) {\n return async (ctx: PlatformContext) => {\n ctx.response.status(200).body(await this.swaggerService.getOpenAPISpec(conf));\n };\n }\n}\n"]}
package/lib/esm/index.js CHANGED
@@ -1,6 +1,16 @@
1
- export * from "./services/SwaggerService.js";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
2
4
  export * from "./SwaggerModule.js";
3
- export * from "./interfaces.js";
4
5
  export * from "./decorators/docs.js";
5
6
  export * from "./decorators/hidden.js";
7
+ export * from "./interfaces/SwaggerSettings.js";
8
+ export * from "./interfaces/interfaces.js";
9
+ export * from "./middlewares/cssMiddleware.js";
10
+ export * from "./middlewares/indexMiddleware.js";
11
+ export * from "./middlewares/jsMiddleware.js";
12
+ export * from "./middlewares/redirectMiddleware.js";
13
+ export * from "./services/SwaggerService.js";
14
+ export * from "./utils/includeRoute.js";
15
+ export * from "./utils/matchPath.js";
6
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./services/SwaggerService\";\nexport * from \"./SwaggerModule\";\nexport * from \"./interfaces\";\nexport * from \"./decorators/docs\";\nexport * from \"./decorators/hidden\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./SwaggerModule\";\nexport * from \"./decorators/docs\";\nexport * from \"./decorators/hidden\";\nexport * from \"./interfaces/SwaggerSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/cssMiddleware\";\nexport * from \"./middlewares/indexMiddleware\";\nexport * from \"./middlewares/jsMiddleware\";\nexport * from \"./middlewares/redirectMiddleware\";\nexport * from \"./services/SwaggerService\";\nexport * from \"./utils/includeRoute\";\nexport * from \"./utils/matchPath\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SwaggerSettings.js","sourceRoot":"","sources":["../../../src/interfaces/SwaggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {OpenSpec2, OpenSpec3, OpenSpecVersions, OS2Versions, OS3Versions} from \"@tsed/openspec\";\n\nexport interface SwaggerUIOptions {\n configUrl?: string;\n url?: string;\n urls?: {url: string; name: string; primaryName?: string}[];\n layout?: string;\n validatorUrl?: string;\n oauth?: any;\n authorize?: any;\n\n [key: string]: any;\n}\n\nexport interface SwaggerSettingsBase {\n /**\n * The url subpath to access to the documentation.\n */\n path: string;\n /**\n * Specify the spec version you want to generate.\n */\n specVersion?: OpenSpecVersions;\n /**\n * Swagger file name. By default swagger.json\n */\n fileName?: string;\n /**\n * Hidden documentation. Use this to hide documentation link in the dropdown.\n */\n hidden?: string;\n /**\n * The documentation key used by `@Docs` decorator to create several swagger documentations.\n */\n doc?: string;\n /**\n * The path to the CSS file.\n */\n cssPath?: string;\n /**\n * The path to the JS file.\n */\n jsPath?: string;\n /**\n * The path to the ejs file to create html page.\n */\n viewPath?: string | false;\n /**\n * SwaggerUI options. See (https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md)\n */\n options?: SwaggerUIOptions;\n /**\n * Display the search field in the navbar.\n */\n showExplorer?: boolean;\n /**\n * Load the base spec documentation from the specified path.\n */\n specPath?: string;\n /**\n * Write the `swagger.json` spec documentation on the specified path.\n */\n outFile?: string;\n /**\n * A function to generate the operationId.\n */\n operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;\n /**\n * A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name).\n */\n operationIdPattern?: string;\n /**\n *\n */\n disableSpec?: boolean;\n /**\n * Include only controllers whose paths match the pattern list provided.\n */\n pathPatterns?: string[];\n}\n\n/**\n * @deprecated Since 2021-09-03. Will be removed in v7.\n */\nexport interface SwaggerOS2Settings extends SwaggerSettingsBase {\n specVersion?: OS2Versions;\n /**\n * OpenSpec 2\n */\n spec?: Partial<OpenSpec2>;\n}\n\nexport interface SwaggerOS3Settings extends SwaggerSettingsBase {\n specVersion?: OS3Versions;\n /**\n * OpenSpec 3\n */\n spec?: Partial<OpenSpec3>;\n}\n\nexport type SwaggerSettings = SwaggerOS2Settings | SwaggerOS3Settings;\n"]}
1
+ {"version":3,"file":"SwaggerSettings.js","sourceRoot":"","sources":["../../../src/interfaces/SwaggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {OpenSpec2, OpenSpec3, OpenSpecVersions, OS2Versions, OS3Versions} from \"@tsed/openspec\";\n\nexport interface SwaggerUIOptions {\n configUrl?: string;\n url?: string;\n urls?: {url: string; name: string; primaryName?: string}[];\n layout?: string;\n validatorUrl?: string;\n oauth?: any;\n authorize?: any;\n\n [key: string]: any;\n}\n\nexport interface SwaggerSettingsBase {\n /**\n * The url subpath to access to the documentation.\n */\n path: string;\n /**\n * Specify the spec version you want to generate.\n */\n specVersion?: OpenSpecVersions;\n /**\n * Swagger file name. By default swagger.json\n */\n fileName?: string;\n /**\n * Hidden documentation. Use this to hide documentation link in the dropdown.\n */\n hidden?: string;\n /**\n * The documentation key used by `@Docs` decorator to create several swagger documentations.\n */\n doc?: string;\n /**\n * The path to the CSS file.\n */\n cssPath?: string;\n /**\n * The path to the JS file.\n */\n jsPath?: string;\n /**\n * The path to the ejs file to create html page.\n */\n viewPath?: string | false;\n /**\n * SwaggerUI options. See (https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md)\n */\n options?: SwaggerUIOptions;\n /**\n * Display the search field in the navbar.\n */\n showExplorer?: boolean;\n /**\n * Load the base spec documentation from the specified path.\n */\n specPath?: string;\n /**\n * Write the `swagger.json` spec documentation on the specified path.\n */\n outFile?: string;\n /**\n * A function to generate the operationId.\n */\n operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;\n /**\n * A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name).\n */\n operationIdPattern?: string;\n /**\n *\n */\n disableSpec?: boolean;\n /**\n * Include only controllers whose paths match the pattern list provided.\n */\n pathPatterns?: string[];\n}\n\nexport interface SwaggerOS2Settings extends SwaggerSettingsBase {\n specVersion?: OS2Versions;\n /**\n * OpenSpec 2\n */\n spec?: Partial<OpenSpec2>;\n}\n\nexport interface SwaggerOS3Settings extends SwaggerSettingsBase {\n specVersion?: OS3Versions;\n /**\n * OpenSpec 3\n */\n spec?: Partial<OpenSpec3>;\n}\n\nexport type SwaggerSettings = SwaggerOS2Settings | SwaggerOS3Settings;\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {SwaggerSettings} from \"./SwaggerSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n swagger: SwaggerSettings[];\n }\n }\n}\n"]}
@@ -1,12 +1,8 @@
1
1
  var _SwaggerService_specs;
2
2
  import { __classPrivateFieldGet, __decorate, __metadata, __param } from "tslib";
3
3
  import { Configuration, Injectable, InjectorService, Platform } from "@tsed/common";
4
- import { getValue } from "@tsed/core";
5
- import { getSpec, mergeSpec } from "@tsed/schema";
6
- import Fs from "fs";
7
- import { getSpecTypeFromSpec } from "../utils/getSpecType.js";
4
+ import { generateSpec } from "@tsed/schema";
8
5
  import { includeRoute } from "../utils/includeRoute.js";
9
- import { mapOpenSpec } from "../utils/mapOpenSpec.js";
10
6
  let SwaggerService = class SwaggerService {
11
7
  constructor(injectorService, platform, configuration) {
12
8
  this.injectorService = injectorService;
@@ -14,60 +10,25 @@ let SwaggerService = class SwaggerService {
14
10
  this.configuration = configuration;
15
11
  _SwaggerService_specs.set(this, new Map());
16
12
  }
17
- getOpenAPISpec(conf) {
13
+ async getOpenAPISpec(conf) {
18
14
  if (!__classPrivateFieldGet(this, _SwaggerService_specs, "f").has(conf.path)) {
19
- const defaultSpec = this.getDefaultSpec(conf);
20
- const specType = getSpecTypeFromSpec(defaultSpec);
21
- let finalSpec = {};
22
- const options = {
23
- paths: {},
24
- tags: [],
25
- schemas: {},
26
- specType,
27
- operationIdFormatter: conf.operationIdFormatter,
28
- operationIdPattern: conf.operationIdPattern,
29
- append(spec) {
30
- finalSpec = mergeSpec(finalSpec, spec);
31
- }
32
- };
33
- this.platform.getMountedControllers().forEach(({ route, provider }) => {
34
- if (includeRoute(route, provider, conf)) {
35
- const spec = getSpec(provider.token, {
36
- ...options,
37
- rootPath: route.replace(provider.path, "")
38
- });
39
- options.append(spec);
40
- }
15
+ const { version = "1.0.0", acceptMimes } = this.configuration;
16
+ const specPath = conf.specPath ? this.configuration.resolve(conf.specPath) : conf.specPath;
17
+ const tokens = this.platform
18
+ .getMountedControllers()
19
+ .filter(({ route, provider }) => includeRoute(route, provider, conf))
20
+ .map(({ route, provider }) => ({ token: provider.token, rootPath: route.replace(provider.path, "") }));
21
+ const spec = await generateSpec({
22
+ tokens,
23
+ ...conf,
24
+ specPath,
25
+ version,
26
+ acceptMimes
41
27
  });
42
- __classPrivateFieldGet(this, _SwaggerService_specs, "f").set(conf.path, mergeSpec(defaultSpec, finalSpec));
28
+ __classPrivateFieldGet(this, _SwaggerService_specs, "f").set(conf.path, spec);
43
29
  }
44
30
  return __classPrivateFieldGet(this, _SwaggerService_specs, "f").get(conf.path);
45
31
  }
46
- /**
47
- * Return the global api information.
48
- */
49
- getDefaultSpec(conf) {
50
- const { version = "1.0.0", acceptMimes } = this.configuration;
51
- const { specPath, specVersion } = conf;
52
- const fileSpec = specPath ? this.readSpecPath(specPath) : {};
53
- return mapOpenSpec(getValue(conf, "spec", {}), {
54
- fileSpec,
55
- version,
56
- specVersion,
57
- acceptMimes
58
- });
59
- }
60
- readSpecPath(path) {
61
- path = this.configuration.resolve(path);
62
- if (Fs.existsSync(path)) {
63
- const json = Fs.readFileSync(path, { encoding: "utf8" });
64
- /* istanbul ignore else */
65
- if (json !== "") {
66
- return JSON.parse(json);
67
- }
68
- }
69
- return {};
70
- }
71
32
  };
72
33
  _SwaggerService_specs = new WeakMap();
73
34
  SwaggerService = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"SwaggerService.js","sourceRoot":"","sources":["../../../src/services/SwaggerService.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,aAAa,EAAsB,UAAU,EAAE,eAAe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CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;YACvD,0BAA0B;YAC1B,IAAI,IAAI,KAAK,EAAE,EAAE;gBACf,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;aACzB;SACF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAA;;AArFY,cAAc;IAD1B,UAAU,EAAE;IAOR,WAAA,aAAa,EAAE,CAAA;qCAFS,eAAe;QACtB,QAAQ;GALjB,cAAc,CAqF1B;SArFY,cAAc","sourcesContent":["import {Configuration, ControllerProvider, Injectable, InjectorService, Platform} from \"@tsed/common\";\nimport {getValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {getSpec, mergeSpec, SpecSerializerOptions} from \"@tsed/schema\";\nimport Fs from \"fs\";\nimport {SwaggerOS2Settings, SwaggerOS3Settings, SwaggerSettings} from \"../interfaces/SwaggerSettings\";\nimport {getSpecTypeFromSpec} from \"../utils/getSpecType\";\nimport {includeRoute} from \"../utils/includeRoute\";\nimport {mapOpenSpec} from \"../utils/mapOpenSpec\";\n\n@Injectable()\nexport class SwaggerService {\n #specs: Map<string, OpenSpec3 | OpenSpec2> = new Map();\n\n constructor(\n private injectorService: InjectorService,\n private platform: Platform,\n @Configuration() private configuration: Configuration\n ) {}\n\n /**\n * Generate Spec for the given configuration\n * @returns {Spec}\n */\n public getOpenAPISpec(conf: SwaggerOS3Settings): OpenSpec3;\n /**\n * @deprecated\n */\n public getOpenAPISpec(conf: SwaggerOS2Settings): OpenSpec2;\n /**\n * @deprecated\n */\n public getOpenAPISpec(conf: SwaggerSettings): OpenSpec2;\n public getOpenAPISpec(conf: SwaggerSettings) {\n if (!this.#specs.has(conf.path)) {\n const defaultSpec: any = this.getDefaultSpec(conf);\n const specType = getSpecTypeFromSpec(defaultSpec);\n let finalSpec: any = {};\n\n const options: SpecSerializerOptions = {\n paths: {},\n tags: [],\n schemas: {},\n specType,\n operationIdFormatter: conf.operationIdFormatter,\n operationIdPattern: conf.operationIdPattern,\n append(spec: any) {\n finalSpec = mergeSpec(finalSpec, spec);\n }\n };\n\n this.platform.getMountedControllers().forEach(({route, provider}) => {\n if (includeRoute(route, provider, conf)) {\n const spec = getSpec(provider.token, {\n ...options,\n rootPath: route.replace(provider.path, \"\")\n });\n\n options.append(spec);\n }\n });\n\n this.#specs.set(conf.path, mergeSpec(defaultSpec, finalSpec) as any);\n }\n\n return this.#specs.get(conf.path);\n }\n\n /**\n * Return the global api information.\n */\n protected getDefaultSpec(conf: Partial<SwaggerSettings>): Partial<OpenSpec2 | OpenSpec3> {\n const {version = \"1.0.0\", acceptMimes} = this.configuration;\n const {specPath, specVersion} = conf;\n const fileSpec: Partial<OpenSpec2 | OpenSpec3> = specPath ? this.readSpecPath(specPath) : {};\n\n return mapOpenSpec(getValue(conf, \"spec\", {}), {\n fileSpec,\n version,\n specVersion,\n acceptMimes\n });\n }\n\n protected readSpecPath(path: string) {\n path = this.configuration.resolve(path);\n if (Fs.existsSync(path)) {\n const json = Fs.readFileSync(path, {encoding: \"utf8\"});\n /* istanbul ignore else */\n if (json !== \"\") {\n return JSON.parse(json);\n }\n }\n\n return {};\n }\n}\n"]}
1
+ {"version":3,"file":"SwaggerService.js","sourceRoot":"","sources":["../../../src/services/SwaggerService.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAElF,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAGnD,IAAa,cAAc,GAA3B,MAAa,cAAc;IAGzB,YACU,eAAgC,EAChC,QAAkB,EACD,aAA4B;QAF7C,oBAAe,GAAf,eAAe,CAAiB;QAChC,aAAQ,GAAR,QAAQ,CAAU;QACD,kBAAa,GAAb,aAAa,CAAe;QALvD,gCAA6C,IAA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QACtB,QAAQ;GALjB,cAAc,CAuC1B;SAvCY,cAAc","sourcesContent":["import {Configuration, Injectable, InjectorService, Platform} from \"@tsed/common\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {generateSpec} from \"@tsed/schema\";\nimport {SwaggerOS2Settings, SwaggerOS3Settings, SwaggerSettings} from \"../interfaces/SwaggerSettings\";\nimport {includeRoute} from \"../utils/includeRoute\";\n\n@Injectable()\nexport class SwaggerService {\n #specs: Map<string, OpenSpec3 | OpenSpec2> = new Map();\n\n constructor(\n private injectorService: InjectorService,\n private platform: Platform,\n @Configuration() private configuration: Configuration\n ) {}\n\n /**\n * Generate Spec for the given configuration\n * @returns {Spec}\n */\n public async getOpenAPISpec(conf: SwaggerOS3Settings): Promise<OpenSpec3>;\n public async getOpenAPISpec(conf: SwaggerOS2Settings): Promise<OpenSpec2>;\n public async getOpenAPISpec(conf: SwaggerSettings): Promise<OpenSpec2>;\n public async getOpenAPISpec(conf: SwaggerSettings) {\n if (!this.#specs.has(conf.path)) {\n const {version = \"1.0.0\", acceptMimes} = this.configuration;\n const specPath = conf.specPath ? this.configuration.resolve(conf.specPath) : conf.specPath;\n\n const tokens = this.platform\n .getMountedControllers()\n .filter(({route, provider}) => includeRoute(route, provider, conf))\n .map(({route, provider}) => ({token: provider.token, rootPath: route.replace(provider.path, \"\")}));\n\n const spec = await generateSpec({\n tokens,\n ...conf,\n specPath,\n version,\n acceptMimes\n });\n\n this.#specs.set(conf.path, spec);\n }\n\n return this.#specs.get(conf.path);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { matchPath } from "..js";
1
+ import { matchPath } from "./matchPath.js";
2
2
  export function includeRoute(route, provider, conf) {
3
3
  const hidden = provider.store.get("hidden");
4
4
  const docs = provider.store.get("docs") || [];
@@ -1 +1 @@
1
- {"version":3,"file":"includeRoute.js","sourceRoot":"","sources":["../../../src/utils/includeRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,GAAG,CAAC;AAG5B,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,QAA4B,EAAE,IAAqB;IAC7F,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9C,MAAM,EAAC,GAAG,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IACjC,MAAM,KAAK,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,YAAY,IAAI,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAExE,IAAI,MAAM,EAAE;QACV,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,gBAAgB,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import {ControllerProvider} from \"@tsed/common\";\nimport {matchPath} from \".\";\nimport {SwaggerSettings} from \"..\";\n\nexport function includeRoute(route: string, provider: ControllerProvider, conf: SwaggerSettings): boolean {\n const hidden = provider.store.get(\"hidden\");\n const docs = provider.store.get(\"docs\") || [];\n const {doc, pathPatterns} = conf;\n const inDoc = doc && docs.indexOf(doc) > -1;\n const pathPatternMatch = pathPatterns && matchPath(route, pathPatterns);\n\n if (hidden) {\n return false;\n }\n\n if (!doc && !pathPatterns) {\n return true;\n }\n\n return !!(inDoc || pathPatternMatch);\n}\n"]}
1
+ {"version":3,"file":"includeRoute.js","sourceRoot":"","sources":["../../../src/utils/includeRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAGtC,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,QAA4B,EAAE,IAAqB;IAC7F,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9C,MAAM,EAAC,GAAG,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IACjC,MAAM,KAAK,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,MAAM,gBAAgB,GAAG,YAAY,IAAI,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAExE,IAAI,MAAM,EAAE;QACV,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,gBAAgB,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import {ControllerProvider} from \"@tsed/common\";\nimport {matchPath} from \"./matchPath\";\nimport {SwaggerSettings} from \"../interfaces/SwaggerSettings\";\n\nexport function includeRoute(route: string, provider: ControllerProvider, conf: SwaggerSettings): boolean {\n const hidden = provider.store.get(\"hidden\");\n const docs = provider.store.get(\"docs\") || [];\n const {doc, pathPatterns} = conf;\n const inDoc = doc && docs.indexOf(doc) > -1;\n const pathPatternMatch = pathPatterns && matchPath(route, pathPatterns);\n\n if (hidden) {\n return false;\n }\n\n if (!doc && !pathPatterns) {\n return true;\n }\n\n return !!(inDoc || pathPatternMatch);\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { OnRoutesInit, Configuration, InjectorService, OnReady, PlatformApplication } from "@tsed/common";
2
- import { SwaggerSettings } from "./interfaces";
2
+ import { SwaggerSettings } from "./interfaces/SwaggerSettings";
3
3
  import { SwaggerService } from "./services/SwaggerService";
4
4
  import { Env } from "@tsed/core";
5
5
  /**
@@ -1,5 +1,15 @@
1
- export * from "./services/SwaggerService";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
2
4
  export * from "./SwaggerModule";
3
- export * from "./interfaces";
4
5
  export * from "./decorators/docs";
5
6
  export * from "./decorators/hidden";
7
+ export * from "./interfaces/SwaggerSettings";
8
+ export * from "./interfaces/interfaces";
9
+ export * from "./middlewares/cssMiddleware";
10
+ export * from "./middlewares/indexMiddleware";
11
+ export * from "./middlewares/jsMiddleware";
12
+ export * from "./middlewares/redirectMiddleware";
13
+ export * from "./services/SwaggerService";
14
+ export * from "./utils/includeRoute";
15
+ export * from "./utils/matchPath";
@@ -79,9 +79,6 @@ export interface SwaggerSettingsBase {
79
79
  */
80
80
  pathPatterns?: string[];
81
81
  }
82
- /**
83
- * @deprecated Since 2021-09-03. Will be removed in v7.
84
- */
85
82
  export interface SwaggerOS2Settings extends SwaggerSettingsBase {
86
83
  specVersion?: OS2Versions;
87
84
  /**
@@ -6,4 +6,3 @@ declare global {
6
6
  }
7
7
  }
8
8
  }
9
- export * from "./SwaggerSettings";
@@ -11,18 +11,7 @@ export declare class SwaggerService {
11
11
  * Generate Spec for the given configuration
12
12
  * @returns {Spec}
13
13
  */
14
- getOpenAPISpec(conf: SwaggerOS3Settings): OpenSpec3;
15
- /**
16
- * @deprecated
17
- */
18
- getOpenAPISpec(conf: SwaggerOS2Settings): OpenSpec2;
19
- /**
20
- * @deprecated
21
- */
22
- getOpenAPISpec(conf: SwaggerSettings): OpenSpec2;
23
- /**
24
- * Return the global api information.
25
- */
26
- protected getDefaultSpec(conf: Partial<SwaggerSettings>): Partial<OpenSpec2 | OpenSpec3>;
27
- protected readSpecPath(path: string): any;
14
+ getOpenAPISpec(conf: SwaggerOS3Settings): Promise<OpenSpec3>;
15
+ getOpenAPISpec(conf: SwaggerOS2Settings): Promise<OpenSpec2>;
16
+ getOpenAPISpec(conf: SwaggerSettings): Promise<OpenSpec2>;
28
17
  }
@@ -1,3 +1,3 @@
1
1
  import { ControllerProvider } from "@tsed/common";
2
- import { SwaggerSettings } from "..";
2
+ import { SwaggerSettings } from "../interfaces/SwaggerSettings";
3
3
  export declare function includeRoute(route: string, provider: ControllerProvider, conf: SwaggerSettings): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/swagger",
3
- "version": "6.105.4",
3
+ "version": "6.107.1",
4
4
  "description": "Swagger package for Ts.ED framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -14,32 +14,35 @@
14
14
  "default": "./lib/esm/index.js"
15
15
  },
16
16
  "scripts": {
17
- "build": "yarn run build:esm && yarn run build:cjs && cp -r ./views ./lib/views",
17
+ "clean": "rm -rf lib",
18
+ "build": "yarn clean && yarn barrels && yarn run build:esm && yarn run build:cjs && cp -r ./views ./lib/views",
18
19
  "build:cjs": "tsc --build tsconfig.compile.json",
19
20
  "build:esm": "tsc --build tsconfig.compile.esm.json",
20
- "start": "ts-node -r tsconfig-paths/register test/app/index.ts"
21
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
22
+ "start": "ts-node -r tsconfig-paths/register test/app/index.ts",
23
+ "test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
21
24
  },
22
25
  "dependencies": {
23
- "@tsed/openspec": "6.105.4",
24
- "fs-extra": "9.0.1",
26
+ "@tsed/openspec": "6.107.1",
27
+ "fs-extra": "10.0.1",
25
28
  "micromatch": "4.0.4",
26
29
  "swagger-ui-dist": "^4.5.2",
27
30
  "tslib": "2.2.0"
28
31
  },
29
32
  "devDependencies": {
30
- "@tsed/common": "6.105.4",
31
- "@tsed/core": "6.105.4",
32
- "@tsed/di": "6.105.4",
33
- "@tsed/json-mapper": "6.105.4",
34
- "@tsed/openspec": "6.105.4",
35
- "@tsed/schema": "6.105.4",
33
+ "@tsed/common": "6.107.1",
34
+ "@tsed/core": "6.107.1",
35
+ "@tsed/di": "6.107.1",
36
+ "@tsed/json-mapper": "6.107.1",
37
+ "@tsed/openspec": "6.107.1",
38
+ "@tsed/schema": "6.107.1",
36
39
  "@types/swagger-ui-dist": ">=3.30.1"
37
40
  },
38
41
  "peerDependencies": {
39
- "@tsed/common": "^6.105.4",
40
- "@tsed/core": "^6.105.4",
41
- "@tsed/json-mapper": "^6.105.4",
42
- "@tsed/schema": "^6.105.4"
42
+ "@tsed/common": "^6.107.1",
43
+ "@tsed/core": "^6.107.1",
44
+ "@tsed/json-mapper": "^6.107.1",
45
+ "@tsed/schema": "^6.107.1"
43
46
  },
44
47
  "repository": "https://github.com/tsedio/tsed",
45
48
  "bugs": {
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./SwaggerSettings"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAUA,iEAAkC","sourcesContent":["import {SwaggerSettings} from \"./SwaggerSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n swagger: SwaggerSettings[];\n }\n }\n}\n\nexport * from \"./SwaggerSettings\";\n"]}
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSpecTypeFromSpec = exports.getSpecType = void 0;
4
- const schema_1 = require("@tsed/schema");
5
- /**
6
- * @ignore
7
- * @param version
8
- */
9
- function getSpecType(version) {
10
- return version.startsWith("3.") ? schema_1.SpecTypes.OPENAPI : schema_1.SpecTypes.SWAGGER;
11
- }
12
- exports.getSpecType = getSpecType;
13
- /**
14
- * @ignore
15
- * @param spec
16
- */
17
- function getSpecTypeFromSpec(spec) {
18
- return "openapi" in spec ? schema_1.SpecTypes.OPENAPI : schema_1.SpecTypes.SWAGGER;
19
- }
20
- exports.getSpecTypeFromSpec = getSpecTypeFromSpec;
21
- //# sourceMappingURL=getSpecType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSpecType.js","sourceRoot":"","sources":["../../../src/utils/getSpecType.ts"],"names":[],"mappings":";;;AACA,yCAAuC;AAEvC;;;GAGG;AACH,SAAgB,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAS,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAS,CAAC,OAAO,CAAC;AAC1E,CAAC;AAFD,kCAEC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,IAAoC;IACtE,OAAO,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,kBAAS,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAS,CAAC,OAAO,CAAC;AACnE,CAAC;AAFD,kDAEC","sourcesContent":["import {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"@tsed/schema\";\n\n/**\n * @ignore\n * @param version\n */\nexport function getSpecType(version: string) {\n return version.startsWith(\"3.\") ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n\n/**\n * @ignore\n * @param spec\n */\nexport function getSpecTypeFromSpec(spec: Partial<OpenSpec2 | OpenSpec3>) {\n return \"openapi\" in spec ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n"]}
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./getSpecType"), exports);
5
- (0, tslib_1.__exportStar)(require("./mapOpenSpec"), exports);
6
- (0, tslib_1.__exportStar)(require("./mapOpenSpec2"), exports);
7
- (0, tslib_1.__exportStar)(require("./mapOpenSpec3"), exports);
8
- (0, tslib_1.__exportStar)(require("./mapOpenSpecInfo"), exports);
9
- (0, tslib_1.__exportStar)(require("./mapOpenSpecInfo"), exports);
10
- (0, tslib_1.__exportStar)(require("./matchPath"), exports);
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,6DAA8B;AAC9B,6DAA8B;AAC9B,8DAA+B;AAC/B,8DAA+B;AAC/B,iEAAkC;AAClC,iEAAkC;AAClC,2DAA4B","sourcesContent":["export * from \"./getSpecType\";\nexport * from \"./mapOpenSpec\";\nexport * from \"./mapOpenSpec2\";\nexport * from \"./mapOpenSpec3\";\nexport * from \"./mapOpenSpecInfo\";\nexport * from \"./mapOpenSpecInfo\";\nexport * from \"./matchPath\";\n"]}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapOpenSpec = void 0;
4
- const core_1 = require("@tsed/core");
5
- const schema_1 = require("@tsed/schema");
6
- const getSpecType_1 = require("./getSpecType");
7
- const mapOpenSpec2_1 = require("./mapOpenSpec2");
8
- const mapOpenSpec3_1 = require("./mapOpenSpec3");
9
- /**
10
- * @ignore
11
- * @param spec
12
- * @param fileSpec
13
- * @param version
14
- * @param acceptMimes
15
- * @param specVersion
16
- */
17
- function mapOpenSpec(spec, { fileSpec, acceptMimes, specVersion, version }) {
18
- specVersion = specVersion || (0, core_1.getValue)(spec, "openapi", (0, core_1.getValue)(spec, "swagger", "2.0"));
19
- const options = {
20
- specVersion,
21
- acceptMimes
22
- };
23
- switch ((0, getSpecType_1.getSpecType)(specVersion)) {
24
- case schema_1.SpecTypes.OPENAPI:
25
- spec = (0, mapOpenSpec3_1.mapOpenSpec3)(spec, options);
26
- fileSpec = fileSpec ? (0, mapOpenSpec3_1.mapOpenSpec3)(fileSpec, options) : fileSpec;
27
- break;
28
- default:
29
- case schema_1.SpecTypes.SWAGGER:
30
- spec = (0, mapOpenSpec2_1.mapOpenSpec2)(spec, options);
31
- fileSpec = fileSpec ? (0, mapOpenSpec2_1.mapOpenSpec2)(fileSpec, options) : fileSpec;
32
- break;
33
- }
34
- spec = (0, schema_1.mergeSpec)(spec, fileSpec);
35
- (0, core_1.setValue)(spec, "info.title", (0, core_1.getValue)(spec, "info.title", "Api documentation"));
36
- (0, core_1.setValue)(spec, "info.version", (0, core_1.getValue)(spec, "info.version", version));
37
- return spec;
38
- }
39
- exports.mapOpenSpec = mapOpenSpec;
40
- //# sourceMappingURL=mapOpenSpec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapOpenSpec.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec.ts"],"names":[],"mappings":";;;AAAA,qCAA8C;AAE9C,yCAAkD;AAClD,+CAA0C;AAC1C,iDAA4C;AAC5C,iDAA4C;AAE5C;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAC,IAAS,EAAE,EAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAM;IACvF,WAAW,GAAG,WAAW,IAAI,IAAA,eAAQ,EAAmB,IAAI,EAAE,SAAS,EAAE,IAAA,eAAQ,EAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAE3G,MAAM,OAAO,GAAG;QACd,WAAW;QACX,WAAW;KACZ,CAAC;IAEF,QAAQ,IAAA,yBAAW,EAAC,WAAW,CAAC,EAAE;QAChC,KAAK,kBAAS,CAAC,OAAO;YACpB,IAAI,GAAG,IAAA,2BAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACnC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAA,2BAAY,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YACjE,MAAM;QACR,QAAQ;QACR,KAAK,kBAAS,CAAC,OAAO;YACpB,IAAI,GAAG,IAAA,2BAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACnC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAA,2BAAY,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YACjE,MAAM;KACT;IAED,IAAI,GAAG,IAAA,kBAAS,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEjC,IAAA,eAAQ,EAAC,IAAI,EAAE,YAAY,EAAE,IAAA,eAAQ,EAAC,IAAI,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAChF,IAAA,eAAQ,EAAC,IAAI,EAAE,cAAc,EAAE,IAAA,eAAQ,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAExE,OAAO,IAAI,CAAC;AACd,CAAC;AA1BD,kCA0BC","sourcesContent":["import {getValue, setValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3, OpenSpecVersions} from \"@tsed/openspec\";\nimport {mergeSpec, SpecTypes} from \"@tsed/schema\";\nimport {getSpecType} from \"./getSpecType\";\nimport {mapOpenSpec2} from \"./mapOpenSpec2\";\nimport {mapOpenSpec3} from \"./mapOpenSpec3\";\n\n/**\n * @ignore\n * @param spec\n * @param fileSpec\n * @param version\n * @param acceptMimes\n * @param specVersion\n */\nexport function mapOpenSpec(spec: any, {fileSpec, acceptMimes, specVersion, version}: any): Partial<OpenSpec2 | OpenSpec3> {\n specVersion = specVersion || getValue<OpenSpecVersions>(spec, \"openapi\", getValue(spec, \"swagger\", \"2.0\"));\n\n const options = {\n specVersion,\n acceptMimes\n };\n\n switch (getSpecType(specVersion)) {\n case SpecTypes.OPENAPI:\n spec = mapOpenSpec3(spec, options);\n fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;\n break;\n default:\n case SpecTypes.SWAGGER:\n spec = mapOpenSpec2(spec, options);\n fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;\n break;\n }\n\n spec = mergeSpec(spec, fileSpec);\n\n setValue(spec, \"info.title\", getValue(spec, \"info.title\", \"Api documentation\"));\n setValue(spec, \"info.version\", getValue(spec, \"info.version\", version));\n\n return spec;\n}\n"]}
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapOpenSpec2 = void 0;
4
- const core_1 = require("@tsed/core");
5
- const mapOpenSpecInfo_1 = require("./mapOpenSpecInfo");
6
- /**
7
- * @ignore
8
- * @param spec
9
- * @param version
10
- * @param specVersion
11
- * @param acceptMimes
12
- * @deprecated
13
- */
14
- function mapOpenSpec2(spec, { version, specVersion, acceptMimes = ["application/json"] }) {
15
- const { paths, security, tags, host, basePath, schemes, consumes = [], produces = ["application/json"], definitions, parameters, responses, securityDefinitions, externalDocs } = spec;
16
- return {
17
- swagger: specVersion,
18
- consumes: (0, core_1.uniq)([...acceptMimes, ...consumes]),
19
- produces: (0, core_1.uniq)([...produces]),
20
- info: (0, mapOpenSpecInfo_1.mapOpenSpecInfo)((0, core_1.getValue)(spec, "info", {})),
21
- paths,
22
- host,
23
- basePath,
24
- schemes,
25
- definitions,
26
- parameters,
27
- responses,
28
- security,
29
- securityDefinitions,
30
- tags,
31
- externalDocs
32
- };
33
- }
34
- exports.mapOpenSpec2 = mapOpenSpec2;
35
- //# sourceMappingURL=mapOpenSpec2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapOpenSpec2.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec2.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAE1C,uDAAkD;AAElD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,IAAwB,EACxB,EAAC,OAAO,EAAE,WAAW,EAAE,WAAW,GAAG,CAAC,kBAAkB,CAAC,EAAM;IAE/D,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,CAAC,kBAAkB,CAAC,EAC/B,WAAW,EACX,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,YAAY,EACb,GAAG,IAAI,CAAC;IAET,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,QAAQ,EAAE,IAAA,WAAI,EAAC,CAAC,GAAG,WAAW,EAAE,GAAG,QAAQ,CAAC,CAAC;QAC7C,QAAQ,EAAE,IAAA,WAAI,EAAS,CAAC,GAAG,QAAQ,CAAC,CAAC;QACrC,IAAI,EAAE,IAAA,iCAAe,EAAC,IAAA,eAAQ,EAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACjD,KAAK;QACL,IAAI;QACJ,QAAQ;QACR,OAAO;QACP,WAAW;QACX,UAAU;QACV,SAAS;QACT,QAAQ;QACR,mBAAmB;QACnB,IAAI;QACJ,YAAY;KACb,CAAC;AACJ,CAAC;AArCD,oCAqCC","sourcesContent":["import {getValue, uniq} from \"@tsed/core\";\nimport {OpenSpec2} from \"@tsed/openspec\";\nimport {mapOpenSpecInfo} from \"./mapOpenSpecInfo\";\n\n/**\n * @ignore\n * @param spec\n * @param version\n * @param specVersion\n * @param acceptMimes\n * @deprecated\n */\nexport function mapOpenSpec2(\n spec: Partial<OpenSpec2>,\n {version, specVersion, acceptMimes = [\"application/json\"]}: any\n): Partial<OpenSpec2> {\n const {\n paths,\n security,\n tags,\n host,\n basePath,\n schemes,\n consumes = [],\n produces = [\"application/json\"],\n definitions,\n parameters,\n responses,\n securityDefinitions,\n externalDocs\n } = spec;\n\n return {\n swagger: specVersion,\n consumes: uniq([...acceptMimes, ...consumes]),\n produces: uniq<string>([...produces]),\n info: mapOpenSpecInfo(getValue(spec, \"info\", {})),\n paths,\n host,\n basePath,\n schemes,\n definitions,\n parameters,\n responses,\n security,\n securityDefinitions,\n tags,\n externalDocs\n };\n}\n"]}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapOpenSpec3 = void 0;
4
- const core_1 = require("@tsed/core");
5
- const mapOpenSpecInfo_1 = require("./mapOpenSpecInfo");
6
- /**
7
- * @ignore
8
- * @param spec
9
- * @param version
10
- * @param specVersion
11
- */
12
- function mapOpenSpec3(spec, { specVersion }) {
13
- const { servers, paths, components, security, tags, externalDocs } = spec;
14
- return {
15
- openapi: specVersion,
16
- info: (0, mapOpenSpecInfo_1.mapOpenSpecInfo)((0, core_1.getValue)(spec, "info", {})),
17
- servers,
18
- paths,
19
- components,
20
- security,
21
- tags,
22
- externalDocs
23
- };
24
- }
25
- exports.mapOpenSpec3 = mapOpenSpec3;
26
- //# sourceMappingURL=mapOpenSpec3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapOpenSpec3.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec3.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,uDAAkD;AAElD;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,IAAS,EAAE,EAAC,WAAW,EAAM;IACxD,MAAM,EAAC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IAExE,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,IAAI,EAAE,IAAA,iCAAe,EAAC,IAAA,eAAQ,EAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACjD,OAAO;QACP,KAAK;QACL,UAAU;QACV,QAAQ;QACR,IAAI;QACJ,YAAY;KACb,CAAC;AACJ,CAAC;AAbD,oCAaC","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {OpenSpec3} from \"@tsed/openspec\";\nimport {mapOpenSpecInfo} from \"./mapOpenSpecInfo\";\n\n/**\n * @ignore\n * @param spec\n * @param version\n * @param specVersion\n */\nexport function mapOpenSpec3(spec: any, {specVersion}: any): Partial<OpenSpec3> {\n const {servers, paths, components, security, tags, externalDocs} = spec;\n\n return {\n openapi: specVersion,\n info: mapOpenSpecInfo(getValue(spec, \"info\", {})),\n servers,\n paths,\n components,\n security,\n tags,\n externalDocs\n };\n}\n"]}
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapOpenSpecInfo = void 0;
4
- const core_1 = require("@tsed/core");
5
- /**
6
- * @ignore
7
- * @param info
8
- */
9
- function mapOpenSpecInfo(info) {
10
- const { title, description, version, termsOfService, contact, license } = info;
11
- return (0, core_1.cleanObject)({
12
- version,
13
- title,
14
- description,
15
- termsOfService,
16
- contact,
17
- license
18
- });
19
- }
20
- exports.mapOpenSpecInfo = mapOpenSpecInfo;
21
- //# sourceMappingURL=mapOpenSpecInfo.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapOpenSpecInfo.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpecInfo.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAGvC;;;GAGG;AACH,SAAgB,eAAe,CAAC,IAA2B;IACzD,MAAM,EAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAC,GAAG,IAAI,CAAC;IAE7E,OAAO,IAAA,kBAAW,EAAC;QACjB,OAAO;QACP,KAAK;QACL,WAAW;QACX,cAAc;QACd,OAAO;QACP,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AAXD,0CAWC","sourcesContent":["import {cleanObject} from \"@tsed/core\";\nimport {OpenSpecInfo} from \"@tsed/openspec\";\n\n/**\n * @ignore\n * @param info\n */\nexport function mapOpenSpecInfo(info: Partial<OpenSpecInfo>): OpenSpecInfo {\n const {title, description, version, termsOfService, contact, license} = info;\n\n return cleanObject({\n version,\n title,\n description,\n termsOfService,\n contact,\n license\n });\n}\n"]}
@@ -1,2 +0,0 @@
1
- export * from "./SwaggerSettings.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAUA,cAAc,mBAAmB,CAAC","sourcesContent":["import {SwaggerSettings} from \"./SwaggerSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n swagger: SwaggerSettings[];\n }\n }\n}\n\nexport * from \"./SwaggerSettings\";\n"]}
@@ -1,16 +0,0 @@
1
- import { SpecTypes } from "@tsed/schema";
2
- /**
3
- * @ignore
4
- * @param version
5
- */
6
- export function getSpecType(version) {
7
- return version.startsWith("3.") ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;
8
- }
9
- /**
10
- * @ignore
11
- * @param spec
12
- */
13
- export function getSpecTypeFromSpec(spec) {
14
- return "openapi" in spec ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;
15
- }
16
- //# sourceMappingURL=getSpecType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSpecType.js","sourceRoot":"","sources":["../../../src/utils/getSpecType.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAoC;IACtE,OAAO,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;AACnE,CAAC","sourcesContent":["import {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"@tsed/schema\";\n\n/**\n * @ignore\n * @param version\n */\nexport function getSpecType(version: string) {\n return version.startsWith(\"3.\") ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n\n/**\n * @ignore\n * @param spec\n */\nexport function getSpecTypeFromSpec(spec: Partial<OpenSpec2 | OpenSpec3>) {\n return \"openapi\" in spec ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n"]}
@@ -1,8 +0,0 @@
1
- export * from "./getSpecType.js";
2
- export * from "./mapOpenSpec.js";
3
- export * from "./mapOpenSpec2.js";
4
- export * from "./mapOpenSpec3.js";
5
- export * from "./mapOpenSpecInfo.js";
6
- export * from "./mapOpenSpecInfo.js";
7
- export * from "./matchPath.js";
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./getSpecType\";\nexport * from \"./mapOpenSpec\";\nexport * from \"./mapOpenSpec2\";\nexport * from \"./mapOpenSpec3\";\nexport * from \"./mapOpenSpecInfo\";\nexport * from \"./mapOpenSpecInfo\";\nexport * from \"./matchPath\";\n"]}
@@ -1,36 +0,0 @@
1
- import { getValue, setValue } from "@tsed/core";
2
- import { mergeSpec, SpecTypes } from "@tsed/schema";
3
- import { getSpecType } from "./getSpecType.js";
4
- import { mapOpenSpec2 } from "./mapOpenSpec2.js";
5
- import { mapOpenSpec3 } from "./mapOpenSpec3.js";
6
- /**
7
- * @ignore
8
- * @param spec
9
- * @param fileSpec
10
- * @param version
11
- * @param acceptMimes
12
- * @param specVersion
13
- */
14
- export function mapOpenSpec(spec, { fileSpec, acceptMimes, specVersion, version }) {
15
- specVersion = specVersion || getValue(spec, "openapi", getValue(spec, "swagger", "2.0"));
16
- const options = {
17
- specVersion,
18
- acceptMimes
19
- };
20
- switch (getSpecType(specVersion)) {
21
- case SpecTypes.OPENAPI:
22
- spec = mapOpenSpec3(spec, options);
23
- fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;
24
- break;
25
- default:
26
- case SpecTypes.SWAGGER:
27
- spec = mapOpenSpec2(spec, options);
28
- fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;
29
- break;
30
- }
31
- spec = mergeSpec(spec, fileSpec);
32
- setValue(spec, "info.title", getValue(spec, "info.title", "Api documentation"));
33
- setValue(spec, "info.version", getValue(spec, "info.version", version));
34
- return spec;
35
- }
36
- //# sourceMappingURL=mapOpenSpec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapOpenSpec.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAC,SAAS,EAAE,SAAS,EAAC,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAS,EAAE,EAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAM;IACvF,WAAW,GAAG,WAAW,IAAI,QAAQ,CAAmB,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAE3G,MAAM,OAAO,GAAG;QACd,WAAW;QACX,WAAW;KACZ,CAAC;IAEF,QAAQ,WAAW,CAAC,WAAW,CAAC,EAAE;QAChC,KAAK,SAAS,CAAC,OAAO;YACpB,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACnC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YACjE,MAAM;QACR,QAAQ;QACR,KAAK,SAAS,CAAC,OAAO;YACpB,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACnC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YACjE,MAAM;KACT;IAED,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEjC,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAChF,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAExE,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import {getValue, setValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3, OpenSpecVersions} from \"@tsed/openspec\";\nimport {mergeSpec, SpecTypes} from \"@tsed/schema\";\nimport {getSpecType} from \"./getSpecType\";\nimport {mapOpenSpec2} from \"./mapOpenSpec2\";\nimport {mapOpenSpec3} from \"./mapOpenSpec3\";\n\n/**\n * @ignore\n * @param spec\n * @param fileSpec\n * @param version\n * @param acceptMimes\n * @param specVersion\n */\nexport function mapOpenSpec(spec: any, {fileSpec, acceptMimes, specVersion, version}: any): Partial<OpenSpec2 | OpenSpec3> {\n specVersion = specVersion || getValue<OpenSpecVersions>(spec, \"openapi\", getValue(spec, \"swagger\", \"2.0\"));\n\n const options = {\n specVersion,\n acceptMimes\n };\n\n switch (getSpecType(specVersion)) {\n case SpecTypes.OPENAPI:\n spec = mapOpenSpec3(spec, options);\n fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;\n break;\n default:\n case SpecTypes.SWAGGER:\n spec = mapOpenSpec2(spec, options);\n fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;\n break;\n }\n\n spec = mergeSpec(spec, fileSpec);\n\n setValue(spec, \"info.title\", getValue(spec, \"info.title\", \"Api documentation\"));\n setValue(spec, \"info.version\", getValue(spec, \"info.version\", version));\n\n return spec;\n}\n"]}
@@ -1,31 +0,0 @@
1
- import { getValue, uniq } from "@tsed/core";
2
- import { mapOpenSpecInfo } from "./mapOpenSpecInfo.js";
3
- /**
4
- * @ignore
5
- * @param spec
6
- * @param version
7
- * @param specVersion
8
- * @param acceptMimes
9
- * @deprecated
10
- */
11
- export function mapOpenSpec2(spec, { version, specVersion, acceptMimes = ["application/json"] }) {
12
- const { paths, security, tags, host, basePath, schemes, consumes = [], produces = ["application/json"], definitions, parameters, responses, securityDefinitions, externalDocs } = spec;
13
- return {
14
- swagger: specVersion,
15
- consumes: uniq([...acceptMimes, ...consumes]),
16
- produces: uniq([...produces]),
17
- info: mapOpenSpecInfo(getValue(spec, "info", {})),
18
- paths,
19
- host,
20
- basePath,
21
- schemes,
22
- definitions,
23
- parameters,
24
- responses,
25
- security,
26
- securityDefinitions,
27
- tags,
28
- externalDocs
29
- };
30
- }
31
- //# sourceMappingURL=mapOpenSpec2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapOpenSpec2.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,IAAI,EAAC,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAwB,EACxB,EAAC,OAAO,EAAE,WAAW,EAAE,WAAW,GAAG,CAAC,kBAAkB,CAAC,EAAM;IAE/D,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,CAAC,kBAAkB,CAAC,EAC/B,WAAW,EACX,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,YAAY,EACb,GAAG,IAAI,CAAC;IAET,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,QAAQ,EAAE,IAAI,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,QAAQ,CAAC,CAAC;QAC7C,QAAQ,EAAE,IAAI,CAAS,CAAC,GAAG,QAAQ,CAAC,CAAC;QACrC,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACjD,KAAK;QACL,IAAI;QACJ,QAAQ;QACR,OAAO;QACP,WAAW;QACX,UAAU;QACV,SAAS;QACT,QAAQ;QACR,mBAAmB;QACnB,IAAI;QACJ,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import {getValue, uniq} from \"@tsed/core\";\nimport {OpenSpec2} from \"@tsed/openspec\";\nimport {mapOpenSpecInfo} from \"./mapOpenSpecInfo\";\n\n/**\n * @ignore\n * @param spec\n * @param version\n * @param specVersion\n * @param acceptMimes\n * @deprecated\n */\nexport function mapOpenSpec2(\n spec: Partial<OpenSpec2>,\n {version, specVersion, acceptMimes = [\"application/json\"]}: any\n): Partial<OpenSpec2> {\n const {\n paths,\n security,\n tags,\n host,\n basePath,\n schemes,\n consumes = [],\n produces = [\"application/json\"],\n definitions,\n parameters,\n responses,\n securityDefinitions,\n externalDocs\n } = spec;\n\n return {\n swagger: specVersion,\n consumes: uniq([...acceptMimes, ...consumes]),\n produces: uniq<string>([...produces]),\n info: mapOpenSpecInfo(getValue(spec, \"info\", {})),\n paths,\n host,\n basePath,\n schemes,\n definitions,\n parameters,\n responses,\n security,\n securityDefinitions,\n tags,\n externalDocs\n };\n}\n"]}
@@ -1,22 +0,0 @@
1
- import { getValue } from "@tsed/core";
2
- import { mapOpenSpecInfo } from "./mapOpenSpecInfo.js";
3
- /**
4
- * @ignore
5
- * @param spec
6
- * @param version
7
- * @param specVersion
8
- */
9
- export function mapOpenSpec3(spec, { specVersion }) {
10
- const { servers, paths, components, security, tags, externalDocs } = spec;
11
- return {
12
- openapi: specVersion,
13
- info: mapOpenSpecInfo(getValue(spec, "info", {})),
14
- servers,
15
- paths,
16
- components,
17
- security,
18
- tags,
19
- externalDocs
20
- };
21
- }
22
- //# sourceMappingURL=mapOpenSpec3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapOpenSpec3.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAS,EAAE,EAAC,WAAW,EAAM;IACxD,MAAM,EAAC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IAExE,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACjD,OAAO;QACP,KAAK;QACL,UAAU;QACV,QAAQ;QACR,IAAI;QACJ,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {OpenSpec3} from \"@tsed/openspec\";\nimport {mapOpenSpecInfo} from \"./mapOpenSpecInfo\";\n\n/**\n * @ignore\n * @param spec\n * @param version\n * @param specVersion\n */\nexport function mapOpenSpec3(spec: any, {specVersion}: any): Partial<OpenSpec3> {\n const {servers, paths, components, security, tags, externalDocs} = spec;\n\n return {\n openapi: specVersion,\n info: mapOpenSpecInfo(getValue(spec, \"info\", {})),\n servers,\n paths,\n components,\n security,\n tags,\n externalDocs\n };\n}\n"]}
@@ -1,17 +0,0 @@
1
- import { cleanObject } from "@tsed/core";
2
- /**
3
- * @ignore
4
- * @param info
5
- */
6
- export function mapOpenSpecInfo(info) {
7
- const { title, description, version, termsOfService, contact, license } = info;
8
- return cleanObject({
9
- version,
10
- title,
11
- description,
12
- termsOfService,
13
- contact,
14
- license
15
- });
16
- }
17
- //# sourceMappingURL=mapOpenSpecInfo.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapOpenSpecInfo.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpecInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAGvC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAA2B;IACzD,MAAM,EAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAC,GAAG,IAAI,CAAC;IAE7E,OAAO,WAAW,CAAC;QACjB,OAAO;QACP,KAAK;QACL,WAAW;QACX,cAAc;QACd,OAAO;QACP,OAAO;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {cleanObject} from \"@tsed/core\";\nimport {OpenSpecInfo} from \"@tsed/openspec\";\n\n/**\n * @ignore\n * @param info\n */\nexport function mapOpenSpecInfo(info: Partial<OpenSpecInfo>): OpenSpecInfo {\n const {title, description, version, termsOfService, contact, license} = info;\n\n return cleanObject({\n version,\n title,\n description,\n termsOfService,\n contact,\n license\n });\n}\n"]}
@@ -1,12 +0,0 @@
1
- import { OpenSpec2, OpenSpec3 } from "@tsed/openspec";
2
- import { SpecTypes } from "@tsed/schema";
3
- /**
4
- * @ignore
5
- * @param version
6
- */
7
- export declare function getSpecType(version: string): SpecTypes.SWAGGER | SpecTypes.OPENAPI;
8
- /**
9
- * @ignore
10
- * @param spec
11
- */
12
- export declare function getSpecTypeFromSpec(spec: Partial<OpenSpec2 | OpenSpec3>): SpecTypes.SWAGGER | SpecTypes.OPENAPI;
@@ -1,7 +0,0 @@
1
- export * from "./getSpecType";
2
- export * from "./mapOpenSpec";
3
- export * from "./mapOpenSpec2";
4
- export * from "./mapOpenSpec3";
5
- export * from "./mapOpenSpecInfo";
6
- export * from "./mapOpenSpecInfo";
7
- export * from "./matchPath";
@@ -1,10 +0,0 @@
1
- import { OpenSpec2, OpenSpec3 } from "@tsed/openspec";
2
- /**
3
- * @ignore
4
- * @param spec
5
- * @param fileSpec
6
- * @param version
7
- * @param acceptMimes
8
- * @param specVersion
9
- */
10
- export declare function mapOpenSpec(spec: any, { fileSpec, acceptMimes, specVersion, version }: any): Partial<OpenSpec2 | OpenSpec3>;
@@ -1,10 +0,0 @@
1
- import { OpenSpec2 } from "@tsed/openspec";
2
- /**
3
- * @ignore
4
- * @param spec
5
- * @param version
6
- * @param specVersion
7
- * @param acceptMimes
8
- * @deprecated
9
- */
10
- export declare function mapOpenSpec2(spec: Partial<OpenSpec2>, { version, specVersion, acceptMimes }: any): Partial<OpenSpec2>;
@@ -1,8 +0,0 @@
1
- import { OpenSpec3 } from "@tsed/openspec";
2
- /**
3
- * @ignore
4
- * @param spec
5
- * @param version
6
- * @param specVersion
7
- */
8
- export declare function mapOpenSpec3(spec: any, { specVersion }: any): Partial<OpenSpec3>;
@@ -1,6 +0,0 @@
1
- import { OpenSpecInfo } from "@tsed/openspec";
2
- /**
3
- * @ignore
4
- * @param info
5
- */
6
- export declare function mapOpenSpecInfo(info: Partial<OpenSpecInfo>): OpenSpecInfo;