@hey-api/openapi-ts 0.37.3 → 0.38.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/README.md +6 -6
- package/bin/index.js +31 -23
- package/dist/node/index.d.ts +100 -105
- package/dist/node/index.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
9
|
+
- Generate TypeScript clients from OpenAPI v2.0, v3.0, and v3.1 specifications
|
|
10
|
+
- Support JSON or YAML input files
|
|
11
|
+
- Handle external references using [JSON Schema $Ref Parser](https://github.com/APIDevTools/json-schema-ref-parser/)
|
|
12
|
+
- Generate Fetch, Node-Fetch, Axios, Angular, or XHR HTTP clients
|
|
13
|
+
- Can be used with CLI, Node.js, or npx
|
|
14
|
+
- Abortable requests through cancellable promise pattern
|
|
15
15
|
|
|
16
16
|
## Migrating from OpenAPI Typescript Codegen?
|
|
17
17
|
|
package/bin/index.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
6
7
|
|
|
8
|
+
import camelCase from 'camelcase';
|
|
7
9
|
import { program } from 'commander';
|
|
8
10
|
|
|
9
11
|
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)).toString());
|
|
@@ -17,6 +19,7 @@ const params = program
|
|
|
17
19
|
.option('-c, --client <value>', 'HTTP client to generate [angular, axios, fetch, node, xhr]')
|
|
18
20
|
.option('-d, --debug', 'Run in debug mode?')
|
|
19
21
|
.option('--base [value]', 'Manually set base in OpenAPI config instead of inferring from server value')
|
|
22
|
+
.option('--dry-run [value]', 'Skip writing files to disk?')
|
|
20
23
|
.option('--enums <value>', 'Export enum definitions (javascript, typescript)')
|
|
21
24
|
.option('--exportCore [value]', 'Write core files to disk')
|
|
22
25
|
.option('--exportModels [value]', 'Write models to disk')
|
|
@@ -31,7 +34,6 @@ const params = program
|
|
|
31
34
|
.option('--serviceResponse [value]', 'Define shape of returned value from service calls')
|
|
32
35
|
.option('--useDateType [value]', 'Output Date instead of string for the format "date-time" in the models')
|
|
33
36
|
.option('--useOptions [value]', 'Use options instead of arguments')
|
|
34
|
-
.option('--write [value]', 'Write files to disk? (used for testing)')
|
|
35
37
|
.parse(process.argv)
|
|
36
38
|
.opts();
|
|
37
39
|
|
|
@@ -45,38 +47,44 @@ const stringToBoolean = value => {
|
|
|
45
47
|
return value;
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
const processParams = (obj,
|
|
49
|
-
const
|
|
50
|
-
for (const key of keys) {
|
|
50
|
+
const processParams = (obj, booleanKeys) => {
|
|
51
|
+
for (const key of booleanKeys) {
|
|
51
52
|
const value = obj[key];
|
|
52
53
|
if (typeof value === 'string') {
|
|
53
|
-
|
|
54
|
+
const parsedValue = stringToBoolean(value);
|
|
55
|
+
delete obj[key];
|
|
56
|
+
obj[camelCase(key)] = parsedValue;
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
|
-
return
|
|
59
|
+
return obj;
|
|
57
60
|
};
|
|
58
61
|
|
|
59
62
|
async function start() {
|
|
63
|
+
let userConfig;
|
|
60
64
|
try {
|
|
61
65
|
const { createClient } = await import(new URL('../dist/node/index.js', import.meta.url));
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
]),
|
|
76
|
-
});
|
|
66
|
+
userConfig = processParams(params, [
|
|
67
|
+
'dryRun',
|
|
68
|
+
'exportCore',
|
|
69
|
+
'exportModels',
|
|
70
|
+
'exportServices',
|
|
71
|
+
'format',
|
|
72
|
+
'lint',
|
|
73
|
+
'operationId',
|
|
74
|
+
'schemas',
|
|
75
|
+
'useDateType',
|
|
76
|
+
'useOptions',
|
|
77
|
+
]);
|
|
78
|
+
await createClient(userConfig);
|
|
77
79
|
process.exit(0);
|
|
78
80
|
} catch (error) {
|
|
79
|
-
|
|
81
|
+
if (!userConfig.dryRun) {
|
|
82
|
+
const logName = `openapi-ts-error-${Date.now()}.log`;
|
|
83
|
+
const logPath = path.resolve(process.cwd(), logName);
|
|
84
|
+
writeFileSync(logPath, `${error.message}\n${error.stack}`);
|
|
85
|
+
console.error(`🔥 Unexpected error occurred. Log saved to ${logPath}`);
|
|
86
|
+
}
|
|
87
|
+
console.error(`🔥 Unexpected error occurred. ${error.message}`);
|
|
80
88
|
process.exit(1);
|
|
81
89
|
}
|
|
82
90
|
}
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,109 +1,6 @@
|
|
|
1
|
-
interface UserConfig {
|
|
2
|
-
/**
|
|
3
|
-
* Manually set base in OpenAPI config instead of inferring from server value
|
|
4
|
-
*/
|
|
5
|
-
base?: string;
|
|
6
|
-
/**
|
|
7
|
-
* The selected HTTP client (fetch, xhr, node or axios)
|
|
8
|
-
* @default 'fetch'
|
|
9
|
-
*/
|
|
10
|
-
client?: 'angular' | 'axios' | 'fetch' | 'node' | 'xhr';
|
|
11
|
-
/**
|
|
12
|
-
* Run in debug mode?
|
|
13
|
-
* @default false
|
|
14
|
-
*/
|
|
15
|
-
debug?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Export enum definitions?
|
|
18
|
-
* @default false
|
|
19
|
-
*/
|
|
20
|
-
enums?: 'javascript' | 'typescript' | false;
|
|
21
|
-
/**
|
|
22
|
-
* Generate an experimental build?
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
25
|
-
experimental?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Generate core client classes?
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
exportCore?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Generate models?
|
|
33
|
-
* @default true
|
|
34
|
-
*/
|
|
35
|
-
exportModels?: boolean | string;
|
|
36
|
-
/**
|
|
37
|
-
* Generate services?
|
|
38
|
-
* @default true
|
|
39
|
-
*/
|
|
40
|
-
exportServices?: boolean | string;
|
|
41
|
-
/**
|
|
42
|
-
* Process output folder with formatter?
|
|
43
|
-
* @default true
|
|
44
|
-
*/
|
|
45
|
-
format?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* The relative location of the OpenAPI spec
|
|
48
|
-
*/
|
|
49
|
-
input: string | Record<string, unknown>;
|
|
50
|
-
/**
|
|
51
|
-
* Process output folder with linter?
|
|
52
|
-
* @default false
|
|
53
|
-
*/
|
|
54
|
-
lint?: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Custom client class name
|
|
57
|
-
*/
|
|
58
|
-
name?: string;
|
|
59
|
-
/**
|
|
60
|
-
* Use operation ID to generate operation names?
|
|
61
|
-
* @default true
|
|
62
|
-
*/
|
|
63
|
-
operationId?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* The relative location of the output directory
|
|
66
|
-
*/
|
|
67
|
-
output: string;
|
|
68
|
-
/**
|
|
69
|
-
* Service name postfix
|
|
70
|
-
* @default 'Service'
|
|
71
|
-
*/
|
|
72
|
-
postfixServices?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Path to custom request file
|
|
75
|
-
*/
|
|
76
|
-
request?: string;
|
|
77
|
-
/**
|
|
78
|
-
* Export JSON schemas?
|
|
79
|
-
* @default true
|
|
80
|
-
*/
|
|
81
|
-
schemas?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Define shape of returned value from service calls
|
|
84
|
-
* @default 'body'
|
|
85
|
-
*/
|
|
86
|
-
serviceResponse?: 'body' | 'response';
|
|
87
|
-
/**
|
|
88
|
-
* Output Date instead of string for the format "date-time" in the models
|
|
89
|
-
* @default false
|
|
90
|
-
*/
|
|
91
|
-
useDateType?: boolean;
|
|
92
|
-
/**
|
|
93
|
-
* Use options or arguments functions
|
|
94
|
-
* @default true
|
|
95
|
-
*/
|
|
96
|
-
useOptions?: boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Write the files to disk (true or false)
|
|
99
|
-
* @default true
|
|
100
|
-
*/
|
|
101
|
-
write?: boolean;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
1
|
interface Enum {
|
|
105
|
-
|
|
106
|
-
|
|
2
|
+
customDescription?: string;
|
|
3
|
+
customName?: string;
|
|
107
4
|
description?: string;
|
|
108
5
|
value: string | number;
|
|
109
6
|
}
|
|
@@ -201,6 +98,104 @@ interface Client {
|
|
|
201
98
|
version: string;
|
|
202
99
|
}
|
|
203
100
|
|
|
101
|
+
interface UserConfig {
|
|
102
|
+
/**
|
|
103
|
+
* Manually set base in OpenAPI config instead of inferring from server value
|
|
104
|
+
*/
|
|
105
|
+
base?: string;
|
|
106
|
+
/**
|
|
107
|
+
* The selected HTTP client (fetch, xhr, node or axios)
|
|
108
|
+
* @default 'fetch'
|
|
109
|
+
*/
|
|
110
|
+
client?: 'angular' | 'axios' | 'fetch' | 'node' | 'xhr';
|
|
111
|
+
/**
|
|
112
|
+
* Run in debug mode?
|
|
113
|
+
* @default false
|
|
114
|
+
*/
|
|
115
|
+
debug?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Skip writing files to disk?
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
120
|
+
dryRun?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Export enum definitions?
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
enums?: 'javascript' | 'typescript' | false;
|
|
126
|
+
/**
|
|
127
|
+
* Generate core client classes?
|
|
128
|
+
* @default true
|
|
129
|
+
*/
|
|
130
|
+
exportCore?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Generate models?
|
|
133
|
+
* @default true
|
|
134
|
+
*/
|
|
135
|
+
exportModels?: boolean | string;
|
|
136
|
+
/**
|
|
137
|
+
* Generate services?
|
|
138
|
+
* @default true
|
|
139
|
+
*/
|
|
140
|
+
exportServices?: boolean | string;
|
|
141
|
+
/**
|
|
142
|
+
* Process output folder with formatter?
|
|
143
|
+
* @default true
|
|
144
|
+
*/
|
|
145
|
+
format?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* The relative location of the OpenAPI spec
|
|
148
|
+
*/
|
|
149
|
+
input: string | Record<string, unknown>;
|
|
150
|
+
/**
|
|
151
|
+
* Process output folder with linter?
|
|
152
|
+
* @default false
|
|
153
|
+
*/
|
|
154
|
+
lint?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Custom client class name
|
|
157
|
+
*/
|
|
158
|
+
name?: string;
|
|
159
|
+
/**
|
|
160
|
+
* Use operation ID to generate operation names?
|
|
161
|
+
* @default true
|
|
162
|
+
*/
|
|
163
|
+
operationId?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* The relative location of the output directory
|
|
166
|
+
*/
|
|
167
|
+
output: string;
|
|
168
|
+
/**
|
|
169
|
+
* Service name postfix
|
|
170
|
+
* @default 'Service'
|
|
171
|
+
*/
|
|
172
|
+
postfixServices?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Path to custom request file
|
|
175
|
+
*/
|
|
176
|
+
request?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Export JSON schemas?
|
|
179
|
+
* @default true
|
|
180
|
+
*/
|
|
181
|
+
schemas?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Define shape of returned value from service calls
|
|
184
|
+
* @default 'body'
|
|
185
|
+
*/
|
|
186
|
+
serviceResponse?: 'body' | 'response';
|
|
187
|
+
/**
|
|
188
|
+
* Output Date instead of string for the format "date-time" in the models
|
|
189
|
+
* @default false
|
|
190
|
+
*/
|
|
191
|
+
useDateType?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Use options or arguments functions
|
|
194
|
+
* @default true
|
|
195
|
+
*/
|
|
196
|
+
useOptions?: boolean;
|
|
197
|
+
}
|
|
198
|
+
|
|
204
199
|
/**
|
|
205
200
|
* Generate the OpenAPI client. This method will read the OpenAPI specification and based on the
|
|
206
201
|
* given language it will generate the client, including the typed models, validation schemas,
|