@hey-api/openapi-ts 0.30.0 → 0.31.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 +38 -41
- package/bin/index.js +1 -2
- package/dist/node/index.d.ts +2 -7
- package/dist/node/index.js +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -100,14 +100,29 @@ Alternatively, you can use `openapi-ts.config.js` and configure the export state
|
|
|
100
100
|
|
|
101
101
|
### Clients
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
By default, `openapi-ts` will try to guess your client based on your project dependencies. If we don't get it right, you can specify the desired client
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
```mjs
|
|
106
|
+
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
107
|
+
export default {
|
|
108
|
+
client: 'fetch',
|
|
109
|
+
input: 'path/to/openapi.json',
|
|
110
|
+
output: 'src/client',
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
We support these clients:
|
|
115
|
+
|
|
116
|
+
- [angular](https://angular.io/) (using [RxJS](https://rxjs.dev/))
|
|
117
|
+
- [axios](https://axios-http.com/)
|
|
118
|
+
- [fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API)
|
|
119
|
+
|
|
120
|
+
We also support the legacy Node.js and XHR clients:
|
|
121
|
+
|
|
122
|
+
- [node](https://nodejs.org/) (using [node-fetch](https://www.npmjs.com/package/node-fetch))
|
|
123
|
+
- [xhr](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest)
|
|
124
|
+
|
|
125
|
+
> ⚠️ You might not need a `node` client. Fetch API is [experimental](https://nodejs.org/docs/latest-v18.x/api/globals.html#fetch) in Node.js v18 and [stable](https://nodejs.org/docs/latest-v21.x/api/globals.html#fetch) in Node.js v21. We recommend upgrading to the latest Node.js version.
|
|
111
126
|
|
|
112
127
|
### Formatting
|
|
113
128
|
|
|
@@ -141,18 +156,18 @@ You can also prevent your client from being processed by linters by adding your
|
|
|
141
156
|
|
|
142
157
|
### Enums
|
|
143
158
|
|
|
144
|
-
|
|
159
|
+
If you need to iterate through possible field values without manually typing arrays, you can export enums with
|
|
145
160
|
|
|
146
161
|
```mjs
|
|
147
162
|
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
148
163
|
export default {
|
|
149
|
-
enums:
|
|
164
|
+
enums: 'javascript',
|
|
150
165
|
input: 'path/to/openapi.json',
|
|
151
166
|
output: 'src/client',
|
|
152
167
|
}
|
|
153
168
|
```
|
|
154
169
|
|
|
155
|
-
This will export
|
|
170
|
+
This will export enums as plain JavaScript objects. For example, `Foo` would become
|
|
156
171
|
|
|
157
172
|
```ts
|
|
158
173
|
export const FooEnum = {
|
|
@@ -161,39 +176,21 @@ export const FooEnum = {
|
|
|
161
176
|
} as const;
|
|
162
177
|
```
|
|
163
178
|
|
|
164
|
-
|
|
179
|
+
We discourage generating [TypeScript enums](https://www.typescriptlang.org/docs/handbook/enums.html) because they are not standard JavaScript and pose [typing challenges](https://dev.to/ivanzm123/dont-use-enums-in-typescript-they-are-very-dangerous-57bh). If you really need TypeScript enums, you can export them with
|
|
165
180
|
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
|
|
174
|
-
-o, --output <value> Output directory (required)
|
|
175
|
-
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
|
|
176
|
-
--name <value> Custom client class name
|
|
177
|
-
--useOptions <value> Use options instead of arguments (default: true)
|
|
178
|
-
--base <value> Manually set base in OpenAPI config instead of inferring from server value
|
|
179
|
-
--enums Generate JavaScript objects from enum definitions (default: false)
|
|
180
|
-
--exportCore <value> Write core files to disk (default: true)
|
|
181
|
-
--exportServices <value> Write services to disk [true, false, regexp] (default: true)
|
|
182
|
-
--exportModels <value> Write models to disk [true, false, regexp] (default: true)
|
|
183
|
-
--exportSchemas <value> Write schemas to disk (default: true)
|
|
184
|
-
--format Process output folder with formatter?
|
|
185
|
-
--no-format Disable processing output folder with formatter
|
|
186
|
-
--lint Process output folder with linter?
|
|
187
|
-
--no-lint Disable processing output folder with linter
|
|
188
|
-
--no-operationId Use path URL to generate operation ID
|
|
189
|
-
--postfixServices Service name postfix (default: "Service")
|
|
190
|
-
--postfixModels Model name postfix
|
|
191
|
-
--request <value> Path to custom request file
|
|
192
|
-
--useDateType <value> Output Date instead of string for the format "date-time" in the models (default: false)
|
|
193
|
-
--useLegacyEnums Generate Typescript enum definitions (default: false)
|
|
194
|
-
-h, --help display help for command
|
|
181
|
+
```mjs
|
|
182
|
+
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
183
|
+
export default {
|
|
184
|
+
enums: 'typescript',
|
|
185
|
+
input: 'path/to/openapi.json',
|
|
186
|
+
output: 'src/client',
|
|
187
|
+
}
|
|
195
188
|
```
|
|
196
189
|
|
|
190
|
+
### Config API
|
|
191
|
+
|
|
192
|
+
You can view the complete list of options in the [UserConfig](./src/types/config.ts) interface.
|
|
193
|
+
|
|
197
194
|
## Interceptors
|
|
198
195
|
|
|
199
196
|
Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to the rest of your application. Below is an example request interceptor
|
|
@@ -216,7 +213,7 @@ OpenAPI.interceptors.response.use(async (response) => {
|
|
|
216
213
|
|
|
217
214
|
If you need to remove an interceptor, pass the same function to `OpenAPI.interceptors.request.eject()` or `OpenAPI.interceptors.response.eject()`.
|
|
218
215
|
|
|
219
|
-
> ⚠️ Angular client does not currently support request interceptors
|
|
216
|
+
> ⚠️ Angular client does not currently support request interceptors.
|
|
220
217
|
|
|
221
218
|
## Migrating
|
|
222
219
|
|
package/bin/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const params = program
|
|
|
18
18
|
.option('--name <value>', 'Custom client class name')
|
|
19
19
|
.option('--useOptions [value]', 'Use options instead of arguments')
|
|
20
20
|
.option('--base [value]', 'Manually set base in OpenAPI config instead of inferring from server value')
|
|
21
|
-
.option('--enums', '
|
|
21
|
+
.option('--enums <value>', 'Export enum definitions (javascript, typescript)')
|
|
22
22
|
.option('--exportCore <value>', 'Write core files to disk')
|
|
23
23
|
.option('--exportServices <value>', 'Write services to disk')
|
|
24
24
|
.option('--exportModels <value>', 'Write models to disk')
|
|
@@ -36,7 +36,6 @@ const params = program
|
|
|
36
36
|
.option('--request <value>', 'Path to custom request file')
|
|
37
37
|
.option('--write', 'Write files to disk? (used for testing)')
|
|
38
38
|
.option('--no-write', 'Skip writing files to disk (used for testing)')
|
|
39
|
-
.option('--useLegacyEnums', 'Generate Typescript enum definitions')
|
|
40
39
|
.parse(process.argv)
|
|
41
40
|
.opts();
|
|
42
41
|
|
package/dist/node/index.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ interface UserConfig {
|
|
|
9
9
|
*/
|
|
10
10
|
client?: 'angular' | 'axios' | 'fetch' | 'node' | 'xhr';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Export enum definitions?
|
|
13
13
|
* @default false
|
|
14
14
|
*/
|
|
15
|
-
enums?:
|
|
15
|
+
enums?: 'javascript' | 'typescript' | false;
|
|
16
16
|
/**
|
|
17
17
|
* Generate core client classes?
|
|
18
18
|
* @default true
|
|
@@ -89,11 +89,6 @@ interface UserConfig {
|
|
|
89
89
|
* @default true
|
|
90
90
|
*/
|
|
91
91
|
useOptions?: boolean;
|
|
92
|
-
/**
|
|
93
|
-
* Generate Typescript enum definitions
|
|
94
|
-
* @default false
|
|
95
|
-
*/
|
|
96
|
-
useLegacyEnums?: boolean;
|
|
97
92
|
/**
|
|
98
93
|
* Write the files to disk (true or false)
|
|
99
94
|
* @default true
|