@tsed/swagger 7.0.0-beta.1 → 7.0.0-beta.12

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 (73) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/cjs/SwaggerModule.js +19 -22
  3. package/lib/cjs/SwaggerModule.js.map +1 -1
  4. package/lib/cjs/index.js +15 -5
  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/middlewares/cssMiddleware.js +1 -1
  10. package/lib/cjs/middlewares/cssMiddleware.js.map +1 -1
  11. package/lib/cjs/middlewares/jsMiddleware.js +1 -1
  12. package/lib/cjs/middlewares/jsMiddleware.js.map +1 -1
  13. package/lib/cjs/package.json +3 -0
  14. package/lib/cjs/services/SwaggerService.js +19 -78
  15. package/lib/cjs/services/SwaggerService.js.map +1 -1
  16. package/lib/cjs/utils/includeRoute.js +2 -2
  17. package/lib/cjs/utils/includeRoute.js.map +1 -1
  18. package/lib/cjs/utils/matchPath.js +1 -1
  19. package/lib/cjs/utils/matchPath.js.map +1 -1
  20. package/lib/esm/SwaggerModule.js +12 -15
  21. package/lib/esm/SwaggerModule.js.map +1 -1
  22. package/lib/esm/index.js +15 -5
  23. package/lib/esm/index.js.map +1 -1
  24. package/lib/esm/interfaces/SwaggerSettings.js.map +1 -1
  25. package/lib/esm/interfaces/interfaces.js +2 -0
  26. package/lib/esm/interfaces/interfaces.js.map +1 -0
  27. package/lib/esm/package.json +3 -0
  28. package/lib/esm/services/SwaggerService.js +16 -75
  29. package/lib/esm/services/SwaggerService.js.map +1 -1
  30. package/lib/esm/utils/includeRoute.js +1 -1
  31. package/lib/esm/utils/includeRoute.js.map +1 -1
  32. package/lib/types/SwaggerModule.d.ts +1 -1
  33. package/lib/types/index.d.ts +12 -2
  34. package/lib/types/interfaces/SwaggerSettings.d.ts +0 -3
  35. package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +0 -1
  36. package/lib/types/services/SwaggerService.d.ts +4 -22
  37. package/lib/types/utils/includeRoute.d.ts +1 -1
  38. package/package.json +30 -21
  39. package/readme.md +73 -86
  40. package/lib/cjs/interfaces/index.js +0 -5
  41. package/lib/cjs/interfaces/index.js.map +0 -1
  42. package/lib/cjs/utils/getSpecType.js +0 -21
  43. package/lib/cjs/utils/getSpecType.js.map +0 -1
  44. package/lib/cjs/utils/index.js +0 -11
  45. package/lib/cjs/utils/index.js.map +0 -1
  46. package/lib/cjs/utils/mapOpenSpec.js +0 -40
  47. package/lib/cjs/utils/mapOpenSpec.js.map +0 -1
  48. package/lib/cjs/utils/mapOpenSpec2.js +0 -35
  49. package/lib/cjs/utils/mapOpenSpec2.js.map +0 -1
  50. package/lib/cjs/utils/mapOpenSpec3.js +0 -26
  51. package/lib/cjs/utils/mapOpenSpec3.js.map +0 -1
  52. package/lib/cjs/utils/mapOpenSpecInfo.js +0 -21
  53. package/lib/cjs/utils/mapOpenSpecInfo.js.map +0 -1
  54. package/lib/esm/interfaces/index.js +0 -2
  55. package/lib/esm/interfaces/index.js.map +0 -1
  56. package/lib/esm/utils/getSpecType.js +0 -16
  57. package/lib/esm/utils/getSpecType.js.map +0 -1
  58. package/lib/esm/utils/index.js +0 -8
  59. package/lib/esm/utils/index.js.map +0 -1
  60. package/lib/esm/utils/mapOpenSpec.js +0 -36
  61. package/lib/esm/utils/mapOpenSpec.js.map +0 -1
  62. package/lib/esm/utils/mapOpenSpec2.js +0 -31
  63. package/lib/esm/utils/mapOpenSpec2.js.map +0 -1
  64. package/lib/esm/utils/mapOpenSpec3.js +0 -22
  65. package/lib/esm/utils/mapOpenSpec3.js.map +0 -1
  66. package/lib/esm/utils/mapOpenSpecInfo.js +0 -17
  67. package/lib/esm/utils/mapOpenSpecInfo.js.map +0 -1
  68. package/lib/types/utils/getSpecType.d.ts +0 -12
  69. package/lib/types/utils/index.d.ts +0 -7
  70. package/lib/types/utils/mapOpenSpec.d.ts +0 -10
  71. package/lib/types/utils/mapOpenSpec2.d.ts +0 -10
  72. package/lib/types/utils/mapOpenSpec3.d.ts +0 -8
  73. package/lib/types/utils/mapOpenSpecInfo.d.ts +0 -6
