@hey-api/openapi-ts 0.0.0-next-20260205083026
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/LICENSE.md +21 -0
- package/README.md +381 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +18 -0
- package/dist/clients/angular/client.ts +237 -0
- package/dist/clients/angular/index.ts +23 -0
- package/dist/clients/angular/types.ts +231 -0
- package/dist/clients/angular/utils.ts +408 -0
- package/dist/clients/axios/client.ts +154 -0
- package/dist/clients/axios/index.ts +21 -0
- package/dist/clients/axios/types.ts +158 -0
- package/dist/clients/axios/utils.ts +206 -0
- package/dist/clients/core/auth.ts +39 -0
- package/dist/clients/core/bodySerializer.ts +82 -0
- package/dist/clients/core/params.ts +167 -0
- package/dist/clients/core/pathSerializer.ts +169 -0
- package/dist/clients/core/queryKeySerializer.ts +115 -0
- package/dist/clients/core/serverSentEvents.ts +241 -0
- package/dist/clients/core/types.ts +102 -0
- package/dist/clients/core/utils.ts +138 -0
- package/dist/clients/fetch/client.ts +286 -0
- package/dist/clients/fetch/index.ts +23 -0
- package/dist/clients/fetch/types.ts +211 -0
- package/dist/clients/fetch/utils.ts +314 -0
- package/dist/clients/ky/client.ts +318 -0
- package/dist/clients/ky/index.ts +24 -0
- package/dist/clients/ky/types.ts +243 -0
- package/dist/clients/ky/utils.ts +312 -0
- package/dist/clients/next/client.ts +253 -0
- package/dist/clients/next/index.ts +21 -0
- package/dist/clients/next/types.ts +162 -0
- package/dist/clients/next/utils.ts +413 -0
- package/dist/clients/nuxt/client.ts +213 -0
- package/dist/clients/nuxt/index.ts +22 -0
- package/dist/clients/nuxt/types.ts +189 -0
- package/dist/clients/nuxt/utils.ts +384 -0
- package/dist/clients/ofetch/client.ts +259 -0
- package/dist/clients/ofetch/index.ts +23 -0
- package/dist/clients/ofetch/types.ts +275 -0
- package/dist/clients/ofetch/utils.ts +504 -0
- package/dist/index.d.mts +8634 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/init-DlaW5Djq.mjs +13832 -0
- package/dist/init-DlaW5Djq.mjs.map +1 -0
- package/dist/internal.d.mts +33 -0
- package/dist/internal.d.mts.map +1 -0
- package/dist/internal.mjs +4 -0
- package/dist/run.d.mts +1 -0
- package/dist/run.mjs +60 -0
- package/dist/run.mjs.map +1 -0
- package/dist/src-BYA2YioO.mjs +225 -0
- package/dist/src-BYA2YioO.mjs.map +1 -0
- package/dist/types-Ba27ofyy.d.mts +157 -0
- package/dist/types-Ba27ofyy.d.mts.map +1 -0
- package/package.json +109 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Hey API
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img alt="Hey API presents openapi-ts" height="214" src="https://heyapi.dev/assets/.gen/openapi-ts-hero-640w.png" width="438">
|
|
3
|
+
<h1><b>OpenAPI TypeScript</b></h1>
|
|
4
|
+
<p><em>“OpenAPI codegen that just works.”</em><br/><sub>— Guillermo Rauch, CEO of Vercel</sub></p>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.devtrends.dev/trends?c=v1.kZIBIg"><img src="https://api.devtrends.dev/badge/npm/%40hey-api%2Fopenapi-ts?period=month&style=flat&view=value" alt="DevTrends badge for @hey-api/openapi-ts" /></a>
|
|
9
|
+
<a href="https://www.devtrends.dev/trends?c=v1.kZIBIg&v=change"><img src="https://api.devtrends.dev/badge/npm/%40hey-api%2Fopenapi-ts?period=year&style=flat&view=change" alt="DevTrends badge for @hey-api/openapi-ts" /></a>
|
|
10
|
+
<a href="https://github.com/hey-api/openapi-ts/actions?query=branch%3Amain"><img src="https://github.com/hey-api/openapi-ts/actions/workflows/ci.yml/badge.svg?event=push&branch=main" alt="CI status" /></a>
|
|
11
|
+
<a href="https://github.com/hey-api/openapi-ts"><img src="https://img.shields.io/github/stars/hey-api/openapi-ts?style=flat&logo=github&label=GitHub&color=54C82D" alt="GitHub stars" /></a>
|
|
12
|
+
<a href="https://github.com/hey-api/openapi-ts/blob/main/LICENSE.md"><img src="https://img.shields.io/github/license/hey-api/openapi-ts" alt="MIT License"></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://stackblitz.com/edit/hey-api-example?file=openapi-ts.config.ts,src%2Fclient%2Fschemas.gen.ts,src%2Fclient%2Fsdk.gen.ts,src%2Fclient%2Ftypes.gen.ts">Demo</a>
|
|
17
|
+
<span> • </span>
|
|
18
|
+
<a href="https://heyapi.dev">Manual</a>
|
|
19
|
+
<span> • </span>
|
|
20
|
+
<a href="https://github.com/hey-api/openapi-ts/issues">Issues</a>
|
|
21
|
+
<span> • </span>
|
|
22
|
+
<a href="https://heyapi.dev/openapi-ts/community/contributing">Contribute</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
## About
|
|
26
|
+
|
|
27
|
+
The OpenAPI to TypeScript code generator used by Vercel, OpenCode, and PayPal.
|
|
28
|
+
|
|
29
|
+
Generate production-ready SDKs, Zod schemas, TanStack Query hooks, or choose from 20+ other plugins.
|
|
30
|
+
|
|
31
|
+
Part of the Hey API ecosystem.
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- production-ready code that compiles
|
|
36
|
+
- runs in any Node.js 20+ environment
|
|
37
|
+
- accepts any OpenAPI specification
|
|
38
|
+
- core plugins for SDKs, types, and schemas
|
|
39
|
+
- HTTP clients for Fetch API, Angular, Axios, Next.js, Nuxt, and more
|
|
40
|
+
- 20+ plugins to reduce third-party boilerplate
|
|
41
|
+
- highly customizable via plugins
|
|
42
|
+
- [sync with Hey API Registry](https://heyapi.dev/openapi-ts/integrations) for spec management
|
|
43
|
+
|
|
44
|
+
## Contributing
|
|
45
|
+
|
|
46
|
+
Want to see your code in products used by millions?
|
|
47
|
+
|
|
48
|
+
Start with our [Contributing](https://heyapi.dev/openapi-ts/community/contributing) guide and release your first feature.
|
|
49
|
+
|
|
50
|
+
## Sponsors
|
|
51
|
+
|
|
52
|
+
Hey API is sponsor-funded. If you rely on Hey API in production, consider becoming a [sponsor](https://github.com/sponsors/hey-api) to accelerate the roadmap.
|
|
53
|
+
|
|
54
|
+
<h3 align="center">Gold</h3>
|
|
55
|
+
|
|
56
|
+
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
|
57
|
+
<tbody>
|
|
58
|
+
<tr>
|
|
59
|
+
<td align="center" width="336px">
|
|
60
|
+
<p></p>
|
|
61
|
+
<p>
|
|
62
|
+
<a href="https://kutt.it/pkEZyc" target="_blank">
|
|
63
|
+
<picture height="50px">
|
|
64
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/.gen/stainless-logo-wordmark-480w.jpeg">
|
|
65
|
+
<img alt="Stainless logo" height="50px" src="https://heyapi.dev/assets/.gen/stainless-logo-wordmark-480w.jpeg">
|
|
66
|
+
</picture>
|
|
67
|
+
</a>
|
|
68
|
+
<br/>
|
|
69
|
+
Best-in-class developer interfaces for your API.
|
|
70
|
+
<br/>
|
|
71
|
+
<a href="https://kutt.it/pkEZyc" style="text-decoration:none;" target="_blank">
|
|
72
|
+
stainless.com
|
|
73
|
+
</a>
|
|
74
|
+
</p>
|
|
75
|
+
<p></p>
|
|
76
|
+
</td>
|
|
77
|
+
<td align="center" width="336px">
|
|
78
|
+
<p></p>
|
|
79
|
+
<p>
|
|
80
|
+
<a href="https://kutt.it/QM9Q2N" target="_blank">
|
|
81
|
+
<picture height="50px">
|
|
82
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/opencode/logo-light.svg">
|
|
83
|
+
<img alt="Opencode logo" height="50px" src="https://heyapi.dev/assets/opencode/logo-dark.svg">
|
|
84
|
+
</picture>
|
|
85
|
+
</a>
|
|
86
|
+
<br/>
|
|
87
|
+
The open source coding agent.
|
|
88
|
+
<br/>
|
|
89
|
+
<a href="https://kutt.it/QM9Q2N" style="text-decoration:none;" target="_blank">
|
|
90
|
+
opencode.ai
|
|
91
|
+
</a>
|
|
92
|
+
</p>
|
|
93
|
+
<p></p>
|
|
94
|
+
</td>
|
|
95
|
+
</tr>
|
|
96
|
+
<tr>
|
|
97
|
+
<td align="center" width="336px">
|
|
98
|
+
<p></p>
|
|
99
|
+
<p>
|
|
100
|
+
<a href="https://kutt.it/6vrYy9" target="_blank">
|
|
101
|
+
<picture height="50px">
|
|
102
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/mintlify/logo-light.svg">
|
|
103
|
+
<img alt="Mintlify logo" height="50px" src="https://heyapi.dev/assets/mintlify/logo-dark.svg">
|
|
104
|
+
</picture>
|
|
105
|
+
</a>
|
|
106
|
+
<br/>
|
|
107
|
+
The intelligent knowledge platform.
|
|
108
|
+
<br/>
|
|
109
|
+
<a href="https://kutt.it/6vrYy9" style="text-decoration:none;" target="_blank">
|
|
110
|
+
mintlify.com
|
|
111
|
+
</a>
|
|
112
|
+
</p>
|
|
113
|
+
<p></p>
|
|
114
|
+
</td>
|
|
115
|
+
</tr>
|
|
116
|
+
</tbody>
|
|
117
|
+
</table>
|
|
118
|
+
|
|
119
|
+
<h3 align="center">Silver</h3>
|
|
120
|
+
|
|
121
|
+
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
|
122
|
+
<tbody>
|
|
123
|
+
<tr>
|
|
124
|
+
<td align="center" width="172px">
|
|
125
|
+
<a href="https://kutt.it/skQUVd" target="_blank">
|
|
126
|
+
<picture height="40px">
|
|
127
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/scalar/logo-light.svg">
|
|
128
|
+
<img alt="Scalar logo" height="40px" src="https://heyapi.dev/assets/scalar/logo-dark.svg">
|
|
129
|
+
</picture>
|
|
130
|
+
</a>
|
|
131
|
+
<br/>
|
|
132
|
+
<a href="https://kutt.it/skQUVd" style="text-decoration:none;" target="_blank">
|
|
133
|
+
scalar.com
|
|
134
|
+
</a>
|
|
135
|
+
</td>
|
|
136
|
+
<td align="center" width="172px">
|
|
137
|
+
<a href="https://kutt.it/Dr9GuW" target="_blank">
|
|
138
|
+
<picture height="40px">
|
|
139
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/fastapi/logo-light.svg">
|
|
140
|
+
<img alt="FastAPI logo" height="40px" src="https://heyapi.dev/assets/fastapi/logo-dark.svg">
|
|
141
|
+
</picture>
|
|
142
|
+
</a>
|
|
143
|
+
<br/>
|
|
144
|
+
<a href="https://kutt.it/Dr9GuW" style="text-decoration:none;" target="_blank">
|
|
145
|
+
fastapi.tiangolo.com
|
|
146
|
+
</a>
|
|
147
|
+
</td>
|
|
148
|
+
</tr>
|
|
149
|
+
</tbody>
|
|
150
|
+
</table>
|
|
151
|
+
|
|
152
|
+
<h3 align="center">Bronze</h3>
|
|
153
|
+
|
|
154
|
+
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
|
155
|
+
<tbody>
|
|
156
|
+
<tr>
|
|
157
|
+
<td align="center" width="136px">
|
|
158
|
+
<a href="https://kutt.it/YpaKsX" target="_blank">
|
|
159
|
+
<picture height="34px">
|
|
160
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/.gen/kinde-logo-wordmark-dark-480w.webp">
|
|
161
|
+
<img alt="Kinde logo" height="34px" src="https://heyapi.dev/assets/.gen/kinde-logo-wordmark-480w.jpeg">
|
|
162
|
+
</picture>
|
|
163
|
+
</a>
|
|
164
|
+
</td>
|
|
165
|
+
<td align="center" width="136px">
|
|
166
|
+
<a href="https://kutt.it/KkqSaw" target="_blank">
|
|
167
|
+
<picture height="34px">
|
|
168
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/cella/logo-light.svg">
|
|
169
|
+
<img alt="Cella logo" height="34px" src="https://heyapi.dev/assets/cella/logo-dark.svg">
|
|
170
|
+
</picture>
|
|
171
|
+
</a>
|
|
172
|
+
</td>
|
|
173
|
+
</tr>
|
|
174
|
+
</tbody>
|
|
175
|
+
</table>
|
|
176
|
+
|
|
177
|
+
## Quick Start
|
|
178
|
+
|
|
179
|
+
The fastest way to use `@hey-api/openapi-ts` is via npx
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
npx @hey-api/openapi-ts -i hey-api/backend -o src/client
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/openapi-ts/output) page.
|
|
186
|
+
|
|
187
|
+
## Installation
|
|
188
|
+
|
|
189
|
+
You can download `@hey-api/openapi-ts` from npm using your favorite package manager.
|
|
190
|
+
|
|
191
|
+
#### npm
|
|
192
|
+
|
|
193
|
+
```sh
|
|
194
|
+
npm install @hey-api/openapi-ts -D -E
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### pnpm
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
pnpm add @hey-api/openapi-ts -D -E
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### yarn
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
yarn add @hey-api/openapi-ts -D -E
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### bun
|
|
210
|
+
|
|
211
|
+
```sh
|
|
212
|
+
bun add @hey-api/openapi-ts -D -E
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Versioning
|
|
216
|
+
|
|
217
|
+
This package is in [initial development](https://semver.org/#spec-item-4). Please pin an exact version so you can safely upgrade when you're ready.
|
|
218
|
+
|
|
219
|
+
We publish [migration notes](https://heyapi.dev/openapi-ts/migrating) for every breaking release. You might not be impacted by a breaking change if you don't use the affected features.
|
|
220
|
+
|
|
221
|
+
## Usage
|
|
222
|
+
|
|
223
|
+
### CLI
|
|
224
|
+
|
|
225
|
+
Most people run `@hey-api/openapi-ts` via CLI. To do that, add a script to your `package.json` file which will make `openapi-ts` executable through script.
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
"scripts": {
|
|
229
|
+
"openapi-ts": "openapi-ts"
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The above script can be executed by running `npm run openapi-ts` or equivalent command in other package managers. Next, we will create a [configuration](https://heyapi.dev/openapi-ts/configuration) file and move our options from Quick Start to it.
|
|
234
|
+
|
|
235
|
+
### Node.js
|
|
236
|
+
|
|
237
|
+
You can also generate output programmatically by calling `createClient()` in a JavaScript/TypeScript file.
|
|
238
|
+
|
|
239
|
+
#### `script.ts`
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import { createClient } from '@hey-api/openapi-ts';
|
|
243
|
+
|
|
244
|
+
createClient({
|
|
245
|
+
input: 'hey-api/backend', // sign up at app.heyapi.dev
|
|
246
|
+
output: 'src/client',
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Configuration
|
|
251
|
+
|
|
252
|
+
`@hey-api/openapi-ts` supports loading configuration from any file inside your project root folder supported by [jiti loader](https://github.com/unjs/c12?tab=readme-ov-file#-features). Below are the most common file formats.
|
|
253
|
+
|
|
254
|
+
#### `openapi-ts.config.ts`
|
|
255
|
+
|
|
256
|
+
```js
|
|
257
|
+
import { defineConfig } from '@hey-api/openapi-ts';
|
|
258
|
+
|
|
259
|
+
export default defineConfig({
|
|
260
|
+
input: 'hey-api/backend', // sign up at app.heyapi.dev
|
|
261
|
+
output: 'src/client',
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
#### `openapi-ts.config.cjs`
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
269
|
+
module.exports = {
|
|
270
|
+
input: 'hey-api/backend', // sign up at app.heyapi.dev
|
|
271
|
+
output: 'src/client',
|
|
272
|
+
};
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
#### `openapi-ts.config.mjs`
|
|
276
|
+
|
|
277
|
+
```js
|
|
278
|
+
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
279
|
+
export default {
|
|
280
|
+
input: 'hey-api/backend', // sign up at app.heyapi.dev
|
|
281
|
+
output: 'src/client',
|
|
282
|
+
};
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Alternatively, you can use `openapi-ts.config.js` and configure the export statement depending on your project setup.
|
|
286
|
+
|
|
287
|
+
### Input
|
|
288
|
+
|
|
289
|
+
You must set the input so we can load your OpenAPI specification. It can be a path or URL, object containing a path or URL, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
|
|
290
|
+
|
|
291
|
+
> If you use an HTTPS URL with a self-signed certificate in development, you will need to set [`NODE_TLS_REJECT_UNAUTHORIZED=0`](https://github.com/hey-api/openapi-ts/issues/276#issuecomment-2043143501) in your environment.
|
|
292
|
+
|
|
293
|
+
### Output
|
|
294
|
+
|
|
295
|
+
You must set the output so we know where to generate your files. It can be a path to the destination folder or an object containing the destination folder path and optional settings.
|
|
296
|
+
|
|
297
|
+
> You should treat the output folder as a dependency. Do not directly modify its contents as your changes might be erased when you run `@hey-api/openapi-ts` again.
|
|
298
|
+
|
|
299
|
+
## Parser
|
|
300
|
+
|
|
301
|
+
We parse your input before making it available to plugins. While configuring the parser is optional, it's the perfect place to modify or validate your input if needed.
|
|
302
|
+
|
|
303
|
+
## Plugins
|
|
304
|
+
|
|
305
|
+
Plugins are responsible for generating artifacts from your input. By default, Hey API will generate TypeScript interfaces and SDK from your OpenAPI specification. You can add, remove, or customize any of the plugins. In fact, we highly encourage you to do so!
|
|
306
|
+
|
|
307
|
+
### Client
|
|
308
|
+
|
|
309
|
+
Clients are responsible for sending the actual HTTP requests. Using clients is not required, but you must add a client to `plugins` if you're generating SDKs (we default to Fetch).
|
|
310
|
+
|
|
311
|
+
### Native Clients
|
|
312
|
+
|
|
313
|
+
- [`@hey-api/client-fetch`](https://heyapi.dev/openapi-ts/clients/fetch)
|
|
314
|
+
- [`@hey-api/client-angular`](https://heyapi.dev/openapi-ts/clients/angular)
|
|
315
|
+
- [`@hey-api/client-axios`](https://heyapi.dev/openapi-ts/clients/axios)
|
|
316
|
+
- [`@hey-api/client-ky`](https://heyapi.dev/openapi-ts/clients/ky)
|
|
317
|
+
- [`@hey-api/client-next`](https://heyapi.dev/openapi-ts/clients/next-js)
|
|
318
|
+
- [`@hey-api/client-nuxt`](https://heyapi.dev/openapi-ts/clients/nuxt)
|
|
319
|
+
- [`@hey-api/client-ofetch`](https://heyapi.dev/openapi-ts/clients/ofetch)
|
|
320
|
+
|
|
321
|
+
### Planned Clients
|
|
322
|
+
|
|
323
|
+
The following clients are planned but not in development yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/labels/RSVP%20%F0%9F%91%8D%F0%9F%91%8E).
|
|
324
|
+
|
|
325
|
+
- [`@hey-api/client-effect`](https://heyapi.dev/openapi-ts/clients/effect)
|
|
326
|
+
|
|
327
|
+
Don't see your client? [Build your own](https://heyapi.dev/openapi-ts/clients/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
|
|
328
|
+
|
|
329
|
+
### Native Plugins
|
|
330
|
+
|
|
331
|
+
These plugins help reduce boilerplate associated with third-party dependencies. Hey API natively supports the most popular packages. Please open an issue on [GitHub](https://github.com/hey-api/openapi-ts/issues) if you'd like us to support your favorite package.
|
|
332
|
+
|
|
333
|
+
- [`@angular/common`](https://heyapi.dev/openapi-ts/plugins/angular)
|
|
334
|
+
- [`@hey-api/schemas`](https://heyapi.dev/openapi-ts/output/json-schema)
|
|
335
|
+
- [`@hey-api/sdk`](https://heyapi.dev/openapi-ts/output/sdk)
|
|
336
|
+
- [`@hey-api/transformers`](https://heyapi.dev/openapi-ts/transformers)
|
|
337
|
+
- [`@hey-api/typescript`](https://heyapi.dev/openapi-ts/output/typescript)
|
|
338
|
+
- [`@pinia/colada`](https://heyapi.dev/openapi-ts/plugins/pinia-colada)
|
|
339
|
+
- [`@tanstack/angular-query-experimental`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
|
|
340
|
+
- [`@tanstack/react-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
|
|
341
|
+
- [`@tanstack/solid-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
|
|
342
|
+
- [`@tanstack/svelte-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
|
|
343
|
+
- [`@tanstack/vue-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
|
|
344
|
+
- [`fastify`](https://heyapi.dev/openapi-ts/plugins/fastify)
|
|
345
|
+
- [`valibot`](https://heyapi.dev/openapi-ts/plugins/valibot)
|
|
346
|
+
- [`zod`](https://heyapi.dev/openapi-ts/plugins/zod)
|
|
347
|
+
|
|
348
|
+
### Planned Plugins
|
|
349
|
+
|
|
350
|
+
The following plugins are planned but not in development yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/labels/RSVP%20%F0%9F%91%8D%F0%9F%91%8E).
|
|
351
|
+
|
|
352
|
+
- [Adonis](https://heyapi.dev/openapi-ts/plugins/adonis)
|
|
353
|
+
- [Ajv](https://heyapi.dev/openapi-ts/plugins/ajv)
|
|
354
|
+
- [Arktype](https://heyapi.dev/openapi-ts/plugins/arktype)
|
|
355
|
+
- [Chance](https://heyapi.dev/openapi-ts/plugins/chance)
|
|
356
|
+
- [Elysia](https://heyapi.dev/openapi-ts/plugins/elysia)
|
|
357
|
+
- [Express](https://heyapi.dev/openapi-ts/plugins/express)
|
|
358
|
+
- [Faker](https://heyapi.dev/openapi-ts/plugins/faker)
|
|
359
|
+
- [Falso](https://heyapi.dev/openapi-ts/plugins/falso)
|
|
360
|
+
- [Hono](https://heyapi.dev/openapi-ts/plugins/hono)
|
|
361
|
+
- [Joi](https://heyapi.dev/openapi-ts/plugins/joi)
|
|
362
|
+
- [Koa](https://heyapi.dev/openapi-ts/plugins/koa)
|
|
363
|
+
- [MSW](https://heyapi.dev/openapi-ts/plugins/msw)
|
|
364
|
+
- [Nest](https://heyapi.dev/openapi-ts/plugins/nest)
|
|
365
|
+
- [Nock](https://heyapi.dev/openapi-ts/plugins/nock)
|
|
366
|
+
- [Superstruct](https://heyapi.dev/openapi-ts/plugins/superstruct)
|
|
367
|
+
- [Supertest](https://heyapi.dev/openapi-ts/plugins/supertest)
|
|
368
|
+
- [SWR](https://heyapi.dev/openapi-ts/plugins/swr)
|
|
369
|
+
- [TypeBox](https://heyapi.dev/openapi-ts/plugins/typebox)
|
|
370
|
+
- [Yup](https://heyapi.dev/openapi-ts/plugins/yup)
|
|
371
|
+
- [Zustand](https://heyapi.dev/openapi-ts/plugins/zustand)
|
|
372
|
+
|
|
373
|
+
Don't see your plugin? [Build your own](https://heyapi.dev/openapi-ts/plugins/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
|
|
374
|
+
|
|
375
|
+
## Migrating
|
|
376
|
+
|
|
377
|
+
You can learn more on the [Migrating](https://heyapi.dev/openapi-ts/migrating) page.
|
|
378
|
+
|
|
379
|
+
## License
|
|
380
|
+
|
|
381
|
+
Released under the [MIT License](https://github.com/hey-api/openapi-ts/blob/main/LICENSE.md).
|
package/bin/run.cmd
ADDED
package/bin/run.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const target = path.join(__dirname, '..', 'dist', 'run.mjs');
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(target)) {
|
|
11
|
+
console.error('openapi-ts not built (expect dist/run.mjs)');
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const res = spawnSync(process.execPath, [target, ...process.argv.slice(2)], {
|
|
16
|
+
stdio: 'inherit',
|
|
17
|
+
});
|
|
18
|
+
process.exit(res.status ?? 0);
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { HttpResponse } from '@angular/common/http';
|
|
2
|
+
import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http';
|
|
3
|
+
import {
|
|
4
|
+
assertInInjectionContext,
|
|
5
|
+
inject,
|
|
6
|
+
provideAppInitializer,
|
|
7
|
+
runInInjectionContext,
|
|
8
|
+
} from '@angular/core';
|
|
9
|
+
import { firstValueFrom } from 'rxjs';
|
|
10
|
+
import { filter } from 'rxjs/operators';
|
|
11
|
+
|
|
12
|
+
import { createSseClient } from '../core/serverSentEvents';
|
|
13
|
+
import type { HttpMethod } from '../core/types';
|
|
14
|
+
import { getValidRequestBody } from '../core/utils';
|
|
15
|
+
import type {
|
|
16
|
+
Client,
|
|
17
|
+
Config,
|
|
18
|
+
RequestOptions,
|
|
19
|
+
ResolvedRequestOptions,
|
|
20
|
+
ResponseStyle,
|
|
21
|
+
} from './types';
|
|
22
|
+
import {
|
|
23
|
+
buildUrl,
|
|
24
|
+
createConfig,
|
|
25
|
+
createInterceptors,
|
|
26
|
+
mergeConfigs,
|
|
27
|
+
mergeHeaders,
|
|
28
|
+
setAuthParams,
|
|
29
|
+
} from './utils';
|
|
30
|
+
|
|
31
|
+
export function provideHeyApiClient(client: Client) {
|
|
32
|
+
return provideAppInitializer(() => {
|
|
33
|
+
const httpClient = inject(HttpClient);
|
|
34
|
+
client.setConfig({ httpClient });
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const createClient = (config: Config = {}): Client => {
|
|
39
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
40
|
+
|
|
41
|
+
const getConfig = (): Config => ({ ..._config });
|
|
42
|
+
|
|
43
|
+
const setConfig = (config: Config): Config => {
|
|
44
|
+
_config = mergeConfigs(_config, config);
|
|
45
|
+
return getConfig();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const interceptors = createInterceptors<
|
|
49
|
+
HttpRequest<unknown>,
|
|
50
|
+
HttpResponse<unknown>,
|
|
51
|
+
unknown,
|
|
52
|
+
ResolvedRequestOptions
|
|
53
|
+
>();
|
|
54
|
+
|
|
55
|
+
const requestOptions = <
|
|
56
|
+
ThrowOnError extends boolean = false,
|
|
57
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
58
|
+
>(
|
|
59
|
+
options: RequestOptions<unknown, TResponseStyle, ThrowOnError>,
|
|
60
|
+
) => {
|
|
61
|
+
const opts = {
|
|
62
|
+
..._config,
|
|
63
|
+
...options,
|
|
64
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
65
|
+
httpClient: options.httpClient ?? _config.httpClient,
|
|
66
|
+
serializedBody: undefined,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (!opts.httpClient) {
|
|
70
|
+
if (opts.injector) {
|
|
71
|
+
opts.httpClient = runInInjectionContext(opts.injector, () => inject(HttpClient));
|
|
72
|
+
} else {
|
|
73
|
+
assertInInjectionContext(requestOptions);
|
|
74
|
+
opts.httpClient = inject(HttpClient);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
79
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
83
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
84
|
+
opts.headers.delete('Content-Type');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const url = buildUrl(opts as any);
|
|
88
|
+
|
|
89
|
+
const req = new HttpRequest<unknown>(opts.method ?? 'GET', url, getValidRequestBody(opts), {
|
|
90
|
+
redirect: 'follow',
|
|
91
|
+
...opts,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return { opts, req, url };
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
98
|
+
const { opts, req, url } = requestOptions(options);
|
|
99
|
+
|
|
100
|
+
if (opts.security) {
|
|
101
|
+
await setAuthParams({
|
|
102
|
+
...opts,
|
|
103
|
+
security: opts.security,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (opts.requestValidator) {
|
|
108
|
+
await opts.requestValidator(opts);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return { opts, req, url };
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const request: Client['request'] = async (options) => {
|
|
115
|
+
// @ts-expect-error
|
|
116
|
+
const { opts, req: initialReq } = await beforeRequest(options);
|
|
117
|
+
|
|
118
|
+
let req = initialReq;
|
|
119
|
+
|
|
120
|
+
for (const fn of interceptors.request.fns) {
|
|
121
|
+
if (fn) {
|
|
122
|
+
req = await fn(req, opts as any);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const result: {
|
|
127
|
+
request: HttpRequest<unknown>;
|
|
128
|
+
response: any;
|
|
129
|
+
} = {
|
|
130
|
+
request: req,
|
|
131
|
+
response: null,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
result.response = (await firstValueFrom(
|
|
136
|
+
opts
|
|
137
|
+
.httpClient!.request(req)
|
|
138
|
+
.pipe(filter((event) => event.type === HttpEventType.Response)),
|
|
139
|
+
)) as HttpResponse<unknown>;
|
|
140
|
+
|
|
141
|
+
for (const fn of interceptors.response.fns) {
|
|
142
|
+
if (fn) {
|
|
143
|
+
result.response = await fn(result.response, req, opts as any);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let bodyResponse = result.response.body;
|
|
148
|
+
|
|
149
|
+
if (opts.responseValidator) {
|
|
150
|
+
await opts.responseValidator(bodyResponse);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (opts.responseTransformer) {
|
|
154
|
+
bodyResponse = await opts.responseTransformer(bodyResponse);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return opts.responseStyle === 'data' ? bodyResponse : { data: bodyResponse, ...result };
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (error instanceof HttpErrorResponse) {
|
|
160
|
+
result.response = error;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let finalError = error instanceof HttpErrorResponse ? error.error : error;
|
|
164
|
+
|
|
165
|
+
for (const fn of interceptors.error.fns) {
|
|
166
|
+
if (fn) {
|
|
167
|
+
finalError = (await fn(finalError, result.response as any, req, opts as any)) as string;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (opts.throwOnError) {
|
|
172
|
+
throw finalError;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return opts.responseStyle === 'data'
|
|
176
|
+
? undefined
|
|
177
|
+
: {
|
|
178
|
+
error: finalError,
|
|
179
|
+
...result,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
185
|
+
request({ ...options, method });
|
|
186
|
+
|
|
187
|
+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
188
|
+
const { opts, url } = await beforeRequest(options);
|
|
189
|
+
return createSseClient({
|
|
190
|
+
...opts,
|
|
191
|
+
body: opts.body as BodyInit | null | undefined,
|
|
192
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
193
|
+
method,
|
|
194
|
+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
|
|
195
|
+
url,
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
buildUrl,
|
|
201
|
+
connect: makeMethodFn('CONNECT'),
|
|
202
|
+
delete: makeMethodFn('DELETE'),
|
|
203
|
+
get: makeMethodFn('GET'),
|
|
204
|
+
getConfig,
|
|
205
|
+
head: makeMethodFn('HEAD'),
|
|
206
|
+
interceptors,
|
|
207
|
+
options: makeMethodFn('OPTIONS'),
|
|
208
|
+
patch: makeMethodFn('PATCH'),
|
|
209
|
+
post: makeMethodFn('POST'),
|
|
210
|
+
put: makeMethodFn('PUT'),
|
|
211
|
+
request,
|
|
212
|
+
requestOptions: (options) => {
|
|
213
|
+
if (options.security) {
|
|
214
|
+
throw new Error('Security is not supported in requestOptions');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (options.requestValidator) {
|
|
218
|
+
throw new Error('Request validation is not supported in requestOptions');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return requestOptions(options).req;
|
|
222
|
+
},
|
|
223
|
+
setConfig,
|
|
224
|
+
sse: {
|
|
225
|
+
connect: makeSseFn('CONNECT'),
|
|
226
|
+
delete: makeSseFn('DELETE'),
|
|
227
|
+
get: makeSseFn('GET'),
|
|
228
|
+
head: makeSseFn('HEAD'),
|
|
229
|
+
options: makeSseFn('OPTIONS'),
|
|
230
|
+
patch: makeSseFn('PATCH'),
|
|
231
|
+
post: makeSseFn('POST'),
|
|
232
|
+
put: makeSseFn('PUT'),
|
|
233
|
+
trace: makeSseFn('TRACE'),
|
|
234
|
+
},
|
|
235
|
+
trace: makeMethodFn('TRACE'),
|
|
236
|
+
} as Client;
|
|
237
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type { Auth } from '../core/auth';
|
|
2
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer';
|
|
3
|
+
export {
|
|
4
|
+
formDataBodySerializer,
|
|
5
|
+
jsonBodySerializer,
|
|
6
|
+
urlSearchParamsBodySerializer,
|
|
7
|
+
} from '../core/bodySerializer';
|
|
8
|
+
export { buildClientParams } from '../core/params';
|
|
9
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer';
|
|
10
|
+
export { createClient } from './client';
|
|
11
|
+
export type {
|
|
12
|
+
Client,
|
|
13
|
+
ClientOptions,
|
|
14
|
+
Config,
|
|
15
|
+
CreateClientConfig,
|
|
16
|
+
Options,
|
|
17
|
+
RequestOptions,
|
|
18
|
+
RequestResult,
|
|
19
|
+
ResolvedRequestOptions,
|
|
20
|
+
ResponseStyle,
|
|
21
|
+
TDataShape,
|
|
22
|
+
} from './types';
|
|
23
|
+
export { createConfig, mergeHeaders } from './utils';
|