@tsed/cli-generate-swagger 4.4.0 → 4.4.2
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.
|
@@ -53,8 +53,7 @@ let GenerateSwaggerCmd = class GenerateSwaggerCmd {
|
|
|
53
53
|
const fileJson = path_1.default.resolve(path_1.default.join($ctx.output, conf.path, "swagger.json"));
|
|
54
54
|
const fileYaml = path_1.default.resolve(path_1.default.join($ctx.output, conf.path, "swagger.yaml"));
|
|
55
55
|
this.fs.ensureDirSync(path_1.default.dirname(fileJson));
|
|
56
|
-
this.fs.
|
|
57
|
-
await this.cliYaml.write(fileYaml, spec);
|
|
56
|
+
await Promise.all([this.fs.writeJson(fileJson, spec), this.cliYaml.write(fileYaml, spec)]);
|
|
58
57
|
}
|
|
59
58
|
};
|
|
60
59
|
tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
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;IAED,KAAK,CAAC,KAAK,CAAC,IAAwB;QAClC,OAAO;YACL;gBACE,KAAK,EAAE,iBAAiB;gBACxB,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;aAChC;SACF,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,kBAAk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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,CA6E9B;AA7EY,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 await Promise.all([this.fs.writeJson(fileJson, spec), this.cliYaml.write(fileYaml, spec)]);\n }\n}\n"]}
|
|
@@ -50,8 +50,7 @@ let GenerateSwaggerCmd = class GenerateSwaggerCmd {
|
|
|
50
50
|
const fileJson = path.resolve(path.join($ctx.output, conf.path, "swagger.json"));
|
|
51
51
|
const fileYaml = path.resolve(path.join($ctx.output, conf.path, "swagger.yaml"));
|
|
52
52
|
this.fs.ensureDirSync(path.dirname(fileJson));
|
|
53
|
-
this.fs.
|
|
54
|
-
await this.cliYaml.write(fileYaml, spec);
|
|
53
|
+
await Promise.all([this.fs.writeJson(fileJson, spec), this.cliYaml.write(fileYaml, spec)]);
|
|
55
54
|
}
|
|
56
55
|
};
|
|
57
56
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateSwaggerCmd.js","sourceRoot":"","sources":["../../../src/commands/GenerateSwaggerCmd.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAmB,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAC,MAAM,gBAAgB,CAAC;AACjH,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,IAAI,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AAC,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,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7F,CAAC;CACF,CAAA;AA5EC;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,CA6E9B;SA7EY,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 await Promise.all([this.fs.writeJson(fileJson, spec), this.cliYaml.write(fileYaml, spec)]);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-generate-swagger",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
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,8 +22,8 @@
|
|
|
22
22
|
"tslib": "2.3.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@tsed/cli": "4.4.
|
|
26
|
-
"@tsed/cli-core": "4.4.
|
|
25
|
+
"@tsed/cli": "4.4.2",
|
|
26
|
+
"@tsed/cli-core": "4.4.2"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@tsed/common": ">=7.14.2",
|
package/readme.md
CHANGED
|
@@ -25,19 +25,18 @@
|
|
|
25
25
|
</div>
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
> Ts.ED CLI plugin. Generate
|
|
28
|
+
> Ts.ED CLI plugin. Generate all Swagger in `json` and `yaml` format from your Ts.ED Server.
|
|
29
29
|
|
|
30
30
|
## Features
|
|
31
31
|
|
|
32
|
-
The plugin let you generate
|
|
33
|
-
Any changes from your controllers and models are reflected in your client!
|
|
32
|
+
The plugin let you generate all Swagger spec from the Ts.ED Server instance without running it.
|
|
34
33
|
|
|
35
34
|
## Installation
|
|
36
35
|
|
|
37
36
|
Run:
|
|
38
37
|
|
|
39
38
|
```bash
|
|
40
|
-
npm install @tsed/cli-generate-swagger @tsed/cli-core @tsed/cli @tsed/swagger
|
|
39
|
+
npm install @tsed/cli-generate-swagger @tsed/cli-core @tsed/cli @tsed/swagger
|
|
41
40
|
```
|
|
42
41
|
|
|
43
42
|
Then create or edit the `src/bin/index.ts` in your project:
|
|
@@ -69,6 +68,8 @@ Add a new script your `package.json`:
|
|
|
69
68
|
}
|
|
70
69
|
```
|
|
71
70
|
|
|
71
|
+
This command generate all Swagger specification in `json` and `yaml` format.
|
|
72
|
+
|
|
72
73
|
## Contributors
|
|
73
74
|
|
|
74
75
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
@@ -91,7 +92,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
91
92
|
|
|
92
93
|
The MIT License (MIT)
|
|
93
94
|
|
|
94
|
-
Copyright (c) 2016 -
|
|
95
|
+
Copyright (c) 2016 - 2023 Romain Lenzotti
|
|
95
96
|
|
|
96
97
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
97
98
|
|