swagger-typescript-api 9.2.0 → 10.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # next release
2
2
 
3
+ # 10.0.0
4
+
5
+ - `--extract-response-body` option - extract response body type to data contract
6
+ - `--extract-response-error` option - extract response error type to data contract
7
+ - `--add-readonly` option - generate readonly properties
8
+ - `authorizationToken` for axios fetch swagger schema request
9
+ - fix: change COMPLEX_NOT_OF to COMPLEX_NOT (internal)
10
+ - feat: improve `@deprecated` jsdoc info
11
+ - feat: improve `required` field in complex data schemas (anyOf, oneOf, allOf etc)
12
+ - feat: abortSignal for fetch http client
13
+ - chore: improve typings in index.d.ts
14
+ - fixed [Request falls if FormData attachment is File instance](https://github.com/acacode/swagger-typescript-api/issues/293)
15
+ - fixed [Response format - global default or override ?](https://github.com/acacode/swagger-typescript-api/issues/251)
16
+
17
+ > Co-authored-by: Sergey S. Volkov <js2me@outlook.com>
18
+ > Co-authored-by: Xavier Cassel <57092100+xcassel@users.noreply.github.com>
19
+ > Co-authored-by: cassel <xavier.cassel35@gmail.com>
20
+ > Co-authored-by: Adrian Wieprzkowicz <Argeento@users.noreply.github.com>
21
+ > Co-authored-by: EvgenBabenko <evgen.babenko@gmail.com>
22
+ > Co-authored-by: RoCat <catoio.romain@gmail.com>
23
+ > Co-authored-by: rcatoio <rcatoio@doubletrade.com>
24
+ > Co-authored-by: 卡色 <cipchk@qq.com>
25
+ > Co-authored-by: 江麻妞 <50100681+jiangmaniu@users.noreply.github.com>
26
+ > Co-authored-by: Kasper Moskwiak <kasper.moskwiak@gmail.com>
27
+ > Co-authored-by: Ben Watkins <ben@outdatedversion.com>
28
+ > Co-authored-by: bonukai <bonukai@protonmail.com>
29
+ > Co-authored-by: baggoedw <92381702+baggoedw@users.noreply.github.com>
30
+ > Co-authored-by: Marcus Dunn <51931484+MarcusDunn@users.noreply.github.com>
31
+ > Co-authored-by: Daniele De Matteo <daniele@kuama.net>
32
+ > Co-authored-by: Daniel Playfair Cal <daniel.playfair.cal@gmail.com>
33
+ > Co-authored-by: Anders Cassidy <anders.cassidy@dailypay.com>
34
+ > Co-authored-by: Daniel Playfair Cal <dcal@atlassian.com>
35
+
3
36
  # 9.2.0
4
37
 
5
38
  Features:
package/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- MIT License
2
-
3
- Copyright (c) 2019-present acacode
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- 'Software'), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1
+ MIT License
2
+
3
+ Copyright (c) 2019-present acacode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -19,7 +19,11 @@ Any questions you can ask [**here**](https://github.com/acacode/swagger-typescri
19
19
 
20
20
  <br>
21
21
 
22
- ![](https://raw.githubusercontent.com/acacode/swagger-typescript-api/master/assets/components-converter-example.jpg)
22
+ ![](https://raw.githubusercontent.com/acacode/swagger-typescript-api/master/assets/components-converter-example.jpg)
23
+
24
+ 👀 This project is looking for a code maintainer 👀
25
+ P.S. If you are creating the PR, please check your changes with using command `npm run prepare`
26
+ P.S. If you want to contribute please use branch `next`. All PRs which will have target `master` will be declined
23
27
 
24
28
  ## 👀 Examples
25
29
 
@@ -38,32 +42,34 @@ Options:
38
42
  -n, --name <name> name of output typescript api file (default: "Api.ts")
39
43
  -t, --templates <path> path to folder containing templates
40
44
  -d, --default-as-success use "default" response status code as success response too.
41
- some swagger schemas use "default" response status code
42
- as success response type by default. (default: false)
45
+ some swagger schemas use "default" response status code as success response type by default. (default: false)
43
46
  -r, --responses generate additional information about request responses
44
47
  also add typings for bad responses (default: false)
45
48
  --union-enums generate all "enum" types as union types (T1 | T2 | TN) (default: false)
49
+ --add-readonly generate readonly properties (default: false)
46
50
  --route-types generate type definitions for API routes (default: false)
47
51
  --no-client do not generate an API class
48
52
  --enum-names-as-values use values in 'x-enumNames' as enum values (not only as keys) (default: false)
49
- --js generate js api module with declaration file (default: false)
50
- --extract-request-params extract request params to data contract (default: false)
51
- Also combine path params and query params into one object
52
- --extract-request-body extract request body type to data contract (default: false)
53
- --module-name-index <number> determines which path index should be used for routes separation (default: 0)
54
- (example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)
55
- --module-name-first-tag splits routes based on the first tag
53
+ --extract-request-params extract request params to data contract (Also combine path params and query params into one object) (default: false)
54
+ --extract-request-body extract request body type to data contract (default: false)
55
+ --extract-response-body extract response body type to data contract (default: false)
56
+ --extract-response-error extract response error type to data contract (default: false)
56
57
  --modular generate separated files for http client, data contracts, and routes (default: false)
58
+ --js generate js api module with declaration file (default: false)
59
+ --module-name-index <number> determines which path index should be used for routes separation (example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites) (default: 0)
60
+ --module-name-first-tag splits routes based on the first tag (default: false)
57
61
  --disableStrictSSL disabled strict SSL (default: false)
58
62
  --disableProxy disabled proxy (default: false)
59
- --clean-output clean output folder before generate api. WARNING: May cause data loss (default: false)
60
63
  --axios generate axios http client (default: false)
64
+ --unwrap-response-data unwrap the data item from the response (default: false)
65
+ --disable-throw-on-error Do not throw an error when response.ok is not true (default: false)
61
66
  --single-http-client Ability to send HttpClient instance to Api constructor (default: false)
62
67
  --silent Output only errors to console (default: false)
63
68
  --default-response <type> default type for empty response schema (default: "void")
64
69
  --type-prefix <string> data contract name prefix (default: "")
65
70
  --type-suffix <string> data contract name suffix (default: "")
66
- -h, --help display help for command
71
+ --clean-output clean output folder before generate api. WARNING: May cause data loss (default: false)
72
+ --patch fix up small errors in the swagger source definition (default: false)
67
73
  ```
68
74
 
69
75
  Also you can use `npx`:
@@ -99,7 +105,7 @@ generateApi({
99
105
  toJS: false,
100
106
  extractRequestParams: false,
101
107
  extractRequestBody: false,
102
- prettier: {
108
+ prettier: { // By default prettier config is load from your project
103
109
  printWidth: 120,
104
110
  tabWidth: 2,
105
111
  trailingComma: "all",
package/index.d.ts CHANGED
@@ -1,19 +1,4 @@
1
- interface GenerateApiParams {
2
- /**
3
- * path to swagger schema
4
- */
5
- input: string;
6
-
7
- /**
8
- * url to swagger schema
9
- */
10
- url: string;
11
-
12
- /**
13
- * swagger schema JSON
14
- */
15
- spec: import("swagger-schema-official").Spec;
16
-
1
+ interface GenerateApiParamsBase {
17
2
  /**
18
3
  * default 'api.ts'
19
4
  */
@@ -25,7 +10,7 @@ interface GenerateApiParams {
25
10
  output?: string;
26
11
 
27
12
  /**
28
- * path to folder containing templates (default: ./scr/templates)
13
+ * path to folder containing templates (default: ./src/templates)
29
14
  */
30
15
  templates?: string;
31
16
 
@@ -88,6 +73,18 @@ interface GenerateApiParams {
88
73
  * extract request params to data contract (Also combine path params and query params into one object)
89
74
  */
90
75
  extractRequestParams?: boolean;
76
+ /**
77
+ * extract request body type to data contract
78
+ */
79
+ extractRequestBody?: boolean;
80
+ /**
81
+ * extract response body type to data contract
82
+ */
83
+ extractResponseBody?: boolean;
84
+ /**
85
+ * extract response error type to data contract
86
+ */
87
+ extractResponseError?: boolean;
91
88
  /**
92
89
  * prettier configuration
93
90
  */
@@ -112,8 +109,40 @@ interface GenerateApiParams {
112
109
  * extra templates
113
110
  */
114
111
  extraTemplates?: { name: string; path: string }[];
112
+
113
+ /**
114
+ * fix up small errors in the swagger source definition
115
+ */
116
+ patch?: boolean;
117
+ /**
118
+ * authorization token
119
+ */
120
+ authorizationToken?: string;
121
+ }
122
+
123
+ interface GenerateApiParamsFromPath extends GenerateApiParamsBase {
124
+ /**
125
+ * path to swagger schema
126
+ */
127
+ input: string;
128
+ }
129
+
130
+ interface GenerateApiParamsFromUrl extends GenerateApiParamsBase {
131
+ /**
132
+ * url to swagger schema
133
+ */
134
+ url: string;
135
+ }
136
+
137
+ interface GenerateApiParamsFromSpecLiteral extends GenerateApiParamsBase {
138
+ /**
139
+ * swagger schema JSON
140
+ */
141
+ spec: import("swagger-schema-official").Spec;
115
142
  }
116
143
 
144
+ export type GenerateApiParams = GenerateApiParamsFromPath | GenerateApiParamsFromUrl | GenerateApiParamsFromSpecLiteral;
145
+
117
146
  export interface Hooks {
118
147
  /** calls after parse schema component */
119
148
  onCreateComponent: (component: SchemaComponent) => SchemaComponent | void;
@@ -126,14 +155,9 @@ export interface Hooks {
126
155
  /** customize configuration object before sending it to ETA templates */
127
156
  onPrepareConfig?: <C extends GenerateApiConfiguration>(currentConfiguration: C) => C | void;
128
157
  /** customize route name as you need */
129
- onCreateRouteName?: (
130
- routeNameInfo: RouteNameInfo,
131
- rawRouteInfo: RawRouteInfo,
132
- ) => RouteNameInfo | void;
158
+ onCreateRouteName?: (routeNameInfo: RouteNameInfo, rawRouteInfo: RawRouteInfo) => RouteNameInfo | void;
133
159
  /** customize request params (path params, query params) */
134
- onCreateRequestParams?: (
135
- rawType: SchemaComponent["rawTypeData"],
136
- ) => SchemaComponent["rawTypeData"] | void;
160
+ onCreateRequestParams?: (rawType: SchemaComponent["rawTypeData"]) => SchemaComponent["rawTypeData"] | void;
137
161
  /** customize name of model type */
138
162
  onFormatTypeName?: (typeName: string, rawTypeName?: string) => string | void;
139
163
  /** customize name of route (operationId), you can do it with using onCreateRouteName too */
@@ -210,14 +234,10 @@ export interface SchemaComponent {
210
234
  discriminator?: {
211
235
  propertyName?: string;
212
236
  };
213
- $parsed: ParsedSchema<
214
- SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent
215
- >;
237
+ $parsed: ParsedSchema<SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent>;
216
238
  };
217
239
  componentName: string;
218
- typeData: ParsedSchema<
219
- SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent
220
- > | null;
240
+ typeData: ParsedSchema<SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent> | null;
221
241
  }
222
242
 
223
243
  export enum RequestContentKind {
@@ -323,6 +343,7 @@ export interface GenerateApiConfiguration {
323
343
  routeName: string;
324
344
  };
325
345
  routeNameDuplicatesMap: Map<string, string>;
346
+ apiClassName: string
326
347
  };
327
348
  modelTypes: ModelType[];
328
349
  rawModelTypes: SchemaComponent[];
@@ -341,10 +362,7 @@ export interface GenerateApiConfiguration {
341
362
  formatDescription: (description: string, inline?: boolean) => string;
342
363
  internalCase: (value: string) => string;
343
364
  classNameCase: (value: string) => string;
344
- getInlineParseContent: (
345
- rawTypeData: SchemaComponent["rawTypeData"],
346
- typeName?: string,
347
- ) => string;
365
+ getInlineParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => string;
348
366
  getParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => ModelType;
349
367
  getComponentByRef: (ref: string) => SchemaComponent;
350
368
  parseSchema: (
@@ -352,14 +370,8 @@ export interface GenerateApiConfiguration {
352
370
  typeName?: string,
353
371
  formattersMap?: Record<MAIN_SCHEMA_TYPES, (content: ModelType) => string>,
354
372
  ) => ModelType;
355
- formatters: Record<
356
- MAIN_SCHEMA_TYPES,
357
- (content: string | object | string[] | object[]) => string
358
- >;
359
- inlineExtraFormatters: Record<
360
- Exclude<MAIN_SCHEMA_TYPES, SCHEMA_TYPES.PRIMITIVE>,
361
- (schema: ModelType) => string
362
- >;
373
+ formatters: Record<MAIN_SCHEMA_TYPES, (content: string | object | string[] | object[]) => string>;
374
+ inlineExtraFormatters: Record<Exclude<MAIN_SCHEMA_TYPES, SCHEMA_TYPES.PRIMITIVE>, (schema: ModelType) => string>;
363
375
  formatModelName: (name: string) => string;
364
376
  fmtToJSDocLine: (line: string, params?: { eol?: boolean }) => string;
365
377
  _: import("lodash").LoDashStatic;
@@ -370,12 +382,7 @@ export interface GenerateApiConfiguration {
370
382
  export interface GenerateApiOutput {
371
383
  configuration: GenerateApiConfiguration;
372
384
  files: { name: string; content: string; declaration: { name: string; content: string } | null }[];
373
- createFile: (params: {
374
- path: string;
375
- fileName: string;
376
- content: string;
377
- withPrefix?: boolean;
378
- }) => void;
385
+ createFile: (params: { path: string; fileName: string; content: string; withPrefix?: boolean }) => void;
379
386
  renderTemplate: (
380
387
  templateContent: string,
381
388
  data: Record<string, unknown>,
@@ -385,12 +392,4 @@ export interface GenerateApiOutput {
385
392
  formatTSContent: (content: string) => string;
386
393
  }
387
394
 
388
- export declare function generateApi(
389
- params: Omit<GenerateApiParams, "url" | "spec">,
390
- ): Promise<GenerateApiOutput>;
391
- export declare function generateApi(
392
- params: Omit<GenerateApiParams, "input" | "spec">,
393
- ): Promise<GenerateApiOutput>;
394
- export declare function generateApi(
395
- params: Omit<GenerateApiParams, "input" | "url">,
396
- ): Promise<GenerateApiOutput>;
395
+ export declare function generateApi(params: GenerateApiParams): Promise<GenerateApiOutput>;
package/index.js CHANGED
@@ -33,29 +33,23 @@ program
33
33
  )
34
34
  .option(
35
35
  "-r, --responses",
36
- "generate additional information about request responses\n" +
37
- "also add typings for bad responses",
36
+ "generate additional information about request responses\n" + "also add typings for bad responses",
38
37
  false,
39
38
  )
40
39
  .option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
40
+ .option("--add-readonly", "generate readonly properties", false)
41
41
  .option("--route-types", "generate type definitions for API routes", false)
42
42
  .option("--no-client", "do not generate an API class", false)
43
- .option(
44
- "--enum-names-as-values",
45
- "use values in 'x-enumNames' as enum values (not only as keys)",
46
- false,
47
- )
43
+ .option("--enum-names-as-values", "use values in 'x-enumNames' as enum values (not only as keys)", false)
48
44
  .option(
49
45
  "--extract-request-params",
50
46
  "extract request params to data contract (Also combine path params and query params into one object)",
51
47
  false,
52
48
  )
53
49
  .option("--extract-request-body", "extract request body type to data contract", false)
54
- .option(
55
- "--modular",
56
- "generate separated files for http client, data contracts, and routes",
57
- false,
58
- )
50
+ .option("--extract-response-body", "extract response body type to data contract", false)
51
+ .option("--extract-response-error", "extract response error type to data contract", false)
52
+ .option("--modular", "generate separated files for http client, data contracts, and routes", false)
59
53
  .option("--js", "generate js api module with declaration file", false)
60
54
  .option(
61
55
  "--module-name-index <number>",
@@ -67,74 +61,55 @@ program
67
61
  .option("--disableProxy", "disabled proxy", false)
68
62
  .option("--axios", "generate axios http client", false)
69
63
  .option("--unwrap-response-data", "unwrap the data item from the response", false)
64
+ .option("--disable-throw-on-error", "Do not throw an error when response.ok is not true", false)
70
65
  .option("--single-http-client", "Ability to send HttpClient instance to Api constructor", false)
71
66
  .option("--silent", "Output only errors to console", false)
72
67
  .option("--default-response <type>", "default type for empty response schema", TS_KEYWORDS.VOID)
73
68
  .option("--type-prefix <string>", "data contract name prefix", "")
74
69
  .option("--type-suffix <string>", "data contract name suffix", "")
75
- .option(
76
- "--clean-output",
77
- "clean output folder before generate api. WARNING: May cause data loss",
78
- false,
79
- );
70
+ .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);
80
72
 
81
73
  program.parse(process.argv);
82
74
 
83
- const {
84
- path,
85
- output,
86
- name,
87
- templates,
88
- unionEnums,
89
- routeTypes,
90
- client,
91
- defaultAsSuccess,
92
- responses,
93
- modular,
94
- js,
95
- moduleNameIndex,
96
- moduleNameFirstTag,
97
- extractRequestParams,
98
- extractRequestBody,
99
- enumNamesAsValues,
100
- disableStrictSSL,
101
- disableProxy,
102
- cleanOutput,
103
- defaultResponse,
104
- unwrapResponseData,
105
- singleHttpClient,
106
- axios,
107
- silent,
108
- typePrefix,
109
- typeSuffix,
110
- } = program;
111
-
112
75
  generateApi({
113
- name,
114
- url: path,
115
- generateRouteTypes: routeTypes,
116
- generateClient: !!(axios || client),
117
- httpClientType: axios ? HTTP_CLIENT.AXIOS : HTTP_CLIENT.FETCH,
118
- defaultResponseAsSuccess: defaultAsSuccess,
119
- defaultResponseType: defaultResponse,
120
- unwrapResponseData: unwrapResponseData,
121
- generateUnionEnums: unionEnums,
122
- generateResponses: responses,
123
- extractRequestParams: !!extractRequestParams,
124
- extractRequestBody: !!extractRequestBody,
125
- input: resolve(process.cwd(), path),
126
- output: resolve(process.cwd(), output || "."),
127
- templates,
128
- modular: !!modular,
129
- toJS: !!js,
130
- enumNamesAsValues: enumNamesAsValues,
131
- moduleNameIndex: +(moduleNameIndex || 0),
132
- moduleNameFirstTag: moduleNameFirstTag,
133
- disableStrictSSL: !!disableStrictSSL,
134
- disableProxy: !!disableProxy,
135
- singleHttpClient: !!singleHttpClient,
136
- cleanOutput: !!cleanOutput,
137
- silent: !!silent,
138
- typePrefix,
139
- typeSuffix,
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,
110
+ }).catch((err) => {
111
+ // NOTE collect all errors on top level and shows to users in any case
112
+ console.error(err);
113
+
114
+ process.exit(1);
140
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-typescript-api",
3
- "version": "9.2.0",
3
+ "version": "10.0.0",
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",
@@ -23,6 +23,7 @@
23
23
  "test:--default-as-success": "node tests/spec/defaultAsSuccess/test.js",
24
24
  "test:--templates": "node tests/spec/templates/test.js",
25
25
  "test:--union-enums": "node tests/spec/unionEnums/test.js",
26
+ "test:--add-readonly": "node tests/spec/readonly/test.js",
26
27
  "test:--responses": "node tests/spec/responses/test.js",
27
28
  "test:specProperty": "node tests/spec/specProperty/test.js",
28
29
  "test:--module-name-index": "node tests/spec/moduleNameIndex/test.js",
@@ -31,6 +32,8 @@
31
32
  "test:--single-http-client": "node tests/spec/singleHttpClient/test.js",
32
33
  "test:--extract-request-params": "node tests/spec/extractRequestParams/test.js",
33
34
  "test:--extract-request-body": "node tests/spec/extractRequestBody/test.js",
35
+ "test:--extract-response-body": "node tests/spec/extractResponseBody/test.js",
36
+ "test:--extract-response-error": "node tests/spec/extractResponseError/test.js",
34
37
  "test:--enum-names-as-values": "node tests/spec/enumNamesAsValues/test.js",
35
38
  "test:--default-response": "node tests/spec/defaultResponse/test.js",
36
39
  "test:--js": "node tests/spec/js/test.js",
@@ -39,34 +42,37 @@
39
42
  "test:--axios--single-http-client": "node tests/spec/axiosSingleHttpClient/test.js",
40
43
  "test:--type-suffix--type-prefix": "node tests/spec/typeSuffixPrefix/test.js",
41
44
  "test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
42
- "test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js"
45
+ "test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
46
+ "test:--patch": "node tests/spec/patch/test.js"
43
47
  },
44
48
  "author": "acacode",
45
49
  "license": "MIT",
46
50
  "typings": "./index.d.ts",
47
51
  "main": "src/index.js",
48
52
  "devDependencies": {
49
- "@types/lodash": "^4.14.166",
53
+ "@types/axios": "^0.14.0",
54
+ "@types/lodash": "^4.14.182",
50
55
  "@types/node": "^15.0.2",
51
- "@types/prettier": "^2.1.6",
52
- "all-contributors-cli": "^6.19.0",
56
+ "@types/prettier": "^2.7.0",
57
+ "all-contributors-cli": "^6.20.0",
53
58
  "husky": "^4.3.6",
54
59
  "pretty-quick": "^3.1.0"
55
60
  },
56
61
  "dependencies": {
57
- "@types/swagger-schema-official": "2.0.21",
58
- "axios": "^0.21.1",
59
- "commander": "^6.2.1",
60
- "eta": "^1.12.1",
61
- "js-yaml": "^4.0.0",
62
+ "axios": "^0.27.2",
63
+ "@types/swagger-schema-official": "2.0.22",
64
+ "commander": "^9.4.0",
65
+ "cosmiconfig": "^7.0.1",
66
+ "eta": "^1.12.3",
67
+ "js-yaml": "^4.1.0",
62
68
  "lodash": "^4.17.21",
63
69
  "make-dir": "^3.1.0",
64
- "nanoid": "^3.1.22",
65
- "node-emoji": "^1.10.0",
66
- "prettier": "^2.2.1",
70
+ "nanoid": "^3.3.4",
71
+ "node-emoji": "^1.11.0",
72
+ "prettier": "^2.7.1",
67
73
  "swagger-schema-official": "2.0.0-bab6bed",
68
- "swagger2openapi": "^7.0.5",
69
- "typescript": "^4.2.4"
74
+ "swagger2openapi": "^7.0.8",
75
+ "typescript": "^4.7.4"
70
76
  },
71
77
  "bin": {
72
78
  "swagger-typescript-api": "index.js",
package/src/config.js CHANGED
@@ -14,6 +14,8 @@ const config = {
14
14
  generateClient: true,
15
15
  /** CLI flag */
16
16
  generateUnionEnums: false,
17
+ /** CLI flag */
18
+ addReadonly: false,
17
19
  enumNamesAsValues: false,
18
20
  /** parsed swagger schema from getSwaggerObject() */
19
21
 
@@ -36,6 +38,8 @@ const config = {
36
38
  disableProxy: false,
37
39
  extractRequestParams: false,
38
40
  extractRequestBody: false,
41
+ extractResponseBody: false,
42
+ extractResponseError: false,
39
43
  fileNames: {
40
44
  dataContracts: "data-contracts",
41
45
  routeTypes: "route-types",
@@ -59,6 +63,8 @@ const config = {
59
63
  singleHttpClient: false,
60
64
  httpClientType: HTTP_CLIENT.FETCH,
61
65
  unwrapResponseData: false,
66
+ disableThrowOnError: false,
67
+ sortTypes: false,
62
68
  templatePaths: {
63
69
  /** `templates/base` */
64
70
  base: "",
@@ -83,7 +89,10 @@ const config = {
83
89
  silent: false,
84
90
  typePrefix: "",
85
91
  typeSuffix: "",
92
+ patch: false,
86
93
  componentTypeNameResolver: new NameResolver([]),
94
+ /** name of the main exported class */
95
+ apiClassName: "Api",
87
96
  };
88
97
 
89
98
  /** needs to use data everywhere in project */