@@ -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"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -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";
8
- import { includeRoute } from "../utils/includeRoute";
9
- import { mapOpenSpec } from "../utils/mapOpenSpec";
4
+ import { generateSpec } from "@tsed/schema";
5
+ import { includeRoute } from "../utils/includeRoute.js";
10
6
  let SwaggerService = class SwaggerService {
11
7
  constructor(injectorService, platform, configuration) {
12
8
  this.injectorService = injectorService;
@@ -14,80 +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 = this.buildRoutes(provider, {
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
- /**
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
32
  };
92
33
  _SwaggerService_specs = new WeakMap();
93
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,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACtG,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAC,OAAO,EAAE,SAAS,EAAwB,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAC,mBAAmB,EAAC,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAGjD,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;IAeG,cAAc,CAAC,IAAqB;QACzC,IAAI,CAAC,uBAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAC/B,MAAM,WAAW,GAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACnD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;YAClD,IAAI,SAAS,GA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CAAC,CAAC;IACtC,CAAC;CACF,CAAA;;AA7GY,cAAc;IAD1B,UAAU,EAAE;IAOR,WAAA,aAAa,EAAE,CAAA;qCAFS,eAAe;QACtB,QAAQ;GALjB,cAAc,CA6G1B;SA7GY,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 = 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"]}
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,oBA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AC;IACpC,CAAC;CACF,CAAA;;AAvCY,cAAc;IAD1B,UAAU,EAAE;IAOR,WAAA,aAAa,EAAE,CAAA;qCAFS,eAAe;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 ".";
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";
@@ -1,6 +1,5 @@
1
- import { Configuration, ControllerProvider, InjectorService, Platform } from "@tsed/common";
1
+ import { Configuration, InjectorService, Platform } from "@tsed/common";
2
2
  import { OpenSpec2, OpenSpec3 } from "@tsed/openspec";
3
- import { SpecSerializerOptions } from "@tsed/schema";
4
3
  import { SwaggerOS2Settings, SwaggerOS3Settings, SwaggerSettings } from "../interfaces/SwaggerSettings";
5
4
  export declare class SwaggerService {
6
5
  #private;
@@ -12,24 +11,7 @@ export declare class SwaggerService {
12
11
  * Generate Spec for the given configuration
13
12
  * @returns {Spec}
14
13
  */
15
- getOpenAPISpec(conf: SwaggerOS3Settings): OpenSpec3;
16
- /**
17
- * @deprecated
18
- */
19
- getOpenAPISpec(conf: SwaggerOS2Settings): OpenSpec2;
20
- /**
21
- * @deprecated
22
- */
23
- getOpenAPISpec(conf: SwaggerSettings): OpenSpec2;
24
- /**
25
- * Return the global api information.
26
- */
27
- protected getDefaultSpec(conf: Partial<SwaggerSettings>): Partial<OpenSpec2 | OpenSpec3>;
28
- protected readSpecPath(path: string): any;
29
- /**
30
- *
31
- * @param ctrl
32
- * @param options
33
- */
34
- protected buildRoutes(ctrl: ControllerProvider, options: SpecSerializerOptions): Partial<OpenSpec2>;
14
+ getOpenAPISpec(conf: SwaggerOS3Settings): Promise<OpenSpec3>;
15
+ getOpenAPISpec(conf: SwaggerOS2Settings): Promise<OpenSpec2>;
16
+ getOpenAPISpec(conf: SwaggerSettings): Promise<OpenSpec2>;
35
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,10 +1,11 @@
1
1
  {
2
2
  "name": "@tsed/swagger",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.0-beta.12",
4
4
  "description": "Swagger package for Ts.ED framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/cjs/index.js",
8
+ "module": "./lib/esm/index.js",
8
9
  "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
10
11
  "types": "./lib/types/index.d.ts",
@@ -13,38 +14,46 @@
13
14
  "default": "./lib/esm/index.js"
14
15
  },
15
16
  "scripts": {
16
- "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",
17
19
  "build:cjs": "tsc --build tsconfig.compile.json",
18
20
  "build:esm": "tsc --build tsconfig.compile.esm.json",
19
- "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"
20
24
  },
21
25
  "dependencies": {
22
- "fs-extra": "9.0.1",
23
- "micromatch": "^4.0.2",
24
- "swagger-ui-dist": "^3.46.0",
25
- "tslib": "2.2.0"
26
+ "@tsed/openspec": "7.0.0-beta.12",
27
+ "fs-extra": "10.0.1",
28
+ "micromatch": "4.0.5",
29
+ "swagger-ui-dist": "^4.5.2",
30
+ "tslib": "2.3.1"
26
31
  },
27
32
  "devDependencies": {
28
- "@tsed/common": "7.0.0-beta.1",
29
- "@tsed/core": "7.0.0-beta.1",
30
- "@tsed/di": "7.0.0-beta.1",
31
- "@tsed/json-mapper": "7.0.0-beta.1",
32
- "@tsed/openspec": "7.0.0-beta.1",
33
- "@tsed/schema": "7.0.0-beta.1"
33
+ "@tsed/common": "7.0.0-beta.12",
34
+ "@tsed/core": "7.0.0-beta.12",
35
+ "@tsed/di": "7.0.0-beta.12",
36
+ "@tsed/json-mapper": "7.0.0-beta.12",
37
+ "@tsed/openspec": "7.0.0-beta.12",
38
+ "@tsed/schema": "7.0.0-beta.12",
39
+ "@types/swagger-ui-dist": ">=3.30.1"
34
40
  },
35
41
  "peerDependencies": {
36
- "@tsed/common": "^7.0.0-beta.1",
37
- "@tsed/core": "^7.0.0-beta.1",
38
- "@tsed/di": "^7.0.0-beta.1",
39
- "@tsed/json-mapper": "^7.0.0-beta.1",
40
- "@tsed/openspec": "^7.0.0-beta.1",
41
- "@tsed/schema": "^7.0.0-beta.1"
42
+ "@tsed/common": "^7.0.0-beta.12"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "@tsed/common": {
46
+ "optional": false
47
+ }
42
48
  },
43
49
  "repository": "https://github.com/tsedio/tsed",
44
50
  "bugs": {
45
51
  "url": "https://github.com/tsedio/tsed/issues"
46
52
  },
47
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/specs/swagger",
53
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/specs/swagger",
48
54
  "author": "Romain Lenzotti",
49
- "license": "MIT"
55
+ "license": "MIT",
56
+ "publishConfig": {
57
+ "tag": "beta"
58
+ }
50
59
  }
package/readme.md CHANGED
@@ -11,7 +11,8 @@
11
11
  [![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
12
12
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
13
13
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
14
- [![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed)
14
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
15
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
15
16
 
16
17
  </div>
17
18
 
@@ -43,25 +44,22 @@ Then add the following configuration in your Server:
43
44
  import {Configuration} from "@tsed/common";
44
45
  import "@tsed/swagger"; // import swagger Ts.ED module
45
46
  import {resolve} from "path";
46
- const rootDir = resolve(__dirname)
47
47
 
48
48
  @Configuration({
49
- rootDir,
50
49
  swagger: [
51
50
  {
52
- path: "/v2/docs",
53
- specVersion: "2.0"
51
+ path: "/v2/docs",
52
+ specVersion: "2.0"
54
53
  },
55
54
  {
56
- path: "/v3/docs",
57
- specVersion: "3.0.1"
55
+ path: "/v3/docs",
56
+ specVersion: "3.0.1"
58
57
  }
59
58
  ]
60
59
  })
61
- export class Server {
62
-
63
- }
60
+ export class Server {}
64
61
  ```
62
+
65
63
  > The path option for swagger will be used to expose the documentation (ex: http://localhost:8000/api-docs).
66
64
 
67
65
  Normally, Swagger-ui is ready. You can start your server and check if it work fine.
@@ -72,21 +70,21 @@ Normally, Swagger-ui is ready. You can start your server and check if it work fi
72
70
 
73
71
  Some options is available to configure Swagger-ui, Ts.ED and the default spec information.
74
72
 
75
- Key | Example | Description
76
- ---|---|---
77
- path | `/api-doc` | The url subpath to access to the documentation.
78
- specVersion | `2.0`, `3.0.1` | The spec version.
79
- doc | `hidden-doc` | The documentation key used by `@Docs` decorator to create several swagger documentations.
80
- cssPath | `${rootDir}/spec/style.css` | The path to the CSS file.
81
- jsPath | `${rootDir}/spec/main.js` | The path to the JS file.
82
- showExplorer | `true` | Display the search field in the navbar.
83
- spec | `{swagger: "2.0"}` | The default information spec.
84
- specPath | `${rootDir}/spec/swagger.base.json` | Load the base spec documentation from the specified path.
85
- outFile | `${rootDir}/spec/swagger.json` | Write the `swagger.json` spec documentation on the specified path.
86
- hidden | `true` | Hide the documentation in the dropdown explorer list.
87
- options | Swagger-UI options | SwaggerUI options. See (https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md)
88
- operationIdFormatter | `(name: string, propertyKey: string, path: string) => string` | A function to generate the operationId.
89
- operationIdPattern | `%c_%m` | A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name).
73
+ | Key | Example | Description |
74
+ | -------------------- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
75
+ | path | `/api-doc` | The url subpath to access to the documentation. |
76
+ | specVersion | `2.0`, `3.0.1` | The spec version. |
77
+ | doc | `hidden-doc` | The documentation key used by `@Docs` decorator to create several swagger documentations. |
78
+ | cssPath | `${rootDir}/spec/style.css` | The path to the CSS file. |
79
+ | jsPath | `${rootDir}/spec/main.js` | The path to the JS file. |
80
+ | showExplorer | `true` | Display the search field in the navbar. |
81
+ | spec | `{swagger: "2.0"}` | The default information spec. |
82
+ | specPath | `${rootDir}/spec/swagger.base.json` | Load the base spec documentation from the specified path. |
83
+ | outFile | `${rootDir}/spec/swagger.json` | Write the `swagger.json` spec documentation on the specified path. |
84
+ | hidden | `true` | Hide the documentation in the dropdown explorer list. |
85
+ | options | Swagger-UI options | SwaggerUI options. See (https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md) |
86
+ | operationIdFormatter | `(name: string, propertyKey: string, path: string) => string` | A function to generate the operationId. |
87
+ | operationIdPattern | `%c_%m` | A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name). |
90
88
 
91
89
  ### Multi documentations
92
90
 
@@ -97,21 +95,18 @@ import {Configuration} from "@tsed/common";
97
95
  import "@tsed/swagger"; // import swagger Ts.ED module
98
96
 
99
97
  @Configuration({
100
- rootDir: __dirname,
101
98
  swagger: [
102
99
  {
103
100
  path: "/api-docs-v1",
104
- doc: 'api-v1'
101
+ doc: "api-v1"
105
102
  },
106
103
  {
107
104
  path: "/api-docs-v2",
108
- doc: 'api-v2'
105
+ doc: "api-v2"
109
106
  }
110
107
  ]
111
108
  })
112
- export class Server {
113
-
114
- }
109
+ export class Server {}
115
110
  ```
116
111
 
117
112
  Then use `@Docs` decorators on your controllers to specify where the controllers should be displayed.
@@ -120,19 +115,17 @@ Then use `@Docs` decorators on your controllers to specify where the controllers
120
115
  import {Controller} from "@tsed/common";
121
116
  import {Docs} from "@tsed/swagger";
122
117
 
123
- @Controller('/calendars')
124
- @Docs('api-v2') // display this controllers only for api-docs-v2
125
- export class CalendarCtrlV2 {
126
- }
127
- // OR
128
- @Controller('/calendars')
129
- @Docs('api-v2', 'api-v1') // display this controllers for api-docs-v2 and api-docs-v1
130
- export class CalendarCtrl {
131
-
132
- }
133
- ```
118
+ @Controller("/calendars")
119
+ @Docs("api-v2") // display this controllers only for api-docs-v2
120
+ export class CalendarCtrlV2 {}
121
+ // OR
122
+ @Controller("/calendars")
123
+ @Docs("api-v2", "api-v1") // display this controllers for api-docs-v2 and api-docs-v1
124
+ export class CalendarCtrl {}
125
+ ```
134
126
 
135
127
  ## Examples
128
+
136
129
  #### Model documentation
137
130
 
138
131
  One of the feature of Ts.ED is the model definition to serialize or deserialize a
@@ -162,57 +155,55 @@ import {BodyParams, Controller, Get, Post, QueryParams, Returns, ReturnsArray, D
162
155
  import {Summary, Deprecated, Security} from "@tsed/swagger";
163
156
  import {CalendarModel} from "../models/CalendarModel";
164
157
 
165
- @Controller('/calendars')
158
+ @Controller("/calendars")
166
159
  export class Calendar {
167
- @Get('/:id')
168
- @Summary("Summary of this route")
169
- @Description("Description of this route")
170
- @Returns(CalendarModel)
171
- @Returns(404, {description: "Not found"})
172
- async getCalendar(@QueryParams('id') id: string): Promise<CalendarModel> {
173
- //...
174
- }
175
-
176
- @Get('/v0/:id')
177
- @Deprecated()
178
- @Description("Deprecated route, use /rest/calendars/:id instead of.")
179
- @Returns(CalendarModel)
180
- @Returns(404, {description: "Not found"})
181
- getCalendarDeprecated(@QueryParams('id') id: string): Promise<CalendarModel> {
182
- //...
183
- }
184
-
185
- @Get('/')
186
- @Description("Description of this route")
187
- @ReturnsArray(CalendarModel)
188
- getCalendars(): Promise<CalendarModel[]> {
189
- // ...
190
- }
191
-
192
- @Post('/')
193
- @Security("calendar_auth", "write:calendar", "read:calendar")
194
- @Returns(CalendarModel)
195
- async createCalendar(@BodyParams() body: any): Promise<CalendarModel> {
196
- //...
197
- }
160
+ @Get("/:id")
161
+ @Summary("Summary of this route")
162
+ @Description("Description of this route")
163
+ @Returns(CalendarModel)
164
+ @Returns(404, {description: "Not found"})
165
+ async getCalendar(@QueryParams("id") id: string): Promise<CalendarModel> {
166
+ //...
167
+ }
168
+
169
+ @Get("/v0/:id")
170
+ @Deprecated()
171
+ @Description("Deprecated route, use /rest/calendars/:id instead of.")
172
+ @Returns(CalendarModel)
173
+ @Returns(404, {description: "Not found"})
174
+ getCalendarDeprecated(@QueryParams("id") id: string): Promise<CalendarModel> {
175
+ //...
176
+ }
177
+
178
+ @Get("/")
179
+ @Description("Description of this route")
180
+ @ReturnsArray(CalendarModel)
181
+ getCalendars(): Promise<CalendarModel[]> {
182
+ // ...
183
+ }
184
+
185
+ @Post("/")
186
+ @Security("calendar_auth", "write:calendar", "read:calendar")
187
+ @Returns(CalendarModel)
188
+ async createCalendar(@BodyParams() body: any): Promise<CalendarModel> {
189
+ //...
190
+ }
198
191
  }
199
192
  ```
193
+
200
194
  ::: warninig
201
195
  To update the swagger.json you need to reload the server before.
202
196
  :::
203
197
 
204
-
205
198
  ## Import Javascript
206
199
 
207
- It possible to import a Javascript in the Swagger-ui documentation. This script let you customize the swagger-ui instance.
208
-
200
+ It possible to import a Javascript in the Swagger-ui documentation. This script let you customize the swagger-ui instance.
209
201
 
210
202
  ```typescript
211
203
  import {Configuration} from "@tsed/common";
212
204
  import "@tsed/swagger"; // import swagger Ts.ED module
213
205
 
214
206
  @Configuration({
215
- rootDir: __dirname,
216
207
  swagger: [
217
208
  {
218
209
  path: "/api-docs",
@@ -220,9 +211,7 @@ import "@tsed/swagger"; // import swagger Ts.ED module
220
211
  }
221
212
  ]
222
213
  })
223
- export class Server {
224
-
225
- }
214
+ export class Server {}
226
215
  ```
227
216
 
228
217
  In your JavaScript file, you can handle Swagger-ui configuration and the instance:
@@ -230,8 +219,8 @@ In your JavaScript file, you can handle Swagger-ui configuration and the instanc
230
219
  ```javascript
231
220
  console.log(SwaggerUIBuilder.config); //Swagger-ui config
232
221
 
233
- document.addEventListener('swagger.init', (evt) => {
234
- console.log(SwaggerUIBuilder.ui); //Swagger-ui instance
222
+ document.addEventListener("swagger.init", (evt) => {
223
+ console.log(SwaggerUIBuilder.ui); //Swagger-ui instance
235
224
  });
236
225
  ```
237
226
 
@@ -239,20 +228,18 @@ document.addEventListener('swagger.init', (evt) => {
239
228
 
240
229
  See our documentation https://tsed.io/#/api/index
241
230
 
242
-
243
231
  ## Contributors
232
+
244
233
  Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
245
234
 
246
235
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
247
236
 
248
-
249
237
  ## Backers
250
238
 
251
239
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
252
240
 
253
241
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
254
242
 
255
-
256
243
  ## Sponsors
257
244
 
258
245
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
@@ -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