@tsed/swagger 6.87.1 → 6.89.0

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 (122) hide show
  1. package/lib/{SwaggerModule.d.ts → cjs/SwaggerModule.d.ts} +2 -0
  2. package/lib/cjs/SwaggerModule.js +135 -0
  3. package/lib/cjs/SwaggerModule.js.map +1 -0
  4. package/lib/{decorators → cjs/decorators}/docs.d.ts +0 -0
  5. package/lib/cjs/decorators/docs.js +18 -0
  6. package/lib/cjs/decorators/docs.js.map +1 -0
  7. package/lib/{decorators → cjs/decorators}/hidden.d.ts +0 -0
  8. package/lib/cjs/decorators/hidden.js +40 -0
  9. package/lib/cjs/decorators/hidden.js.map +1 -0
  10. package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
  11. package/lib/cjs/index.js +9 -0
  12. package/lib/cjs/index.js.map +1 -0
  13. package/lib/{interfaces → cjs/interfaces}/SwaggerSettings.d.ts +0 -0
  14. package/lib/cjs/interfaces/SwaggerSettings.js +3 -0
  15. package/lib/cjs/interfaces/SwaggerSettings.js.map +1 -0
  16. package/lib/{interfaces → cjs/interfaces}/index.d.ts +0 -0
  17. package/lib/cjs/interfaces/index.js +5 -0
  18. package/lib/cjs/interfaces/index.js.map +1 -0
  19. package/lib/{middlewares → cjs/middlewares}/cssMiddleware.d.ts +0 -0
  20. package/lib/cjs/middlewares/cssMiddleware.js +23 -0
  21. package/lib/cjs/middlewares/cssMiddleware.js.map +1 -0
  22. package/lib/{middlewares → cjs/middlewares}/indexMiddleware.d.ts +0 -0
  23. package/lib/cjs/middlewares/indexMiddleware.js +24 -0
  24. package/lib/cjs/middlewares/indexMiddleware.js.map +1 -0
  25. package/lib/{middlewares → cjs/middlewares}/jsMiddleware.d.ts +0 -0
  26. package/lib/cjs/middlewares/jsMiddleware.js +18 -0
  27. package/lib/cjs/middlewares/jsMiddleware.js.map +1 -0
  28. package/lib/{middlewares → cjs/middlewares}/redirectMiddleware.d.ts +0 -0
  29. package/lib/cjs/middlewares/redirectMiddleware.js +16 -0
  30. package/lib/cjs/middlewares/redirectMiddleware.js.map +1 -0
  31. package/lib/{services → cjs/services}/SwaggerService.d.ts +0 -0
  32. package/lib/cjs/services/SwaggerService.js +103 -0
  33. package/lib/cjs/services/SwaggerService.js.map +1 -0
  34. package/lib/{utils → cjs/utils}/getSpecType.d.ts +0 -0
  35. package/lib/cjs/utils/getSpecType.js +21 -0
  36. package/lib/cjs/utils/getSpecType.js.map +1 -0
  37. package/lib/{utils → cjs/utils}/includeRoute.d.ts +0 -0
  38. package/lib/cjs/utils/includeRoute.js +20 -0
  39. package/lib/cjs/utils/includeRoute.js.map +1 -0
  40. package/lib/{utils → cjs/utils}/index.d.ts +0 -0
  41. package/lib/cjs/utils/index.js +11 -0
  42. package/lib/cjs/utils/index.js.map +1 -0
  43. package/lib/{utils → cjs/utils}/mapOpenSpec.d.ts +0 -0
  44. package/lib/cjs/utils/mapOpenSpec.js +40 -0
  45. package/lib/cjs/utils/mapOpenSpec.js.map +1 -0
  46. package/lib/{utils → cjs/utils}/mapOpenSpec2.d.ts +0 -0
  47. package/lib/cjs/utils/mapOpenSpec2.js +34 -0
  48. package/lib/cjs/utils/mapOpenSpec2.js.map +1 -0
  49. package/lib/{utils → cjs/utils}/mapOpenSpec3.d.ts +0 -0
  50. package/lib/cjs/utils/mapOpenSpec3.js +26 -0
  51. package/lib/cjs/utils/mapOpenSpec3.js.map +1 -0
  52. package/lib/{utils → cjs/utils}/mapOpenSpecInfo.d.ts +0 -0
  53. package/lib/cjs/utils/mapOpenSpecInfo.js +21 -0
  54. package/lib/cjs/utils/mapOpenSpecInfo.js.map +1 -0
  55. package/lib/{utils → cjs/utils}/matchPath.d.ts +0 -0
  56. package/lib/cjs/utils/matchPath.js +10 -0
  57. package/lib/cjs/utils/matchPath.js.map +1 -0
  58. package/lib/esm/SwaggerModule.js +132 -0
  59. package/lib/esm/SwaggerModule.js.map +1 -0
  60. package/lib/esm/decorators/docs.js +14 -0
  61. package/lib/esm/decorators/docs.js.map +1 -0
  62. package/lib/esm/decorators/hidden.js +36 -0
  63. package/lib/esm/decorators/hidden.js.map +1 -0
  64. package/lib/esm/index.js +6 -0
  65. package/lib/esm/index.js.map +1 -0
  66. package/lib/esm/interfaces/SwaggerSettings.js +2 -0
  67. package/lib/esm/interfaces/SwaggerSettings.js.map +1 -0
  68. package/lib/esm/interfaces/index.js +2 -0
  69. package/lib/esm/interfaces/index.js.map +1 -0
  70. package/lib/esm/middlewares/cssMiddleware.js +18 -0
  71. package/lib/esm/middlewares/cssMiddleware.js.map +1 -0
  72. package/lib/esm/middlewares/indexMiddleware.js +20 -0
  73. package/lib/esm/middlewares/indexMiddleware.js.map +1 -0
  74. package/lib/esm/middlewares/jsMiddleware.js +13 -0
  75. package/lib/esm/middlewares/jsMiddleware.js.map +1 -0
  76. package/lib/esm/middlewares/redirectMiddleware.js +12 -0
  77. package/lib/esm/middlewares/redirectMiddleware.js.map +1 -0
  78. package/lib/esm/services/SwaggerService.js +100 -0
  79. package/lib/esm/services/SwaggerService.js.map +1 -0
  80. package/lib/esm/utils/getSpecType.js +16 -0
  81. package/lib/esm/utils/getSpecType.js.map +1 -0
  82. package/lib/esm/utils/includeRoute.js +16 -0
  83. package/lib/esm/utils/includeRoute.js.map +1 -0
  84. package/lib/esm/utils/index.js +8 -0
  85. package/lib/esm/utils/index.js.map +1 -0
  86. package/lib/esm/utils/mapOpenSpec.js +36 -0
  87. package/lib/esm/utils/mapOpenSpec.js.map +1 -0
  88. package/lib/esm/utils/mapOpenSpec2.js +30 -0
  89. package/lib/esm/utils/mapOpenSpec2.js.map +1 -0
  90. package/lib/esm/utils/mapOpenSpec3.js +22 -0
  91. package/lib/esm/utils/mapOpenSpec3.js.map +1 -0
  92. package/lib/esm/utils/mapOpenSpecInfo.js +17 -0
  93. package/lib/esm/utils/mapOpenSpecInfo.js.map +1 -0
  94. package/lib/esm/utils/matchPath.js +5 -0
  95. package/lib/esm/utils/matchPath.js.map +1 -0
  96. package/lib/types/SwaggerModule.d.ts +30 -0
  97. package/lib/types/decorators/docs.d.ts +10 -0
  98. package/lib/types/decorators/hidden.d.ts +32 -0
  99. package/lib/types/index.d.ts +5 -0
  100. package/lib/types/interfaces/SwaggerSettings.d.ts +99 -0
  101. package/lib/types/interfaces/index.d.ts +9 -0
  102. package/lib/types/middlewares/cssMiddleware.d.ts +6 -0
  103. package/lib/types/middlewares/indexMiddleware.d.ts +10 -0
  104. package/lib/types/middlewares/jsMiddleware.d.ts +6 -0
  105. package/lib/types/middlewares/redirectMiddleware.d.ts +6 -0
  106. package/lib/types/services/SwaggerService.d.ts +29 -0
  107. package/lib/types/utils/getSpecType.d.ts +12 -0
  108. package/lib/types/utils/includeRoute.d.ts +3 -0
  109. package/lib/types/utils/index.d.ts +7 -0
  110. package/lib/types/utils/mapOpenSpec.d.ts +10 -0
  111. package/lib/types/utils/mapOpenSpec2.d.ts +9 -0
  112. package/lib/types/utils/mapOpenSpec3.d.ts +8 -0
  113. package/lib/types/utils/mapOpenSpecInfo.d.ts +6 -0
  114. package/lib/types/utils/matchPath.d.ts +1 -0
  115. package/lib/views/index.ejs +145 -0
  116. package/lib/views/index.html +144 -0
  117. package/package.json +22 -18
  118. package/tsconfig.compile.esm.json +24 -0
  119. package/lib/index.js +0 -614
  120. package/lib/index.js.map +0 -1
  121. package/lib/index.modern.js +0 -608
  122. package/lib/index.modern.js.map +0 -1
