@tsed/swagger 7.0.0-beta.3 → 7.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +14 -0
- package/lib/cjs/SwaggerModule.js +18 -17
- package/lib/cjs/SwaggerModule.js.map +1 -1
- package/lib/cjs/index.js +15 -5
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/SwaggerSettings.js.map +1 -1
- package/lib/cjs/interfaces/interfaces.js +3 -0
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/cjs/middlewares/cssMiddleware.js +1 -1
- package/lib/cjs/middlewares/cssMiddleware.js.map +1 -1
- package/lib/cjs/middlewares/jsMiddleware.js +1 -1
- package/lib/cjs/middlewares/jsMiddleware.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/SwaggerService.js +19 -80
- package/lib/cjs/services/SwaggerService.js.map +1 -1
- package/lib/cjs/utils/includeRoute.js +2 -2
- package/lib/cjs/utils/includeRoute.js.map +1 -1
- package/lib/cjs/utils/matchPath.js +1 -1
- package/lib/cjs/utils/matchPath.js.map +1 -1
- package/lib/esm/SwaggerModule.js +11 -10
- package/lib/esm/SwaggerModule.js.map +1 -1
- package/lib/esm/index.js +15 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/SwaggerSettings.js.map +1 -1
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/SwaggerService.js +16 -77
- package/lib/esm/services/SwaggerService.js.map +1 -1
- package/lib/esm/utils/includeRoute.js +1 -1
- package/lib/esm/utils/includeRoute.js.map +1 -1
- package/lib/types/SwaggerModule.d.ts +2 -1
- package/lib/types/index.d.ts +12 -2
- package/lib/types/interfaces/SwaggerSettings.d.ts +9 -2
- package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +0 -1
- package/lib/types/services/SwaggerService.d.ts +6 -16
- package/lib/types/utils/includeRoute.d.ts +1 -1
- package/package.json +26 -20
- package/readme.md +71 -85
- package/lib/cjs/interfaces/index.js +0 -5
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/cjs/utils/index.js +0 -9
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/cjs/utils/mapOpenSpec.js +0 -29
- package/lib/cjs/utils/mapOpenSpec.js.map +0 -1
- package/lib/cjs/utils/mapOpenSpec3.js +0 -26
- package/lib/cjs/utils/mapOpenSpec3.js.map +0 -1
- package/lib/cjs/utils/mapOpenSpecInfo.js +0 -21
- package/lib/cjs/utils/mapOpenSpecInfo.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -2
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/esm/utils/index.js +0 -6
- package/lib/esm/utils/index.js.map +0 -1
- package/lib/esm/utils/mapOpenSpec.js +0 -25
- package/lib/esm/utils/mapOpenSpec.js.map +0 -1
- package/lib/esm/utils/mapOpenSpec3.js +0 -22
- package/lib/esm/utils/mapOpenSpec3.js.map +0 -1
- package/lib/esm/utils/mapOpenSpecInfo.js +0 -17
- package/lib/esm/utils/mapOpenSpecInfo.js.map +0 -1
- package/lib/types/utils/index.d.ts +0 -5
- package/lib/types/utils/mapOpenSpec.d.ts +0 -10
- package/lib/types/utils/mapOpenSpec3.d.ts +0 -8
- package/lib/types/utils/mapOpenSpecInfo.d.ts +0 -6
|
@@ -1,11 +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 {
|
|
5
|
-
import {
|
|
6
|
-
import Fs from "fs";
|
|
7
|
-
import { includeRoute } from "../utils/includeRoute";
|
|
8
|
-
import { mapOpenSpec } from "../utils/mapOpenSpec";
|
|
4
|
+
import { generateSpec } from "@tsed/schema";
|
|
5
|
+
import { includeRoute } from "../utils/includeRoute.js";
|
|
9
6
|
let SwaggerService = class SwaggerService {
|
|
10
7
|
constructor(injectorService, platform, configuration) {
|
|
11
8
|
this.injectorService = injectorService;
|
|
@@ -13,83 +10,25 @@ let SwaggerService = class SwaggerService {
|
|
|
13
10
|
this.configuration = configuration;
|
|
14
11
|
_SwaggerService_specs.set(this, new Map());
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
* Generate Spec for the given configuration
|
|
18
|
-
* @returns {Spec}
|
|
19
|
-
*/
|
|
20
|
-
getOpenAPISpec(conf) {
|
|
13
|
+
async getOpenAPISpec(conf) {
|
|
21
14
|
if (!__classPrivateFieldGet(this, _SwaggerService_specs, "f").has(conf.path)) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
this.platform.getMountedControllers().forEach(({ route, provider }) => {
|
|
36
|
-
if (includeRoute(route, provider, conf)) {
|
|
37
|
-
const spec = this.buildRoutes(provider, {
|
|
38
|
-
...options,
|
|
39
|
-
rootPath: route.replace(provider.path, "")
|
|
40
|
-
});
|
|
41
|
-
options.append(spec);
|
|
42
|
-
}
|
|
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
|
|
43
27
|
});
|
|
44
|
-
__classPrivateFieldGet(this, _SwaggerService_specs, "f").set(conf.path,
|
|
28
|
+
__classPrivateFieldGet(this, _SwaggerService_specs, "f").set(conf.path, spec);
|
|
45
29
|
}
|
|
46
30
|
return __classPrivateFieldGet(this, _SwaggerService_specs, "f").get(conf.path);
|
|
47
31
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Return the global api information.
|
|
50
|
-
*/
|
|
51
|
-
getDefaultSpec(conf) {
|
|
52
|
-
const { version = "1.0.0", acceptMimes } = this.configuration;
|
|
53
|
-
const { specPath, specVersion } = conf;
|
|
54
|
-
const fileSpec = specPath ? this.readSpecPath(specPath) : {};
|
|
55
|
-
return mapOpenSpec(getValue(conf, "spec", {}), {
|
|
56
|
-
fileSpec,
|
|
57
|
-
version,
|
|
58
|
-
specVersion,
|
|
59
|
-
acceptMimes
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
readSpecPath(path) {
|
|
63
|
-
path = this.configuration.resolve(path);
|
|
64
|
-
if (Fs.existsSync(path)) {
|
|
65
|
-
const json = Fs.readFileSync(path, { encoding: "utf8" });
|
|
66
|
-
/* istanbul ignore else */
|
|
67
|
-
if (json !== "") {
|
|
68
|
-
return JSON.parse(json);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return {};
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
* @param ctrl
|
|
76
|
-
* @param options
|
|
77
|
-
*/
|
|
78
|
-
buildRoutes(ctrl, options) {
|
|
79
|
-
const rootPath = options.rootPath + ctrl.path;
|
|
80
|
-
ctrl.children
|
|
81
|
-
.map((ctrl) => this.injectorService.getProvider(ctrl))
|
|
82
|
-
.forEach((provider) => {
|
|
83
|
-
if (!provider.store.get("hidden")) {
|
|
84
|
-
const spec = this.buildRoutes(provider, {
|
|
85
|
-
...options,
|
|
86
|
-
rootPath
|
|
87
|
-
});
|
|
88
|
-
options.append(spec);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return getSpec(ctrl.token, options);
|
|
92
|
-
}
|
|
93
32
|
};
|
|
94
33
|
_SwaggerService_specs = new WeakMap();
|
|
95
34
|
SwaggerService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwaggerService.js","sourceRoot":"","sources":["../../../src/services/SwaggerService.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,aAAa,
|
|
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,IAAI,GAAG,EAAE,EAAC;IAMpD,CAAC;IASG,KAAK,CAAC,cAAc,CAAC,IAAqB;QAC/C,IAAI,CAAC,uBAAA,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,YAAY,CAAC,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,YAAY,CAAC;gBAC9B,MAAM;gBACN,GAAG,IAAI;gBACP,QAAQ;gBACR,OAAO;gBACP,WAAW;aACZ,CAAC,CAAC;YAEH,uBAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SAClC;QAED,OAAO,uBAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"includeRoute.js","sourceRoot":"","sources":["../../../src/utils/includeRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,
|
|
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,4 +1,5 @@
|
|
|
1
1
|
import { OnRoutesInit, Configuration, InjectorService, OnReady, PlatformApplication } from "@tsed/common";
|
|
2
|
+
import { SwaggerSettings } from "./interfaces/SwaggerSettings";
|
|
2
3
|
import { SwaggerService } from "./services/SwaggerService";
|
|
3
4
|
import { Env } from "@tsed/core";
|
|
4
5
|
/**
|
|
@@ -11,7 +12,7 @@ export declare class SwaggerModule implements OnRoutesInit, OnReady {
|
|
|
11
12
|
swaggerService: SwaggerService;
|
|
12
13
|
env: Env;
|
|
13
14
|
private loaded;
|
|
14
|
-
get settings():
|
|
15
|
+
get settings(): SwaggerSettings[];
|
|
15
16
|
/**
|
|
16
17
|
*
|
|
17
18
|
*/
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
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";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenSpec3, OpenSpecVersions, OS3Versions } from "@tsed/openspec";
|
|
1
|
+
import { OpenSpec2, OpenSpec3, OpenSpecVersions, OS2Versions, OS3Versions } from "@tsed/openspec";
|
|
2
2
|
export interface SwaggerUIOptions {
|
|
3
3
|
configUrl?: string;
|
|
4
4
|
url?: string;
|
|
@@ -79,6 +79,13 @@ export interface SwaggerSettingsBase {
|
|
|
79
79
|
*/
|
|
80
80
|
pathPatterns?: string[];
|
|
81
81
|
}
|
|
82
|
+
export interface SwaggerOS2Settings extends SwaggerSettingsBase {
|
|
83
|
+
specVersion?: OS2Versions;
|
|
84
|
+
/**
|
|
85
|
+
* OpenSpec 2
|
|
86
|
+
*/
|
|
87
|
+
spec?: Partial<OpenSpec2>;
|
|
88
|
+
}
|
|
82
89
|
export interface SwaggerOS3Settings extends SwaggerSettingsBase {
|
|
83
90
|
specVersion?: OS3Versions;
|
|
84
91
|
/**
|
|
@@ -86,4 +93,4 @@ export interface SwaggerOS3Settings extends SwaggerSettingsBase {
|
|
|
86
93
|
*/
|
|
87
94
|
spec?: Partial<OpenSpec3>;
|
|
88
95
|
}
|
|
89
|
-
export declare type SwaggerSettings = SwaggerOS3Settings;
|
|
96
|
+
export declare type SwaggerSettings = SwaggerOS2Settings | SwaggerOS3Settings;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Configuration,
|
|
2
|
-
import { OpenSpec3 } from "@tsed/openspec";
|
|
3
|
-
import {
|
|
4
|
-
import { SwaggerSettings } from "../interfaces/SwaggerSettings";
|
|
1
|
+
import { Configuration, InjectorService, Platform } from "@tsed/common";
|
|
2
|
+
import { OpenSpec2, OpenSpec3 } from "@tsed/openspec";
|
|
3
|
+
import { SwaggerOS2Settings, SwaggerOS3Settings, SwaggerSettings } from "../interfaces/SwaggerSettings";
|
|
5
4
|
export declare class SwaggerService {
|
|
6
5
|
#private;
|
|
7
6
|
private injectorService;
|
|
@@ -12,16 +11,7 @@ export declare class SwaggerService {
|
|
|
12
11
|
* Generate Spec for the given configuration
|
|
13
12
|
* @returns {Spec}
|
|
14
13
|
*/
|
|
15
|
-
getOpenAPISpec(conf:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
protected getDefaultSpec(conf: Partial<SwaggerSettings>): Partial<OpenSpec3>;
|
|
20
|
-
protected readSpecPath(path: string): any;
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @param ctrl
|
|
24
|
-
* @param options
|
|
25
|
-
*/
|
|
26
|
-
protected buildRoutes(ctrl: ControllerProvider, options: SpecSerializerOptions): Partial<OpenSpec3<import("@tsed/openspec").OS3Schema>>;
|
|
14
|
+
getOpenAPISpec(conf: SwaggerOS3Settings): Promise<OpenSpec3>;
|
|
15
|
+
getOpenAPISpec(conf: SwaggerOS2Settings): Promise<OpenSpec2>;
|
|
16
|
+
getOpenAPISpec(conf: SwaggerSettings): Promise<OpenSpec2>;
|
|
27
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.
|
|
3
|
+
"version": "7.0.0-beta.6",
|
|
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,43 @@
|
|
|
13
14
|
"default": "./lib/esm/index.js"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
16
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
+
"@tsed/openspec": "7.0.0-beta.6",
|
|
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.
|
|
29
|
-
"@tsed/core": "7.0.0-beta.
|
|
30
|
-
"@tsed/di": "7.0.0-beta.
|
|
31
|
-
"@tsed/json-mapper": "7.0.0-beta.
|
|
32
|
-
"@tsed/openspec": "7.0.0-beta.
|
|
33
|
-
"@tsed/schema": "7.0.0-beta.
|
|
33
|
+
"@tsed/common": "7.0.0-beta.6",
|
|
34
|
+
"@tsed/core": "7.0.0-beta.6",
|
|
35
|
+
"@tsed/di": "7.0.0-beta.6",
|
|
36
|
+
"@tsed/json-mapper": "7.0.0-beta.6",
|
|
37
|
+
"@tsed/openspec": "7.0.0-beta.6",
|
|
38
|
+
"@tsed/schema": "7.0.0-beta.6",
|
|
39
|
+
"@types/swagger-ui-dist": ">=3.30.1"
|
|
34
40
|
},
|
|
35
41
|
"peerDependencies": {
|
|
36
|
-
"@tsed/common": "^7.0.0-beta.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"@tsed/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
"@tsed/common": "^7.0.0-beta.6"
|
|
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/
|
|
53
|
+
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/swagger",
|
|
48
54
|
"author": "Romain Lenzotti",
|
|
49
55
|
"license": "MIT"
|
|
50
56
|
}
|
package/readme.md
CHANGED
|
@@ -43,25 +43,22 @@ Then add the following configuration in your Server:
|
|
|
43
43
|
import {Configuration} from "@tsed/common";
|
|
44
44
|
import "@tsed/swagger"; // import swagger Ts.ED module
|
|
45
45
|
import {resolve} from "path";
|
|
46
|
-
const rootDir = resolve(__dirname)
|
|
47
46
|
|
|
48
47
|
@Configuration({
|
|
49
|
-
rootDir,
|
|
50
48
|
swagger: [
|
|
51
49
|
{
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
path: "/v2/docs",
|
|
51
|
+
specVersion: "2.0"
|
|
54
52
|
},
|
|
55
53
|
{
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
path: "/v3/docs",
|
|
55
|
+
specVersion: "3.0.1"
|
|
58
56
|
}
|
|
59
57
|
]
|
|
60
58
|
})
|
|
61
|
-
export class Server {
|
|
62
|
-
|
|
63
|
-
}
|
|
59
|
+
export class Server {}
|
|
64
60
|
```
|
|
61
|
+
|
|
65
62
|
> The path option for swagger will be used to expose the documentation (ex: http://localhost:8000/api-docs).
|
|
66
63
|
|
|
67
64
|
Normally, Swagger-ui is ready. You can start your server and check if it work fine.
|
|
@@ -72,21 +69,21 @@ Normally, Swagger-ui is ready. You can start your server and check if it work fi
|
|
|
72
69
|
|
|
73
70
|
Some options is available to configure Swagger-ui, Ts.ED and the default spec information.
|
|
74
71
|
|
|
75
|
-
Key
|
|
76
|
-
|
|
77
|
-
path
|
|
78
|
-
specVersion
|
|
79
|
-
doc
|
|
80
|
-
cssPath
|
|
81
|
-
jsPath
|
|
82
|
-
showExplorer
|
|
83
|
-
spec
|
|
84
|
-
specPath
|
|
85
|
-
outFile
|
|
86
|
-
hidden
|
|
87
|
-
options
|
|
88
|
-
operationIdFormatter | `(name: string, propertyKey: string, path: string) => string` | A function to generate the operationId.
|
|
89
|
-
operationIdPattern
|
|
72
|
+
| Key | Example | Description |
|
|
73
|
+
| -------------------- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
74
|
+
| path | `/api-doc` | The url subpath to access to the documentation. |
|
|
75
|
+
| specVersion | `2.0`, `3.0.1` | The spec version. |
|
|
76
|
+
| doc | `hidden-doc` | The documentation key used by `@Docs` decorator to create several swagger documentations. |
|
|
77
|
+
| cssPath | `${rootDir}/spec/style.css` | The path to the CSS file. |
|
|
78
|
+
| jsPath | `${rootDir}/spec/main.js` | The path to the JS file. |
|
|
79
|
+
| showExplorer | `true` | Display the search field in the navbar. |
|
|
80
|
+
| spec | `{swagger: "2.0"}` | The default information spec. |
|
|
81
|
+
| specPath | `${rootDir}/spec/swagger.base.json` | Load the base spec documentation from the specified path. |
|
|
82
|
+
| outFile | `${rootDir}/spec/swagger.json` | Write the `swagger.json` spec documentation on the specified path. |
|
|
83
|
+
| hidden | `true` | Hide the documentation in the dropdown explorer list. |
|
|
84
|
+
| options | Swagger-UI options | SwaggerUI options. See (https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md) |
|
|
85
|
+
| operationIdFormatter | `(name: string, propertyKey: string, path: string) => string` | A function to generate the operationId. |
|
|
86
|
+
| operationIdPattern | `%c_%m` | A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name). |
|
|
90
87
|
|
|
91
88
|
### Multi documentations
|
|
92
89
|
|
|
@@ -97,21 +94,18 @@ import {Configuration} from "@tsed/common";
|
|
|
97
94
|
import "@tsed/swagger"; // import swagger Ts.ED module
|
|
98
95
|
|
|
99
96
|
@Configuration({
|
|
100
|
-
rootDir: __dirname,
|
|
101
97
|
swagger: [
|
|
102
98
|
{
|
|
103
99
|
path: "/api-docs-v1",
|
|
104
|
-
doc:
|
|
100
|
+
doc: "api-v1"
|
|
105
101
|
},
|
|
106
102
|
{
|
|
107
103
|
path: "/api-docs-v2",
|
|
108
|
-
doc:
|
|
104
|
+
doc: "api-v2"
|
|
109
105
|
}
|
|
110
106
|
]
|
|
111
107
|
})
|
|
112
|
-
export class Server {
|
|
113
|
-
|
|
114
|
-
}
|
|
108
|
+
export class Server {}
|
|
115
109
|
```
|
|
116
110
|
|
|
117
111
|
Then use `@Docs` decorators on your controllers to specify where the controllers should be displayed.
|
|
@@ -120,19 +114,17 @@ Then use `@Docs` decorators on your controllers to specify where the controllers
|
|
|
120
114
|
import {Controller} from "@tsed/common";
|
|
121
115
|
import {Docs} from "@tsed/swagger";
|
|
122
116
|
|
|
123
|
-
@Controller(
|
|
124
|
-
@Docs(
|
|
125
|
-
export class CalendarCtrlV2 {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
@
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
```
|
|
117
|
+
@Controller("/calendars")
|
|
118
|
+
@Docs("api-v2") // display this controllers only for api-docs-v2
|
|
119
|
+
export class CalendarCtrlV2 {}
|
|
120
|
+
// OR
|
|
121
|
+
@Controller("/calendars")
|
|
122
|
+
@Docs("api-v2", "api-v1") // display this controllers for api-docs-v2 and api-docs-v1
|
|
123
|
+
export class CalendarCtrl {}
|
|
124
|
+
```
|
|
134
125
|
|
|
135
126
|
## Examples
|
|
127
|
+
|
|
136
128
|
#### Model documentation
|
|
137
129
|
|
|
138
130
|
One of the feature of Ts.ED is the model definition to serialize or deserialize a
|
|
@@ -162,57 +154,55 @@ import {BodyParams, Controller, Get, Post, QueryParams, Returns, ReturnsArray, D
|
|
|
162
154
|
import {Summary, Deprecated, Security} from "@tsed/swagger";
|
|
163
155
|
import {CalendarModel} from "../models/CalendarModel";
|
|
164
156
|
|
|
165
|
-
@Controller(
|
|
157
|
+
@Controller("/calendars")
|
|
166
158
|
export class Calendar {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
159
|
+
@Get("/:id")
|
|
160
|
+
@Summary("Summary of this route")
|
|
161
|
+
@Description("Description of this route")
|
|
162
|
+
@Returns(CalendarModel)
|
|
163
|
+
@Returns(404, {description: "Not found"})
|
|
164
|
+
async getCalendar(@QueryParams("id") id: string): Promise<CalendarModel> {
|
|
165
|
+
//...
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@Get("/v0/:id")
|
|
169
|
+
@Deprecated()
|
|
170
|
+
@Description("Deprecated route, use /rest/calendars/:id instead of.")
|
|
171
|
+
@Returns(CalendarModel)
|
|
172
|
+
@Returns(404, {description: "Not found"})
|
|
173
|
+
getCalendarDeprecated(@QueryParams("id") id: string): Promise<CalendarModel> {
|
|
174
|
+
//...
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@Get("/")
|
|
178
|
+
@Description("Description of this route")
|
|
179
|
+
@ReturnsArray(CalendarModel)
|
|
180
|
+
getCalendars(): Promise<CalendarModel[]> {
|
|
181
|
+
// ...
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@Post("/")
|
|
185
|
+
@Security("calendar_auth", "write:calendar", "read:calendar")
|
|
186
|
+
@Returns(CalendarModel)
|
|
187
|
+
async createCalendar(@BodyParams() body: any): Promise<CalendarModel> {
|
|
188
|
+
//...
|
|
189
|
+
}
|
|
198
190
|
}
|
|
199
191
|
```
|
|
192
|
+
|
|
200
193
|
::: warninig
|
|
201
194
|
To update the swagger.json you need to reload the server before.
|
|
202
195
|
:::
|
|
203
196
|
|
|
204
|
-
|
|
205
197
|
## Import Javascript
|
|
206
198
|
|
|
207
|
-
It possible to import a Javascript in the Swagger-ui documentation. This script let you customize the swagger-ui instance.
|
|
208
|
-
|
|
199
|
+
It possible to import a Javascript in the Swagger-ui documentation. This script let you customize the swagger-ui instance.
|
|
209
200
|
|
|
210
201
|
```typescript
|
|
211
202
|
import {Configuration} from "@tsed/common";
|
|
212
203
|
import "@tsed/swagger"; // import swagger Ts.ED module
|
|
213
204
|
|
|
214
205
|
@Configuration({
|
|
215
|
-
rootDir: __dirname,
|
|
216
206
|
swagger: [
|
|
217
207
|
{
|
|
218
208
|
path: "/api-docs",
|
|
@@ -220,9 +210,7 @@ import "@tsed/swagger"; // import swagger Ts.ED module
|
|
|
220
210
|
}
|
|
221
211
|
]
|
|
222
212
|
})
|
|
223
|
-
export class Server {
|
|
224
|
-
|
|
225
|
-
}
|
|
213
|
+
export class Server {}
|
|
226
214
|
```
|
|
227
215
|
|
|
228
216
|
In your JavaScript file, you can handle Swagger-ui configuration and the instance:
|
|
@@ -230,8 +218,8 @@ In your JavaScript file, you can handle Swagger-ui configuration and the instanc
|
|
|
230
218
|
```javascript
|
|
231
219
|
console.log(SwaggerUIBuilder.config); //Swagger-ui config
|
|
232
220
|
|
|
233
|
-
document.addEventListener(
|
|
234
|
-
|
|
221
|
+
document.addEventListener("swagger.init", (evt) => {
|
|
222
|
+
console.log(SwaggerUIBuilder.ui); //Swagger-ui instance
|
|
235
223
|
});
|
|
236
224
|
```
|
|
237
225
|
|
|
@@ -239,20 +227,18 @@ document.addEventListener('swagger.init', (evt) => {
|
|
|
239
227
|
|
|
240
228
|
See our documentation https://tsed.io/#/api/index
|
|
241
229
|
|
|
242
|
-
|
|
243
230
|
## Contributors
|
|
231
|
+
|
|
244
232
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
|
|
245
233
|
|
|
246
234
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
247
235
|
|
|
248
|
-
|
|
249
236
|
## Backers
|
|
250
237
|
|
|
251
238
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
252
239
|
|
|
253
240
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
254
241
|
|
|
255
|
-
|
|
256
242
|
## Sponsors
|
|
257
243
|
|
|
258
244
|
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 +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"]}
|
package/lib/cjs/utils/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
(0, tslib_1.__exportStar)(require("./mapOpenSpec"), exports);
|
|
5
|
-
(0, tslib_1.__exportStar)(require("./mapOpenSpec3"), exports);
|
|
6
|
-
(0, tslib_1.__exportStar)(require("./mapOpenSpecInfo"), exports);
|
|
7
|
-
(0, tslib_1.__exportStar)(require("./mapOpenSpecInfo"), exports);
|
|
8
|
-
(0, tslib_1.__exportStar)(require("./matchPath"), exports);
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,6DAA8B;AAC9B,8DAA+B;AAC/B,iEAAkC;AAClC,iEAAkC;AAClC,2DAA4B","sourcesContent":["export * from \"./mapOpenSpec\";\nexport * from \"./mapOpenSpec3\";\nexport * from \"./mapOpenSpecInfo\";\nexport * from \"./mapOpenSpecInfo\";\nexport * from \"./matchPath\";\n"]}
|