@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.
- package/jest.config.js +14 -0
- package/lib/cjs/SwaggerModule.js +19 -22
- 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 -78
- 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 +12 -15
- 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 -75
- 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 +1 -1
- package/lib/types/index.d.ts +12 -2
- package/lib/types/interfaces/SwaggerSettings.d.ts +0 -3
- package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +0 -1
- package/lib/types/services/SwaggerService.d.ts +4 -22
- package/lib/types/utils/includeRoute.d.ts +1 -1
- package/package.json +30 -21
- package/readme.md +73 -86
- package/lib/cjs/interfaces/index.js +0 -5
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/cjs/utils/getSpecType.js +0 -21
- package/lib/cjs/utils/getSpecType.js.map +0 -1
- package/lib/cjs/utils/index.js +0 -11
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/cjs/utils/mapOpenSpec.js +0 -40
- package/lib/cjs/utils/mapOpenSpec.js.map +0 -1
- package/lib/cjs/utils/mapOpenSpec2.js +0 -35
- package/lib/cjs/utils/mapOpenSpec2.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/getSpecType.js +0 -16
- package/lib/esm/utils/getSpecType.js.map +0 -1
- package/lib/esm/utils/index.js +0 -8
- package/lib/esm/utils/index.js.map +0 -1
- package/lib/esm/utils/mapOpenSpec.js +0 -36
- package/lib/esm/utils/mapOpenSpec.js.map +0 -1
- package/lib/esm/utils/mapOpenSpec2.js +0 -31
- package/lib/esm/utils/mapOpenSpec2.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/getSpecType.d.ts +0 -12
- package/lib/types/utils/index.d.ts +0 -7
- package/lib/types/utils/mapOpenSpec.d.ts +0 -10
- package/lib/types/utils/mapOpenSpec2.d.ts +0 -10
- package/lib/types/utils/mapOpenSpec3.d.ts +0 -8
- 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"]}
|
|
@@ -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 {
|
|
5
|
-
import {
|
|
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
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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,
|
|
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,
|
|
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,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
|
/**
|
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,6 +1,5 @@
|
|
|
1
|
-
import { Configuration,
|
|
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
|
-
|
|
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.
|
|
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
|
-
"
|
|
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.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.
|
|
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.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.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"@tsed/
|
|
40
|
-
|
|
41
|
-
|
|
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/
|
|
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
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
12
|
[](https://github.com/semantic-release/semantic-release)
|
|
13
13
|
[](https://github.com/prettier/prettier)
|
|
14
|
-
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](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
|
-
|
|
53
|
-
|
|
51
|
+
path: "/v2/docs",
|
|
52
|
+
specVersion: "2.0"
|
|
54
53
|
},
|
|
55
54
|
{
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
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
|
|
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:
|
|
101
|
+
doc: "api-v1"
|
|
105
102
|
},
|
|
106
103
|
{
|
|
107
104
|
path: "/api-docs-v2",
|
|
108
|
-
doc:
|
|
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(
|
|
124
|
-
@Docs(
|
|
125
|
-
export class CalendarCtrlV2 {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
@
|
|
129
|
-
|
|
130
|
-
|
|
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(
|
|
158
|
+
@Controller("/calendars")
|
|
166
159
|
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
|
-
|
|
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(
|
|
234
|
-
|
|
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 +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
|