Skip to content

Commit fe08dec

Browse files
authored
Release 10.0.1 (#382)
* fix: try to fix problem linked with this.name is not a function * chore: add alias for commander program * docs: update readme, changelog; bump: up version to 10.0.1; internal: add cli test
1 parent 544c809 commit fe08dec

File tree

7 files changed

+1011
-55
lines changed

7 files changed

+1011
-55
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# next release
1+
# next release
2+
3+
# 10.0.1
4+
5+
- fix problem linked with [this.name is not a function](https://github.com/acacode/swagger-typescript-api/issues/381)
6+
- [internal] add cli tests
7+
- fix problem with not correct working the `--no-client` option
28

39
# 10.0.0
410

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ Usage: swagger-typescript-api [options]
3737
3838
Options:
3939
-v, --version output the current version
40-
-p, --path <path> path/url to swagger scheme
41-
-o, --output <output> output path of typescript api file (default: "./")
42-
-n, --name <name> name of output typescript api file (default: "Api.ts")
43-
-t, --templates <path> path to folder containing templates
40+
-p, --path <string> path/url to swagger scheme
41+
-o, --output <string> output path of typescript api file (default: "./")
42+
-n, --name <string> name of output typescript api file (default: "Api.ts")
43+
-t, --templates <string> path to folder containing templates
4444
-d, --default-as-success use "default" response status code as success response too.
4545
some swagger schemas use "default" response status code as success response type by default. (default: false)
4646
-r, --responses generate additional information about request responses
@@ -69,7 +69,9 @@ Options:
6969
--type-prefix <string> data contract name prefix (default: "")
7070
--type-suffix <string> data contract name suffix (default: "")
7171
--clean-output clean output folder before generate api. WARNING: May cause data loss (default: false)
72+
--api-class-name <string> name of the api class
7273
--patch fix up small errors in the swagger source definition (default: false)
74+
-h, --help display help for command
7375
```
7476

7577
Also you can use `npx`:

index.js

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ const { TS_KEYWORDS, HTTP_CLIENT } = require("./src/constants");
1414

1515
const program = new Command(packageName);
1616

17-
program.storeOptionsAsProperties(true);
18-
19-
program
17+
const options = program
18+
.alias("sta")
2019
.version(version, "-v, --version", "output the current version")
21-
.description("Generate api via swagger scheme.\nSupports OA 3.0, 2.0, JSON, yaml.");
22-
23-
program
24-
.requiredOption("-p, --path <path>", "path/url to swagger scheme")
25-
.option("-o, --output <output>", "output path of typescript api file", "./")
26-
.option("-n, --name <name>", "name of output typescript api file", "Api.ts")
27-
.option("-t, --templates <path>", "path to folder containing templates")
20+
.description("Generate api via swagger scheme.\nSupports OA 3.0, 2.0, JSON, yaml.")
21+
.requiredOption("-p, --path <string>", "path/url to swagger scheme")
22+
.option("-o, --output <string>", "output path of typescript api file", "./")
23+
.option("-n, --name <string>", "name of output typescript api file", "Api.ts")
24+
.option("-t, --templates <string>", "path to folder containing templates")
2825
.option(
2926
"-d, --default-as-success",
3027
'use "default" response status code as success response too.\n' +
@@ -39,7 +36,7 @@ program
3936
.option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
4037
.option("--add-readonly", "generate readonly properties", false)
4138
.option("--route-types", "generate type definitions for API routes", false)
42-
.option("--no-client", "do not generate an API class", false)
39+
.option("--no-client", "do not generate an API class", true)
4340
.option("--enum-names-as-values", "use values in 'x-enumNames' as enum values (not only as keys)", false)
4441
.option(
4542
"--extract-request-params",
@@ -68,45 +65,46 @@ program
6865
.option("--type-prefix <string>", "data contract name prefix", "")
6966
.option("--type-suffix <string>", "data contract name suffix", "")
7067
.option("--clean-output", "clean output folder before generate api. WARNING: May cause data loss", false)
71-
.option("--patch", "fix up small errors in the swagger source definition", false);
72-
73-
program.parse(process.argv);
68+
.option("--api-class-name <string>", "name of the api class")
69+
.option("--patch", "fix up small errors in the swagger source definition", false)
70+
.parse(process.argv)
71+
.opts();
7472

7573
generateApi({
76-
name: program.name,
77-
url: program.path,
78-
generateRouteTypes: program.routeTypes,
79-
generateClient: !!(program.axios || program.client),
80-
httpClientType: program.axios ? HTTP_CLIENT.AXIOS : HTTP_CLIENT.FETCH,
81-
defaultResponseAsSuccess: program.defaultAsSuccess,
82-
defaultResponseType: program.defaultResponse,
83-
unwrapResponseData: program.unwrapResponseData,
84-
disableThrowOnError: program.disableThrowOnError,
85-
sortTypes: program.sortTypes,
86-
generateUnionEnums: program.unionEnums,
87-
addReadonly: program.addReadonly,
88-
generateResponses: program.responses,
89-
extractRequestParams: !!program.extractRequestParams,
90-
extractRequestBody: !!program.extractRequestBody,
91-
extractResponseBody: !!program.extractResponseBody,
92-
extractResponseError: !!program.extractResponseError,
93-
input: resolve(process.cwd(), program.path),
94-
output: resolve(process.cwd(), program.output || "."),
95-
templates: program.templates,
96-
modular: !!program.modular,
97-
toJS: !!program.js,
98-
enumNamesAsValues: program.enumNamesAsValues,
99-
moduleNameIndex: +(program.moduleNameIndex || 0),
100-
moduleNameFirstTag: program.moduleNameFirstTag,
101-
disableStrictSSL: !!program.disableStrictSSL,
102-
disableProxy: !!program.disableProxy,
103-
singleHttpClient: !!program.singleHttpClient,
104-
cleanOutput: !!program.cleanOutput,
105-
silent: !!program.silent,
106-
typePrefix: program.typePrefix,
107-
typeSuffix: program.typeSuffix,
108-
patch: !!program.patch,
109-
apiClassName,
74+
name: options.name,
75+
url: options.path,
76+
generateRouteTypes: options.routeTypes,
77+
generateClient: !!(options.axios || options.client),
78+
httpClientType: options.axios ? HTTP_CLIENT.AXIOS : HTTP_CLIENT.FETCH,
79+
defaultResponseAsSuccess: options.defaultAsSuccess,
80+
defaultResponseType: options.defaultResponse,
81+
unwrapResponseData: options.unwrapResponseData,
82+
disableThrowOnError: options.disableThrowOnError,
83+
sortTypes: options.sortTypes,
84+
generateUnionEnums: options.unionEnums,
85+
addReadonly: options.addReadonly,
86+
generateResponses: options.responses,
87+
extractRequestParams: !!options.extractRequestParams,
88+
extractRequestBody: !!options.extractRequestBody,
89+
extractResponseBody: !!options.extractResponseBody,
90+
extractResponseError: !!options.extractResponseError,
91+
input: resolve(process.cwd(), options.path),
92+
output: resolve(process.cwd(), options.output || "."),
93+
templates: options.templates,
94+
modular: !!options.modular,
95+
toJS: !!options.js,
96+
enumNamesAsValues: options.enumNamesAsValues,
97+
moduleNameIndex: +(options.moduleNameIndex || 0),
98+
moduleNameFirstTag: options.moduleNameFirstTag,
99+
disableStrictSSL: !!options.disableStrictSSL,
100+
disableProxy: !!options.disableProxy,
101+
singleHttpClient: !!options.singleHttpClient,
102+
cleanOutput: !!options.cleanOutput,
103+
silent: !!options.silent,
104+
typePrefix: options.typePrefix,
105+
typeSuffix: options.typeSuffix,
106+
patch: !!options.patch,
107+
apiClassName: options.apiClassName,
110108
}).catch((err) => {
111109
// NOTE collect all errors on top level and shows to users in any case
112110
console.error(err);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "10.0.0",
3+
"version": "10.0.1",
44
"description": "Generate typescript/javascript api from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
@@ -41,6 +41,7 @@
4141
"test:--axios": "node tests/spec/axios/test.js",
4242
"test:--axios--single-http-client": "node tests/spec/axiosSingleHttpClient/test.js",
4343
"test:--type-suffix--type-prefix": "node tests/spec/typeSuffixPrefix/test.js",
44+
"test:--cli": "node index.js -p tests/spec/cli/schema.json -o tests/spec/cli -n schema.ts --extract-response-body --extract-response-error --type-prefix Prefix --api-class-name MySuperApi --no-client",
4445
"test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
4546
"test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
4647
"test:--patch": "node tests/spec/patch/test.js"

0 commit comments

Comments
 (0)