@hey-api/openapi-ts 0.60.1 → 0.61.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 CHANGED
@@ -1,10 +1,32 @@
1
1
  <div align="center">
2
- <img width="150" height="150" src="https://heyapi.dev/logo.png" alt="Logo">
2
+ <img alt="Hey API logo" height="150" src="https://heyapi.dev/images/logo-300w.png" width="150">
3
3
  <h1 align="center"><b>OpenAPI TypeScript</b></h1>
4
4
  <p align="center">🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.</p>
5
5
  </div>
6
6
 
7
- [Live demo](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)
7
+ <br/>
8
+
9
+ <p align="center">
10
+ <a href="https://opensource.org/license/mit" rel="nofollow"><img src="https://img.shields.io/github/license/hey-api/openapi-ts" alt="MIT License"></a>
11
+ <a href="https://github.com/hey-api/openapi-ts/actions?query=branch%3Amain"><img src="https://img.shields.io/github/last-commit/hey-api/openapi-ts" alt="Last commit" /></a>
12
+ <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>
13
+ <a href="https://github.com/hey-api/openapi-ts/issues" rel="nofollow"><img src="https://img.shields.io/github/issues/hey-api/openapi-ts" alt="Number of open issues"></a>
14
+ <a href="https://app.codecov.io/gh/hey-api/openapi-ts/tree/main"><img src="https://codecov.io/gh/hey-api/openapi-ts/branch/main/graph/badge.svg" alt="Test coverage" /></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <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>
19
+ <span>&nbsp;•&nbsp;</span>
20
+ <a href="https://heyapi.dev">Documentation</a>
21
+ <span>&nbsp;•&nbsp;</span>
22
+ <a href="https://github.com/hey-api/openapi-ts/issues">Issues</a>
23
+ <span>&nbsp;•&nbsp;</span>
24
+ <a href="https://github.com/orgs/hey-api/discussions/1495">Roadmap</a>
25
+ <span>&nbsp;•&nbsp;</span>
26
+ <a href="https://npmjs.com/package/@hey-api/openapi-ts">npm</a>
27
+ </p>
28
+
29
+ <br/>
8
30
 
9
31
  ## Features
10
32
 
@@ -15,10 +37,6 @@
15
37
  - Fetch API, Axios, Angular, Node.js, and XHR clients available
16
38
  - plugin ecosystem to reduce third-party boilerplate
17
39
 
