@tsed/cli-generate-swagger 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/commands/GenerateSwaggerCmd.js +10 -8
- package/lib/cjs/commands/GenerateSwaggerCmd.js.map +1 -1
- package/lib/esm/commands/GenerateSwaggerCmd.js +11 -9
- package/lib/esm/commands/GenerateSwaggerCmd.js.map +1 -1
- package/lib/types/commands/GenerateSwaggerCmd.d.ts +2 -7
- package/package.json +4 -6
|
@@ -8,8 +8,8 @@ const path_1 = tslib_1.__importStar(require("path"));
|
|
|
8
8
|
let GenerateSwaggerCmd = class GenerateSwaggerCmd {
|
|
9
9
|
injector;
|
|
10
10
|
fs;
|
|
11
|
+
cliYaml;
|
|
11
12
|
serverModule;
|
|
12
|
-
options;
|
|
13
13
|
$mapContext($ctx) {
|
|
14
14
|
return { ...$ctx, output: (0, path_1.resolve)((0, path_1.join)(process.cwd(), $ctx.output)) };
|
|
15
15
|
}
|
|
@@ -50,9 +50,11 @@ let GenerateSwaggerCmd = class GenerateSwaggerCmd {
|
|
|
50
50
|
await platform.stop();
|
|
51
51
|
}
|
|
52
52
|
async generateFromSpec(spec, conf, $ctx) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const fileJson = path_1.default.resolve(path_1.default.join($ctx.output, conf.path, "swagger.json"));
|
|
54
|
+
const fileYaml = path_1.default.resolve(path_1.default.join($ctx.output, conf.path, "swagger.yaml"));
|
|
55
|
+
this.fs.ensureDirSync(path_1.default.dirname(fileJson));
|
|
56
|
+
this.fs.writeFile(fileJson, JSON.stringify(spec, null, 2), { encoding: "utf8" });
|
|
57
|
+
await this.cliYaml.write(fileYaml, spec);
|
|
56
58
|
}
|
|
57
59
|
};
|
|
58
60
|
tslib_1.__decorate([
|
|
@@ -63,14 +65,14 @@ tslib_1.__decorate([
|
|
|
63
65
|
(0, cli_core_1.Inject)(),
|
|
64
66
|
tslib_1.__metadata("design:type", cli_core_1.CliFs)
|
|
65
67
|
], GenerateSwaggerCmd.prototype, "fs", void 0);
|
|
68
|
+
tslib_1.__decorate([
|
|
69
|
+
(0, cli_core_1.Inject)(),
|
|
70
|
+
tslib_1.__metadata("design:type", cli_core_1.CliYaml)
|
|
71
|
+
], GenerateSwaggerCmd.prototype, "cliYaml", void 0);
|
|
66
72
|
tslib_1.__decorate([
|
|
67
73
|
(0, cli_core_1.Constant)("server"),
|
|
68
74
|
tslib_1.__metadata("design:type", cli_core_1.Type)
|
|
69
75
|
], GenerateSwaggerCmd.prototype, "serverModule", void 0);
|
|
70
|
-
tslib_1.__decorate([
|
|
71
|
-
(0, cli_core_1.Constant)("Swagger", { hooks: {} }),
|
|
72
|
-
tslib_1.__metadata("design:type", Object)
|
|
73
|
-
], GenerateSwaggerCmd.prototype, "options", void 0);
|
|
74
76
|
GenerateSwaggerCmd = tslib_1.__decorate([
|
|
75
77
|
(0, cli_core_1.Command)({
|
|
76
78
|
name: "generate-swagger",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateSwaggerCmd.js","sourceRoot":"","sources":["../../../src/commands/GenerateSwaggerCmd.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"GenerateSwaggerCmd.js","sourceRoot":"","sources":["../../../src/commands/GenerateSwaggerCmd.ts"],"names":[],"mappings":";;;;AAAA,6CAAiH;AACjH,qCAAyC;AACzC,qDAAyC;AAiBlC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAE7B,QAAQ,CAAkB;IAGhB,EAAE,CAAQ;IAGV,OAAO,CAAU;IAGjB,YAAY,CAAY;IAElC,WAAW,CAAC,IAAwB;QAClC,OAAO,EAAC,GAAG,IAAI,EAAE,MAAM,EAAE,IAAA,cAAO,EAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAAC,CAAC;IACtE,CAAC;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,gBAAK;8CAAC;AAEpB;IAAC,IAAA,iBAAM,GAAE;sCACU,kBAAO;mDAAC;AAE3B;IAAC,IAAA,mBAAQ,EAAC,QAAQ,CAAC;sCACK,eAAI;wDAAM;AAXvB,kBAAkB;IAX9B,IAAA,kBAAO,EAAC;QACP,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,2CAA2C;QACxD,OAAO,EAAE;YACP,uBAAuB,EAAE;gBACvB,QAAQ,EAAE,IAAI;gBACd,IAAI,EAAE,MAAM;gBACZ,WAAW,EAAE,wBAAwB;aACtC;SACF;KACF,CAAC;GACW,kBAAkB,CA8E9B;AA9EY,gDAAkB","sourcesContent":["import {CliFs, CliYaml, Command, CommandProvider, Constant, Inject, InjectorService, Type} from \"@tsed/cli-core\";\nimport {importPackage} from \"@tsed/core\";\nimport path, {join, resolve} from \"path\";\n\nexport interface GenerateSwaggerCtx {\n output: string;\n}\n\n@Command({\n name: \"generate-swagger\",\n description: \"Generate the client API from swagger spec\",\n options: {\n \"-o, --output <output>\": {\n required: true,\n type: String,\n description: \"Path to generate files\"\n }\n }\n})\nexport class GenerateSwaggerCmd implements CommandProvider {\n @Inject()\n injector: InjectorService;\n\n @Inject()\n protected fs: CliFs;\n\n @Inject()\n protected cliYaml: CliYaml;\n\n @Constant(\"server\")\n protected serverModule: Type<any>;\n\n $mapContext($ctx: GenerateSwaggerCtx) {\n return {...$ctx, output: resolve(join(process.cwd(), $ctx.output))};\n }\n\n async $exec($ctx: GenerateSwaggerCtx) {\n return [\n {\n title: \"generate client\",\n task: () => this.generate($ctx)\n }\n ];\n }\n\n private async loadPlatformModule(): Promise<{\n bootstrap(module: any, settings: any): Promise<{injector: InjectorService; stop(): Promise<void>}>;\n }> {\n let platform = await importPackage(\"@tsed/platform-express\", undefined, true);\n\n if (platform) {\n return platform.PlatformExpress;\n }\n\n platform = await importPackage(\"@tsed/platform-koa\", undefined, true);\n\n if (platform) {\n return platform.PlatformKoa;\n }\n\n throw new Error(\"Unsupported platform. Please use Express.js or Koa.js platform.\");\n }\n\n private async generate($ctx: GenerateSwaggerCtx) {\n const Platform = await this.loadPlatformModule();\n const {SwaggerService} = await importPackage(\"@tsed/swagger\");\n\n const platform = await Platform.bootstrap(this.serverModule, {\n logger: {level: \"off\"}\n });\n\n const swaggerService = platform.injector.get<any>(SwaggerService)!;\n const confs = platform.injector.settings.get<any[]>(\"swagger\", []);\n\n await this.fs.raw.remove($ctx.output);\n await this.fs.ensureDir($ctx.output);\n\n const promises = confs.map(async (conf) => {\n const spec = await swaggerService.getOpenAPISpec(conf);\n\n await this.generateFromSpec(spec, conf, $ctx);\n });\n\n await Promise.all(promises);\n\n await platform.stop();\n }\n\n private async generateFromSpec(spec: any, conf: any, $ctx: GenerateSwaggerCtx) {\n const fileJson = path.resolve(path.join($ctx.output, conf.path, \"swagger.json\"));\n const fileYaml = path.resolve(path.join($ctx.output, conf.path, \"swagger.yaml\"));\n\n this.fs.ensureDirSync(path.dirname(fileJson));\n\n this.fs.writeFile(fileJson, JSON.stringify(spec, null, 2), {encoding: \"utf8\"});\n await this.cliYaml.write(fileYaml, spec);\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { CliFs, Command, Constant, Inject, InjectorService, Type } from "@tsed/cli-core";
|
|
2
|
+
import { CliFs, CliYaml, Command, Constant, Inject, InjectorService, Type } from "@tsed/cli-core";
|
|
3
3
|
import { importPackage } from "@tsed/core";
|
|
4
4
|
import path, { join, resolve } from "path";
|
|
5
5
|
let GenerateSwaggerCmd = class GenerateSwaggerCmd {
|
|
6
6
|
injector;
|
|
7
7
|
fs;
|
|
8
|
+
cliYaml;
|
|
8
9
|
serverModule;
|
|
9
|
-
options;
|
|
10
10
|
$mapContext($ctx) {
|
|
11
11
|
return { ...$ctx, output: resolve(join(process.cwd(), $ctx.output)) };
|
|
12
12
|
}
|
|
@@ -47,9 +47,11 @@ let GenerateSwaggerCmd = class GenerateSwaggerCmd {
|
|
|
47
47
|
await platform.stop();
|
|
48
48
|
}
|
|
49
49
|
async generateFromSpec(spec, conf, $ctx) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const fileJson = path.resolve(path.join($ctx.output, conf.path, "swagger.json"));
|
|
51
|
+
const fileYaml = path.resolve(path.join($ctx.output, conf.path, "swagger.yaml"));
|
|
52
|
+
this.fs.ensureDirSync(path.dirname(fileJson));
|
|
53
|
+
this.fs.writeFile(fileJson, JSON.stringify(spec, null, 2), { encoding: "utf8" });
|
|
54
|
+
await this.cliYaml.write(fileYaml, spec);
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
__decorate([
|
|
@@ -60,14 +62,14 @@ __decorate([
|
|
|
60
62
|
Inject(),
|
|
61
63
|
__metadata("design:type", CliFs)
|
|
62
64
|
], GenerateSwaggerCmd.prototype, "fs", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
Inject(),
|
|
67
|
+
__metadata("design:type", CliYaml)
|
|
68
|
+
], GenerateSwaggerCmd.prototype, "cliYaml", void 0);
|
|
63
69
|
__decorate([
|
|
64
70
|
Constant("server"),
|
|
65
71
|
__metadata("design:type", Type)
|
|
66
72
|
], GenerateSwaggerCmd.prototype, "serverModule", void 0);
|
|
67
|
-
__decorate([
|
|
68
|
-
Constant("Swagger", { hooks: {} }),
|
|
69
|
-
__metadata("design:type", Object)
|
|
70
|
-
], GenerateSwaggerCmd.prototype, "options", void 0);
|
|
71
73
|
GenerateSwaggerCmd = __decorate([
|
|
72
74
|
Command({
|
|
73
75
|
name: "generate-swagger",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateSwaggerCmd.js","sourceRoot":"","sources":["../../../src/commands/GenerateSwaggerCmd.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,KAAK,EAAE,OAAO,EAAmB,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAC,MAAM,gBAAgB,CAAC;
|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EAAE,cAAc,CAAC,CAAC,CAAC;QACjF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;QAEjF,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9C,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;QAC/E,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AA7EC;IAAC,MAAM,EAAE;8BACC,eAAe;oDAAC;AAE1B;IAAC,MAAM,EAAE;8BACK,KAAK;8CAAC;AAEpB;IAAC,MAAM,EAAE;8BACU,OAAO;mDAAC;AAE3B;IAAC,QAAQ,CAAC,QAAQ,CAAC;8BACK,IAAI;wDAAM;AAXvB,kBAAkB;IAX9B,OAAO,CAAC;QACP,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,2CAA2C;QACxD,OAAO,EAAE;YACP,uBAAuB,EAAE;gBACvB,QAAQ,EAAE,IAAI;gBACd,IAAI,EAAE,MAAM;gBACZ,WAAW,EAAE,wBAAwB;aACtC;SACF;KACF,CAAC;GACW,kBAAkB,CA8E9B;SA9EY,kBAAkB","sourcesContent":["import {CliFs, CliYaml, Command, CommandProvider, Constant, Inject, InjectorService, Type} from \"@tsed/cli-core\";\nimport {importPackage} from \"@tsed/core\";\nimport path, {join, resolve} from \"path\";\n\nexport interface GenerateSwaggerCtx {\n output: string;\n}\n\n@Command({\n name: \"generate-swagger\",\n description: \"Generate the client API from swagger spec\",\n options: {\n \"-o, --output <output>\": {\n required: true,\n type: String,\n description: \"Path to generate files\"\n }\n }\n})\nexport class GenerateSwaggerCmd implements CommandProvider {\n @Inject()\n injector: InjectorService;\n\n @Inject()\n protected fs: CliFs;\n\n @Inject()\n protected cliYaml: CliYaml;\n\n @Constant(\"server\")\n protected serverModule: Type<any>;\n\n $mapContext($ctx: GenerateSwaggerCtx) {\n return {...$ctx, output: resolve(join(process.cwd(), $ctx.output))};\n }\n\n async $exec($ctx: GenerateSwaggerCtx) {\n return [\n {\n title: \"generate client\",\n task: () => this.generate($ctx)\n }\n ];\n }\n\n private async loadPlatformModule(): Promise<{\n bootstrap(module: any, settings: any): Promise<{injector: InjectorService; stop(): Promise<void>}>;\n }> {\n let platform = await importPackage(\"@tsed/platform-express\", undefined, true);\n\n if (platform) {\n return platform.PlatformExpress;\n }\n\n platform = await importPackage(\"@tsed/platform-koa\", undefined, true);\n\n if (platform) {\n return platform.PlatformKoa;\n }\n\n throw new Error(\"Unsupported platform. Please use Express.js or Koa.js platform.\");\n }\n\n private async generate($ctx: GenerateSwaggerCtx) {\n const Platform = await this.loadPlatformModule();\n const {SwaggerService} = await importPackage(\"@tsed/swagger\");\n\n const platform = await Platform.bootstrap(this.serverModule, {\n logger: {level: \"off\"}\n });\n\n const swaggerService = platform.injector.get<any>(SwaggerService)!;\n const confs = platform.injector.settings.get<any[]>(\"swagger\", []);\n\n await this.fs.raw.remove($ctx.output);\n await this.fs.ensureDir($ctx.output);\n\n const promises = confs.map(async (conf) => {\n const spec = await swaggerService.getOpenAPISpec(conf);\n\n await this.generateFromSpec(spec, conf, $ctx);\n });\n\n await Promise.all(promises);\n\n await platform.stop();\n }\n\n private async generateFromSpec(spec: any, conf: any, $ctx: GenerateSwaggerCtx) {\n const fileJson = path.resolve(path.join($ctx.output, conf.path, \"swagger.json\"));\n const fileYaml = path.resolve(path.join($ctx.output, conf.path, \"swagger.yaml\"));\n\n this.fs.ensureDirSync(path.dirname(fileJson));\n\n this.fs.writeFile(fileJson, JSON.stringify(spec, null, 2), {encoding: \"utf8\"});\n await this.cliYaml.write(fileYaml, spec);\n }\n}\n"]}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import { CliFs, CommandProvider, InjectorService, Type } from "@tsed/cli-core";
|
|
2
|
-
import { Hooks, RawRouteInfo, RouteNameInfo } from "swagger-typescript-api";
|
|
1
|
+
import { CliFs, CliYaml, CommandProvider, InjectorService, Type } from "@tsed/cli-core";
|
|
3
2
|
export interface GenerateSwaggerCtx {
|
|
4
3
|
output: string;
|
|
5
4
|
}
|
|
6
|
-
export interface GenerateSwaggerOpts {
|
|
7
|
-
hooks?: Partial<Hooks>;
|
|
8
|
-
transformOperationId?(operationId: string, routeNameInfo: RouteNameInfo, raw: RawRouteInfo): string;
|
|
9
|
-
}
|
|
10
5
|
export declare class GenerateSwaggerCmd implements CommandProvider {
|
|
11
6
|
injector: InjectorService;
|
|
12
7
|
protected fs: CliFs;
|
|
8
|
+
protected cliYaml: CliYaml;
|
|
13
9
|
protected serverModule: Type<any>;
|
|
14
|
-
protected options: Partial<GenerateSwaggerOpts>;
|
|
15
10
|
$mapContext($ctx: GenerateSwaggerCtx): {
|
|
16
11
|
output: string;
|
|
17
12
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-generate-swagger",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Ts.ED CLI plugin. Export a command that generate the swagger.json from your Ts.ED controllers and OS3 spec.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -22,14 +22,12 @@
|
|
|
22
22
|
"tslib": "2.3.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@tsed/cli": "4.
|
|
26
|
-
"@tsed/cli-core": "4.
|
|
27
|
-
"swagger-typescript-api": "^9.3.1"
|
|
25
|
+
"@tsed/cli": "4.4.0",
|
|
26
|
+
"@tsed/cli-core": "4.4.0"
|
|
28
27
|
},
|
|
29
28
|
"peerDependencies": {
|
|
30
29
|
"@tsed/common": ">=7.14.2",
|
|
31
|
-
"@tsed/swagger": ">=7.14.2"
|
|
32
|
-
"swagger-typescript-api": "^9.3.1"
|
|
30
|
+
"@tsed/swagger": ">=7.14.2"
|
|
33
31
|
},
|
|
34
32
|
"peerDependenciesMeta": {
|
|
35
33
|
"@tsed/swagger": {
|