@@ -0,0 +1,40 @@
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
@@ -0,0 +1 @@
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"]}
File without changes
@@ -0,0 +1,34 @@
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
+ */
13
+ function mapOpenSpec2(spec, { version, specVersion, acceptMimes = ["application/json"] }) {
14
+ const { paths, security, tags, host, basePath, schemes, consumes = [], produces = ["application/json"], definitions, parameters, responses, securityDefinitions, externalDocs } = spec;
15
+ return {
16
+ swagger: specVersion,
17
+ consumes: (0, core_1.uniq)([...acceptMimes, ...consumes]),
18
+ produces: (0, core_1.uniq)([...produces]),
19
+ info: (0, mapOpenSpecInfo_1.mapOpenSpecInfo)((0, core_1.getValue)(spec, "info", {})),
20
+ paths,
21
+ host,
22
+ basePath,
23
+ schemes,
24
+ definitions,
25
+ parameters,
26
+ responses,
27
+ security,
28
+ securityDefinitions,
29
+ tags,
30
+ externalDocs
31
+ };
32
+ }
33
+ exports.mapOpenSpec2 = mapOpenSpec2;
34
+ //# sourceMappingURL=mapOpenSpec2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOpenSpec2.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec2.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAE1C,uDAAkD;AAElD;;;;;;GAMG;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 */\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"]}
File without changes
@@ -0,0 +1,26 @@
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
@@ -0,0 +1 @@
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"]}
File without changes
@@ -0,0 +1,21 @@
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
@@ -0,0 +1 @@
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"]}
File without changes
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchPath = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const micromatch_1 = (0, tslib_1.__importDefault)(require("micromatch"));
6
+ function matchPath(path, patterns) {
7
+ return patterns && patterns.length ? micromatch_1.default.isMatch(path, patterns) : true;
8
+ }
9
+ exports.matchPath = matchPath;
10
+ //# sourceMappingURL=matchPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchPath.js","sourceRoot":"","sources":["../../../src/utils/matchPath.ts"],"names":[],"mappings":";;;;AAAA,yEAAoC;AAEpC,SAAgB,SAAS,CAAC,IAAY,EAAE,QAAmB;IACzD,OAAO,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAU,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjF,CAAC;AAFD,8BAEC","sourcesContent":["import micromatch from \"micromatch\";\n\nexport function matchPath(path: string, patterns?: string[]) {\n return patterns && patterns.length ? micromatch.isMatch(path, patterns) : true;\n}\n"]}
@@ -0,0 +1,132 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Configuration, Constant, Inject, InjectorService, Module, normalizePath, PlatformApplication, PlatformRouter, useCtxHandler } from "@tsed/common";
3
+ import Fs from "fs";
4
+ import { join } from "path";
5
+ import { cssMiddleware } from "./middlewares/cssMiddleware";
6
+ import { indexMiddleware } from "./middlewares/indexMiddleware";
7
+ import { jsMiddleware } from "./middlewares/jsMiddleware";
8
+ import { redirectMiddleware } from "./middlewares/redirectMiddleware";
9
+ import { SwaggerService } from "./services/SwaggerService";
10
+ import { Env } from "@tsed/core";
11
+ const swaggerUiPath = require("swagger-ui-dist").absolutePath();
12
+ /**
13
+ * @ignore
14
+ */
15
+ let SwaggerModule = class SwaggerModule {
16
+ constructor() {
17
+ this.loaded = false;
18
+ }
19
+ get settings() {
20
+ return [].concat(this.configuration.get("swagger")).filter((o) => !!o);
21
+ }
22
+ /**
23
+ *
24
+ */
25
+ $beforeRoutesInit() {
26
+ if (this.loaded) {
27
+ return;
28
+ }
29
+ const urls = this.getUrls();
30
+ this.settings.forEach((conf) => {
31
+ const { path = "/" } = conf;
32
+ this.app.get(path, useCtxHandler(redirectMiddleware(path)));
33
+ this.app.use(path, this.createRouter(conf, urls));
34
+ });
35
+ this.loaded = true;
36
+ }
37
+ $onReady() {
38
+ // istanbul ignore next
39
+ if (this.configuration.getBestHost) {
40
+ const host = this.configuration.getBestHost();
41
+ if (!host) {
42
+ return;
43
+ }
44
+ const displayLog = (conf) => {
45
+ const { path = "/", fileName = "swagger.json", doc } = conf;
46
+ let url = "/";
47
+ if (host) {
48
+ url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
49
+ }
50
+ this.injector.logger.info(`[${doc || "default"}] Swagger JSON is available on ${url}${normalizePath(path, fileName)}`);
51
+ this.injector.logger.info(`[${doc || "default"}] Swagger UI is available on ${url}${path}/`);
52
+ };
53
+ this.settings.forEach((conf) => {
54
+ displayLog(conf);
55
+ });
56
+ }
57
+ this.generateSpecFiles();
58
+ }
59
+ generateSpecFiles() {
60
+ return Promise.all(this.settings.map((conf) => {
61
+ const { outFile } = conf;
62
+ if (this.env === Env.PROD || outFile) {
63
+ const spec = this.swaggerService.getOpenAPISpec(conf);
64
+ if (outFile) {
65
+ return Fs.writeFile(outFile, JSON.stringify(spec, null, 2), { encoding: "utf8" }, () => { });
66
+ }
67
+ }
68
+ }));
69
+ }
70
+ getUrls() {
71
+ return this.settings.reduce((acc, conf) => {
72
+ const { path = "/", fileName = "swagger.json", doc, hidden } = conf;
73
+ if (!hidden) {
74
+ acc.push({ url: normalizePath(path, fileName), name: doc || path });
75
+ }
76
+ return acc;
77
+ }, []);
78
+ }
79
+ /**
80
+ *
81
+ * @param conf
82
+ * @param urls
83
+ */
84
+ createRouter(conf, urls) {
85
+ const { disableSpec = false, fileName = "swagger.json", cssPath, jsPath, viewPath = join(__dirname, "../views/index.ejs") } = conf;
86
+ const router = PlatformRouter.create(this.injector);
87
+ if (!disableSpec) {
88
+ router.get(normalizePath("/", fileName), useCtxHandler(this.middlewareSwaggerJson(conf)));
89
+ }
90
+ if (viewPath) {
91
+ if (cssPath) {
92
+ router.get("/main.css", useCtxHandler(cssMiddleware(cssPath)));
93
+ }
94
+ if (jsPath) {
95
+ router.get("/main.js", useCtxHandler(jsMiddleware(jsPath)));
96
+ }
97
+ router.get("/", useCtxHandler(indexMiddleware(viewPath, { urls, ...conf })));
98
+ router.statics("/", { root: swaggerUiPath });
99
+ }
100
+ return router;
101
+ }
102
+ middlewareSwaggerJson(conf) {
103
+ return (ctx) => {
104
+ ctx.response.status(200).body(this.swaggerService.getOpenAPISpec(conf));
105
+ };
106
+ }
107
+ };
108
+ __decorate([
109
+ Inject(),
110
+ __metadata("design:type", InjectorService)
111
+ ], SwaggerModule.prototype, "injector", void 0);
112
+ __decorate([
113
+ Inject(),
114
+ __metadata("design:type", PlatformApplication)
115
+ ], SwaggerModule.prototype, "app", void 0);
116
+ __decorate([
117
+ Configuration(),
118
+ __metadata("design:type", Object)
119
+ ], SwaggerModule.prototype, "configuration", void 0);
120
+ __decorate([
121
+ Inject(),
122
+ __metadata("design:type", SwaggerService)
123
+ ], SwaggerModule.prototype, "swaggerService", void 0);
124
+ __decorate([
125
+ Constant("env"),
126
+ __metadata("design:type", String)
127
+ ], SwaggerModule.prototype, "env", void 0);
128
+ SwaggerModule = __decorate([
129
+ Module()
130
+ ], SwaggerModule);
131
+ export { SwaggerModule };
132
+ //# sourceMappingURL=SwaggerModule.js.map
@@ -0,0 +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;AAE/B,MAAM,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,YAAY,EAAE,CAAC;AAEhE;;GAEG;AAEH,IAAa,aAAa,GAA1B,MAAa,aAAa;IAA1B;QAgBU,WAAM,GAAG,KAAK,CAAC;IAsHzB,CAAC;IApHC,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,iBAAiB;QACf,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO;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G,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;AApIC;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,CAsIzB;SAtIY,aAAa","sourcesContent":["import {\n BeforeRoutesInit,\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\";\n\nconst swaggerUiPath = require(\"swagger-ui-dist\").absolutePath();\n\n/**\n * @ignore\n */\n@Module()\nexport class SwaggerModule implements BeforeRoutesInit, 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 $beforeRoutesInit() {\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\n if (!host) {\n return;\n }\n\n const displayLog = (conf: SwaggerSettings) => {\n const {path = \"/\", fileName = \"swagger.json\", doc} = conf;\n\n let url = \"/\";\n\n if (host) {\n url = typeof host.port === \"number\" ? `${host.protocol}://${host.address}:${host.port}` : \"\";\n }\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 };\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"]}
@@ -0,0 +1,14 @@
1
+ import { StoreMerge } from "@tsed/core";
2
+ /**
3
+ * Set the type documentation for this class.
4
+ *
5
+ * See [swagger documentation](/tutorials/swagger.html)
6
+ *
7
+ * @decorator
8
+ * @swagger
9
+ * @param docs
10
+ */
11
+ export function Docs(...docs) {
12
+ return StoreMerge("docs", docs);
13
+ }
14
+ //# sourceMappingURL=docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/decorators/docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAC,GAAG,IAAc;IACpC,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import {StoreMerge} from \"@tsed/core\";\n\n/**\n * Set the type documentation for this class.\n *\n * See [swagger documentation](/tutorials/swagger.html)\n *\n * @decorator\n * @swagger\n * @param docs\n */\nexport function Docs(...docs: string[]) {\n return StoreMerge(\"docs\", docs);\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import { Hidden as H } from "@tsed/schema";
2
+ /**
3
+ * Disable documentation for the class and his endpoint.
4
+ *
5
+ * ````typescript
6
+ * @Controller('/')
7
+ * export class Ctrl {
8
+ *
9
+ * @Get('/')
10
+ * @Hidden()
11
+ * hiddenRoute(){
12
+ *
13
+ * }
14
+ * }
15
+ *
16
+ * @Controller('/')
17
+ * @Hidden()
18
+ * export class Ctrl {
19
+ * @Get('/')
20
+ * hiddenRoute() {
21
+ *
22
+ * }
23
+ * @Get('/2')
24
+ * hiddenRoute2() {
25
+ *
26
+ * }
27
+ * }
28
+ * ```
29
+ *
30
+ * @decorator
31
+ * @swagger
32
+ */
33
+ export function Hidden() {
34
+ return H();
35
+ }
36
+ //# sourceMappingURL=hidden.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hidden.js","sourceRoot":"","sources":["../../../src/decorators/hidden.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,IAAI,CAAC,EAAC,MAAM,cAAc,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,CAAC,EAAE,CAAC;AACb,CAAC","sourcesContent":["import {Hidden as H} from \"@tsed/schema\";\n\n/**\n * Disable documentation for the class and his endpoint.\n *\n * ````typescript\n * @Controller('/')\n * export class Ctrl {\n *\n * @Get('/')\n * @Hidden()\n * hiddenRoute(){\n *\n * }\n * }\n *\n * @Controller('/')\n * @Hidden()\n * export class Ctrl {\n * @Get('/')\n * hiddenRoute() {\n *\n * }\n * @Get('/2')\n * hiddenRoute2() {\n *\n * }\n * }\n * ```\n *\n * @decorator\n * @swagger\n */\nexport function Hidden() {\n return H();\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export * from "./services/SwaggerService";
2
+ export * from "./SwaggerModule";
3
+ export * from "./interfaces";
4
+ export * from "./decorators/docs";
5
+ export * from "./decorators/hidden";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SwaggerSettings.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,2 @@
1
+ export * from "./SwaggerSettings";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,18 @@
1
+ import Fs from "fs";
2
+ import { resolve } from "path";
3
+ /**
4
+ * @ignore
5
+ * @param path
6
+ */
7
+ export function cssMiddleware(path) {
8
+ return (ctx) => {
9
+ const content = Fs.readFileSync(resolve(path), { encoding: "utf8" });
10
+ ctx.response
11
+ .setHeaders({
12
+ "Content-Type": "text/css"
13
+ })
14
+ .status(200)
15
+ .body(content);
16
+ };
17
+ }
18
+ //# sourceMappingURL=cssMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cssMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/cssMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,CAAC,GAAoB,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;QACnE,GAAG,CAAC,QAAQ;aACT,UAAU,CAAC;YACV,cAAc,EAAE,UAAU;SAC3B,CAAC;aACD,MAAM,CAAC,GAAG,CAAC;aACX,IAAI,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {resolve} from \"path\";\n\n/**\n * @ignore\n * @param path\n */\nexport function cssMiddleware(path: string) {\n return (ctx: PlatformContext) => {\n const content = Fs.readFileSync(resolve(path), {encoding: \"utf8\"});\n ctx.response\n .setHeaders({\n \"Content-Type\": \"text/css\"\n })\n .status(200)\n .body(content);\n };\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @ignore
3
+ * @param viewPath
4
+ * @param conf
5
+ */
6
+ export function indexMiddleware(viewPath, conf) {
7
+ return async (ctx) => {
8
+ const { path = "/", options = {}, showExplorer, cssPath, jsPath, urls } = conf;
9
+ ctx.response.body(await ctx.response.render(viewPath, {
10
+ spec: {},
11
+ url: `${path}/swagger.json`,
12
+ urls,
13
+ showExplorer,
14
+ cssPath,
15
+ jsPath,
16
+ swaggerOptions: options
17
+ }));
18
+ };
19
+ }
20
+ //# sourceMappingURL=indexMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/indexMiddleware.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,IAAwC;IACxF,OAAO,KAAK,EAAE,GAAoB,EAAE,EAAE;QACpC,MAAM,EAAC,IAAI,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC;QAE7E,GAAG,CAAC,QAAQ,CAAC,IAAI,CACf,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE;YAClC,IAAI,EAAE,EAAE;YACR,GAAG,EAAE,GAAG,IAAI,eAAe;YAC3B,IAAI;YACJ,YAAY;YACZ,OAAO;YACP,MAAM;YACN,cAAc,EAAE,OAAO;SACxB,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport {SwaggerSettings} from \"../interfaces/SwaggerSettings\";\n\n/**\n * @ignore\n * @param viewPath\n * @param conf\n */\nexport function indexMiddleware(viewPath: string, conf: SwaggerSettings & {urls: string[]}) {\n return async (ctx: PlatformContext) => {\n const {path = \"/\", options = {}, showExplorer, cssPath, jsPath, urls} = conf;\n\n ctx.response.body(\n await ctx.response.render(viewPath, {\n spec: {},\n url: `${path}/swagger.json`,\n urls,\n showExplorer,\n cssPath,\n jsPath,\n swaggerOptions: options\n })\n );\n };\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import Fs from "fs";
2
+ import { resolve } from "path";
3
+ /**
4
+ * @ignore
5
+ * @param path
6
+ */
7
+ export function jsMiddleware(path) {
8
+ return (ctx) => {
9
+ const content = Fs.readFileSync(resolve(path), { encoding: "utf8" });
10
+ ctx.response.setHeaders({ "Content-Type": "application/javascript" }).status(200).body(content);
11
+ };
12
+ }
13
+ //# sourceMappingURL=jsMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/jsMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,CAAC,GAAoB,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;QACnE,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAC,cAAc,EAAE,wBAAwB,EAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChG,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {resolve} from \"path\";\n\n/**\n * @ignore\n * @param path\n */\nexport function jsMiddleware(path: string) {\n return (ctx: PlatformContext) => {\n const content = Fs.readFileSync(resolve(path), {encoding: \"utf8\"});\n ctx.response.setHeaders({\"Content-Type\": \"application/javascript\"}).status(200).body(content);\n };\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @ignore
3
+ * @param path
4
+ */
5
+ export function redirectMiddleware(path) {
6
+ return (ctx) => {
7
+ if (ctx.request.url === path && !ctx.request.url.match(/\/$/)) {
8
+ ctx.response.redirect(302, `${path}/`);
9
+ }
10
+ };
11
+ }
12
+ //# sourceMappingURL=redirectMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirectMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/redirectMiddleware.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,CAAC,GAAoB,EAAE,EAAE;QAC9B,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAC7D,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC;SACxC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\n\n/**\n * @ignore\n * @param path\n */\nexport function redirectMiddleware(path: string) {\n return (ctx: PlatformContext) => {\n if (ctx.request.url === path && !ctx.request.url.match(/\\/$/)) {\n ctx.response.redirect(302, `${path}/`);\n }\n };\n}\n"]}
@@ -0,0 +1,100 @@
1
+ var _SwaggerService_specs;
2
+ import { __classPrivateFieldGet, __decorate, __metadata, __param } from "tslib";
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";
8
+ import { includeRoute } from "../utils/includeRoute";
9
+ import { mapOpenSpec } from "../utils/mapOpenSpec";
10
+ let SwaggerService = class SwaggerService {
11
+ constructor(injectorService, platform, configuration) {
12
+ this.injectorService = injectorService;
13
+ this.platform = platform;
14
+ this.configuration = configuration;
15
+ _SwaggerService_specs.set(this, new Map());
16
+ }
17
+ getOpenAPISpec(conf) {
18
+ 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 = this.buildRoutes(provider, {
36
+ ...options,
37
+ rootPath: route.replace(provider.path, "")
38
+ });
39
+ options.append(spec);
40
+ }
41
+ });
42
+ __classPrivateFieldGet(this, _SwaggerService_specs, "f").set(conf.path, mergeSpec(defaultSpec, finalSpec));
43
+ }
44
+ return __classPrivateFieldGet(this, _SwaggerService_specs, "f").get(conf.path);
45
+ }
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
+ /**
72
+ *
73
+ * @param ctrl
74
+ * @param options
75
+ */
76
+ buildRoutes(ctrl, options) {
77
+ const rootPath = options.rootPath + ctrl.path;
78
+ ctrl.children
79
+ .map((ctrl) => this.injectorService.getProvider(ctrl))
80
+ .forEach((provider) => {
81
+ if (!provider.store.get("hidden")) {
82
+ const spec = this.buildRoutes(provider, {
83
+ ...options,
84
+ rootPath
85
+ });
86
+ options.append(spec);
87
+ }
88
+ });
89
+ return getSpec(ctrl.token, options);
90
+ }
91
+ };
92
+ _SwaggerService_specs = new WeakMap();
93
+ SwaggerService = __decorate([
94
+ Injectable(),
95
+ __param(2, Configuration()),
96
+ __metadata("design:paramtypes", [InjectorService,
97
+ Platform, Object])
98
+ ], SwaggerService);
99
+ export { SwaggerService };
100
+ //# sourceMappingURL=SwaggerService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwaggerService.js","sourceRoot":"","sources":["../../../src/services/SwaggerService.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,aAAa,EAAsB,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACtG,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAC,OAAO,EAAE,SAAS,EAAwB,MAAM,cAAc,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AC,IAAI,CAAC,CAAC;aACzB;SACF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;OAIG;IACO,WAAW,CAAC,IAAwB,EAAE,OAA8B;QAC5E,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;QAE9C,IAAI,CAAC,QAAQ;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;aACrD,OAAO,CAAC,CAAC,QAA4B,EAAE,EAAE;YACxC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;gBACjC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE;oBACtC,GAAG,OAAO;oBACV,QAAQ;iBACT,CAAC,CAAC;gBAEH,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aACtB;QACH,CAAC,CAAC,CAAC;QAEL,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;;AAvGY,cAAc;IAD1B,UAAU,EAAE;IAOR,WAAA,aAAa,EAAE,CAAA;qCAFS,eAAe;QACtB,QAAQ;GALjB,cAAc,CAuG1B;SAvGY,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 public getOpenAPISpec(conf: SwaggerOS2Settings): OpenSpec2;\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 = this.buildRoutes(provider, {\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 /**\n *\n * @param ctrl\n * @param options\n */\n protected buildRoutes(ctrl: ControllerProvider, options: SpecSerializerOptions) {\n const rootPath = options.rootPath + ctrl.path;\n\n ctrl.children\n .map((ctrl) => this.injectorService.getProvider(ctrl))\n .forEach((provider: ControllerProvider) => {\n if (!provider.store.get(\"hidden\")) {\n const spec = this.buildRoutes(provider, {\n ...options,\n rootPath\n });\n\n options.append(spec);\n }\n });\n\n return getSpec(ctrl.token, options);\n }\n}\n"]}