18
- ## Documentation
19
-
20
- Please visit our [website](https://heyapi.dev/) for documentation, guides, migrating, and more.
21
-
22
40
  ## Sponsors
23
41
 
24
42
  Love Hey API? Become our [sponsor](https://github.com/sponsors/hey-api).
@@ -29,10 +47,213 @@ Love Hey API? Become our [sponsor](https://github.com/sponsors/hey-api).
29
47
  </a>
30
48
  </p>
31
49
 
32
- ## GitHub Integration (coming soon)
50
+ ## GitHub Integration (coming 2025)
33
51
 
34
52
  Automatically update your code when the APIs it depends on change. [Find out more](https://heyapi.dev/openapi-ts/integrations.html).
35
53
 
54
+ ## Quick Start
55
+
56
+ The fastest way to use `@hey-api/openapi-ts` is via npx
57
+
58
+ ```sh
59
+ npx @hey-api/openapi-ts \
60
+ -c @hey-api/client-fetch \
61
+ -i path/to/openapi.json \
62
+ -o src/client \
63
+ ```
64
+
65
+ Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/openapi-ts/output) page.
66
+
67
+ Before you can make API requests with the client you've just created, you need to install `@hey-api/client-fetch` and configure it.
68
+
69
+ ## Installation
70
+
71
+ #### npm
72
+
73
+ ```sh
74
+ npm install @hey-api/client-fetch && npm install @hey-api/openapi-ts -D
75
+ ```
76
+
77
+ #### pnpm
78
+
79
+ ```sh
80
+ pnpm add @hey-api/client-fetch && pnpm add @hey-api/openapi-ts -D
81
+ ```
82
+
83
+ #### yarn
84
+
85
+ ```sh
86
+ yarn add @hey-api/client-fetch && yarn add @hey-api/openapi-ts -D
87
+ ```
88
+
89
+ #### bun
90
+
91
+ ```sh
92
+ bun add @hey-api/client-fetch && bun add @hey-api/openapi-ts -D
93
+ ```
94
+
95
+ We recommend pinning an exact version so you can safely upgrade when you're ready. This package is in [initial development](https://semver.org/spec/v0.1.0.html#spec-item-5) and its API might change before v1.
96
+
97
+ ### CLI
98
+
99
+ 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.
100
+
101
+ ```json
102
+ "scripts": {
103
+ "openapi-ts": "openapi-ts"
104
+ }
105
+ ```
106
+
107
+ The above script can be executed by running `npm run openapi-ts` or equivalent command in other package managers. Next, we need to create a [configuration](https://heyapi.dev/openapi-ts/configuration) file and move our options from Quick Start to it.
108
+
109
+ ### Node.js
110
+
111
+ You can also generate clients programmatically by importing `@hey-api/openapi-ts` in a TypeScript file.
112
+
113
+ ```ts
114
+ import { createClient } from '@hey-api/openapi-ts';
115
+
116
+ createClient({
117
+ client: '@hey-api/client-fetch',
118
+ input: 'path/to/openapi.json',
119
+ output: 'src/client',
120
+ });
121
+ ```
122
+
123
+ ## Configuration
124
+
125
+ `@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.
126
+
127
+ #### `openapi-ts.config.ts`
128
+
129
+ ```js
130
+ import { defineConfig } from '@hey-api/openapi-ts';
131
+
132
+ export default defineConfig({
133
+ client: '@hey-api/client-fetch',
134
+ input: 'path/to/openapi.json',
135
+ output: 'src/client',
136
+ });
137
+ ```
138
+
139
+ #### `openapi-ts.config.cjs`
140
+
141
+ ```js
142
+ /** @type {import('@hey-api/openapi-ts').UserConfig} */
143
+ module.exports = {
144
+ client: '@hey-api/client-fetch',
145
+ input: 'path/to/openapi.json',
146
+ output: 'src/client',
147
+ };
148
+ ```
149
+
150
+ #### `openapi-ts.config.mjs`
151
+
152
+ ```js
153
+ /** @type {import('@hey-api/openapi-ts').UserConfig} */
154
+ export default {
155
+ client: '@hey-api/client-fetch',
156
+ input: 'path/to/openapi.json',
157
+ output: 'src/client',
158
+ };
159
+ ```
160
+
161
+ Alternatively, you can use `openapi-ts.config.js` and configure the export statement depending on your project setup.
162
+
163
+ ### Input
164
+
165
+ Input is the first thing you must define. It can be a path, URL, or a string content resolving to an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
166
+
167
+ > 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.
168
+
169
+ ### Output
170
+
171
+ Output is the next thing to define. It can be either a string pointing to the destination folder or a configuration object containing the destination folder path and optional settings (these are described below).
172
+
173
+ > 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.
174
+
175
+ ### Client
176
+
177
+ Clients are responsible for sending the actual HTTP requests. The `client` value is not required, but you must define it if you're generating SDKs (enabled by default).
178
+
179
+ You can learn more on the [Clients](https://heyapi.dev/openapi-ts/clients) page.
180
+
181
+ ### Parser
182
+
183
+ If you're NOT using a legacy client, we encourage you to try out the experimental parser. Soon, it will become the default parser, but until it's been tested it's an opt-in feature. To try it out, set the `experimentalParser` flag in your configuration to `true`.
184
+
185
+ #### config
186
+
187
+ ```js
188
+ export default {
189
+ client: '@hey-api/client-fetch',
190
+ experimentalParser: true,
191
+ input: 'path/to/openapi.json',
192
+ output: 'src/client',
193
+ };
194
+ ```
195
+
196
+ #### cli
197
+
198
+ ```sh
199
+ npx @hey-api/openapi-ts \
200
+ -c @hey-api/client-fetch \
201
+ -e \
202
+ -i path/to/openapi.json \
203
+ -o src/client
204
+ ```
205
+
206
+ The experimental parser produces a cleaner output while being faster than the legacy parser. It also supports features such as [Filters](https://heyapi.dev/openapi-ts/configuration#filters) and more are being added.
207
+
208
+ The legacy parser will be used with the [legacy clients](https://heyapi.dev/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates.
209
+
210
+ ## Plugins
211
+
212
+ 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!
213
+
214
+ ### Native Plugins
215
+
216
+ 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.
217
+
218
+ - [`@hey-api/schemas`](https://heyapi.dev/openapi-ts/output/json-schema)
219
+ - [`@hey-api/sdk`](https://heyapi.dev/openapi-ts/output/sdk)
220
+ - [`@hey-api/transformers`](https://heyapi.dev/openapi-ts/transformers)
221
+ - [`@hey-api/typescript`](https://heyapi.dev/openapi-ts/output/typescript)
222
+ - [`@tanstack/angular-query-experimental`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
223
+ - [`@tanstack/react-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
224
+ - [`@tanstack/solid-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
225
+ - [`@tanstack/svelte-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
226
+ - [`@tanstack/vue-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
227
+ - [`fastify`](https://heyapi.dev/openapi-ts/plugins/fastify)
228
+ - [`zod`](https://heyapi.dev/openapi-ts/plugins/zod)
229
+
230
+ ### Planned Plugins
231
+
232
+ 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).
233
+
234
+ - [Ajv](https://heyapi.dev/openapi-ts/plugins/ajv)
235
+ - [Arktype](https://heyapi.dev/openapi-ts/plugins/arktype)
236
+ - [Express](https://heyapi.dev/openapi-ts/plugins/express)
237
+ - [Faker](https://heyapi.dev/openapi-ts/plugins/faker)
238
+ - [Hono](https://heyapi.dev/openapi-ts/plugins/hono)
239
+ - [Joi](https://heyapi.dev/openapi-ts/plugins/joi)
240
+ - [Koa](https://heyapi.dev/openapi-ts/plugins/koa)
241
+ - [MSW](https://heyapi.dev/openapi-ts/plugins/msw)
242
+ - [Nest](https://heyapi.dev/openapi-ts/plugins/nest)
243
+ - [Nock](https://heyapi.dev/openapi-ts/plugins/nock)
244
+ - [Pinia Colada](https://heyapi.dev/openapi-ts/plugins/pinia-colada)
245
+ - [Superstruct](https://heyapi.dev/openapi-ts/plugins/superstruct)
246
+ - [Supertest](https://heyapi.dev/openapi-ts/plugins/supertest)
247
+ - [SWR](https://heyapi.dev/openapi-ts/plugins/swr)
248
+ - [TypeBox](https://heyapi.dev/openapi-ts/plugins/typebox)
249
+ - [Valibot](https://heyapi.dev/openapi-ts/plugins/valibot)
250
+ - [Yup](https://heyapi.dev/openapi-ts/plugins/yup)
251
+ - [Zustand](https://heyapi.dev/openapi-ts/plugins/zustand)
252
+
36
253
  ## Migration Guides
37
254
 
38
- [OpenAPI Typescript Codegen](https://heyapi.dev/openapi-ts/migrating.html#openapi-typescript-codegen)
255
+ [OpenAPI Typescript Codegen](https://heyapi.dev/openapi-ts/migrating#openapi-typescript-codegen)
256
+
257
+ ## License
258
+
259
+ Released under the [MIT License](https://github.com/hey-api/openapi-ts/blob/main/LICENSE.md).
package/bin/index.cjs CHANGED
@@ -34,6 +34,10 @@ const params = program
34
34
  'DEPRECATED. Manually set base in OpenAPI config instead of inferring from server value',
35
35
  )
36
36
  .option('-s, --silent', 'Set log level to silent')
37
+ .option(
38
+ '-w, --watch [value]',
39
+ 'Regenerate the client when the input file changes?',
40
+ )
37
41
  .option('--exportCore [value]', 'DEPRECATED. Write core files to disk')
38
42
  .option('--name <value>', 'DEPRECATED. Custom client class name')
39
43
  .option('--request <value>', 'DEPRECATED. Path to custom request file')
@@ -102,8 +106,14 @@ async function start() {
102
106
  userConfig.logs.level = 'silent';
103
107
  }
104
108
 
105
- await createClient(userConfig);
106
- process.exit(0);
109
+ if (typeof params.watch === 'string') {
110
+ userConfig.watch = Number.parseInt(params.watch, 10);
111
+ }
112
+
113
+ const context = await createClient(userConfig);
114
+ if (!context[0] || !context[0].config.watch) {
115
+ process.exit(0);
116
+ }
107
117
  } catch (error) {
108
118
  process.exit(1);
109
119
  }