swagger-typescript-api 10.0.0 → 10.0.1
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/CHANGELOG.md +7 -1
- package/README.md +6 -4
- package/index.js +46 -48
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -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
|
|
2
8
|
|
|
3
9
|
# 10.0.0
|
|
4
10
|
|
package/README.md
CHANGED
|
@@ -37,10 +37,10 @@ Usage: swagger-typescript-api [options]
|
|
|
37
37
|
|
|
38
38
|
Options:
|
|
39
39
|
-v, --version output the current version
|
|
40
|
-
-p, --path <
|
|
41
|
-
-o, --output <
|
|
42
|
-
-n, --name <
|
|
43
|
-
-t, --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
|
|
44
44
|
-d, --default-as-success use "default" response status code as success response too.
|
|
45
45
|
some swagger schemas use "default" response status code as success response type by default. (default: false)
|
|
46
46
|
-r, --responses generate additional information about request responses
|
|
@@ -69,7 +69,9 @@ Options:
|
|
|
69
69
|
--type-prefix <string> data contract name prefix (default: "")
|
|
70
70
|
--type-suffix <string> data contract name suffix (default: "")
|
|
71
71
|
--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
|
|
72
73
|
--patch fix up small errors in the swagger source definition (default: false)
|
|
74
|
+
-h, --help display help for command
|
|
73
75
|
```
|
|
74
76
|
|
|
75
77
|
Also you can use `npx`:
|
package/index.js
CHANGED
|
@@ -14,17 +14,14 @@ const { TS_KEYWORDS, HTTP_CLIENT } = require("./src/constants");
|
|
|
14
14
|
|
|
15
15
|
const program = new Command(packageName);
|
|
16
16
|
|
|
17
|
-
program
|
|
18
|
-
|
|
19
|
-
program
|
|
17
|
+
const options = program
|
|
18
|
+
.alias("sta")
|
|
20
19
|
.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
|
-
|
|
24
|
-
.
|
|
25
|
-
.option("-
|
|
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")
|
|
28
25
|
.option(
|
|
29
26
|
"-d, --default-as-success",
|
|
30
27
|
'use "default" response status code as success response too.\n' +
|
|
@@ -39,7 +36,7 @@ program
|
|
|
39
36
|
.option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
|
|
40
37
|
.option("--add-readonly", "generate readonly properties", false)
|
|
41
38
|
.option("--route-types", "generate type definitions for API routes", false)
|
|
42
|
-
.option("--no-client", "do not generate an API class",
|
|
39
|
+
.option("--no-client", "do not generate an API class", true)
|
|
43
40
|
.option("--enum-names-as-values", "use values in 'x-enumNames' as enum values (not only as keys)", false)
|
|
44
41
|
.option(
|
|
45
42
|
"--extract-request-params",
|
|
@@ -68,45 +65,46 @@ program
|
|
|
68
65
|
.option("--type-prefix <string>", "data contract name prefix", "")
|
|
69
66
|
.option("--type-suffix <string>", "data contract name suffix", "")
|
|
70
67
|
.option("--clean-output", "clean output folder before generate api. WARNING: May cause data loss", false)
|
|
71
|
-
.option("--
|
|
72
|
-
|
|
73
|
-
|
|
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();
|
|
74
72
|
|
|
75
73
|
generateApi({
|
|
76
|
-
name:
|
|
77
|
-
url:
|
|
78
|
-
generateRouteTypes:
|
|
79
|
-
generateClient: !!(
|
|
80
|
-
httpClientType:
|
|
81
|
-
defaultResponseAsSuccess:
|
|
82
|
-
defaultResponseType:
|
|
83
|
-
unwrapResponseData:
|
|
84
|
-
disableThrowOnError:
|
|
85
|
-
sortTypes:
|
|
86
|
-
generateUnionEnums:
|
|
87
|
-
addReadonly:
|
|
88
|
-
generateResponses:
|
|
89
|
-
extractRequestParams: !!
|
|
90
|
-
extractRequestBody: !!
|
|
91
|
-
extractResponseBody: !!
|
|
92
|
-
extractResponseError: !!
|
|
93
|
-
input: resolve(process.cwd(),
|
|
94
|
-
output: resolve(process.cwd(),
|
|
95
|
-
templates:
|
|
96
|
-
modular: !!
|
|
97
|
-
toJS: !!
|
|
98
|
-
enumNamesAsValues:
|
|
99
|
-
moduleNameIndex: +(
|
|
100
|
-
moduleNameFirstTag:
|
|
101
|
-
disableStrictSSL: !!
|
|
102
|
-
disableProxy: !!
|
|
103
|
-
singleHttpClient: !!
|
|
104
|
-
cleanOutput: !!
|
|
105
|
-
silent: !!
|
|
106
|
-
typePrefix:
|
|
107
|
-
typeSuffix:
|
|
108
|
-
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,
|
|
110
108
|
}).catch((err) => {
|
|
111
109
|
// NOTE collect all errors on top level and shows to users in any case
|
|
112
110
|
console.error(err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swagger-typescript-api",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.1",
|
|
4
4
|
"description": "Generate typescript/javascript api from swagger schema",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"test:--axios": "node tests/spec/axios/test.js",
|
|
42
42
|
"test:--axios--single-http-client": "node tests/spec/axiosSingleHttpClient/test.js",
|
|
43
43
|
"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",
|
|
44
45
|
"test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
|
|
45
46
|
"test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
|
|
46
47
|
"test:--patch": "node tests/spec/patch/test.js"
|