···10101111## Features
12121313-- works with CLI, Node.js, or npx
1313+- works with CLI, Node.js 18+, or npx
1414- supports OpenAPI 2.0, 3.0, and 3.1 specifications
1515- supports both JSON and YAML input files
1616- generates TypeScript interfaces, REST clients, and JSON Schemas
···33description: Hello from Hey API.
44---
5566-# About Hey API
66+# About
7788-Hey API's objective is to provide a set of TypeScript tools to manage API interactions. Whether you're building a front-end application, API-to-API service, or micro-frontends, we want Hey API to be your go-to resource.
88+Hey API's objective is to provide a suite of TypeScript tools to manage API interactions. Whether you're building a front-end application, API-to-API service, or micro-frontends, we want Hey API to be your go-to resource.
991010Typically, developers of such applications want to:
1111
···2727Fetch API client is currently in beta. The interface might change before it becomes stable. We encourage you to leave feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues).
2828:::
29293030-Start by adding `@hey-api/client-fetch` into your project's dependencies.
3030+Start by adding `@hey-api/client-fetch` to your dependencies.
31313232::: code-group
3333···49495050:::
51515252-Ensure you have already [installed](/openapi-ts/get-started) and configured `@hey-api/openapi-ts`. Update your configuration to use the client package.
5252+Ensure you have already [configured](/openapi-ts/get-started) `@hey-api/openapi-ts`. Update your configuration to use the Fetch API client package.
53535454```js{2}
5555export default {
···5959}
6060```
61616262-You can now run `openapi-ts` as usual to generate the new services.
6262+You can now run `openapi-ts` to use the new Fetch API client. 🎉
63636464### Configuration
65656666-You will most likely want to configure the global client instance used by services. You can do that with the `createClient()` method. Call it at the beginning of your program.
6666+You will most likely want to configure the global client instance used by services. You can do that with the `createClient()` method. Call it at the beginning of your application.
67676868```js
6969import { createClient } from '@hey-api/client-fetch';
···96969797## Legacy Clients
98989999-Before standalone client packages, clients were generated using `@hey-api/openapi-ts`. If you want to generate a legacy client that isn't published as a standalone package, you can use the `client` config option.
9999+Before standalone client packages, clients were generated using `@hey-api/openapi-ts`. In fact, `@hey-api/openapi-ts` still generates a legacy Fetch API client by default. You can generate other legacy clients with the `client` config option.
100100101101::: code-group
102102103103+```js{2} [fetch]
104104+export default {
105105+ client: 'fetch',
106106+ input: 'path/to/openapi.json',
107107+ output: 'src/client',
108108+}
109109+```
110110+111111+```js{2} [axios]
112112+export default {
113113+ client: 'axios',
114114+ input: 'path/to/openapi.json',
115115+ output: 'src/client',
116116+}
117117+```
118118+103119```js{2} [angular]
104120export default {
105121 client: 'angular',
···124140}
125141```
126142143143+:::
144144+127145The following legacy clients are available:
128146129147- [angular](https://angular.io/) (using [RxJS](https://rxjs.dev/))
148148+- [axios](https://axios-http.com/)
149149+- [fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API)
130150- [node](https://nodejs.org/) (using [node-fetch](https://www.npmjs.com/package/node-fetch))
131151- [xhr](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest)
132152153153+Please be aware that legacy clients are missing some features:
154154+155155+- no typesafe errors 🚫
156156+- no access to the original request and response 🚫
157157+- hard to configure individual requests 👎
158158+- inconsistent interceptors and response APIs 👎
159159+133160If you'd like a standalone package for your client, let us know by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
134161135135-## Examples
162162+::: tip
163163+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.
164164+:::
136165137137-You can view live examples on [StackBlitz](https://stackblitz.com/orgs/github/hey-api/collections/openapi-ts-examples).
166166+<!--@include: ../examples.md-->
+71-135
docs/openapi-ts/configuration.md
···40404141## Clients
42424343-By default, `@hey-api/openapi-ts` will generate a Fetch API client. If you want a different client, you can specify it using the `client` option.
4343+Clients are responsible for sending the actual HTTP requests. By default, `@hey-api/openapi-ts` will generate a Fetch API client. We are moving away from generated clients toward standalone packages. This approach has many benefits over the current default. You can learn more on the [Clients](/openapi-ts/clients) page.
4444+4545+<!--
4646+TODO: uncomment after c12 supports multiple configs
4747+see https://github.com/unjs/c12/issues/92
4848+-->
4949+<!-- ### Multiple Clients
5050+5151+If you want to generate multiple clients with a single `openapi-ts` command, you can provide an array of configuration objects.
5252+5353+```js
5454+import { defineConfig } from '@hey-api/openapi-ts';
5555+5656+export default defineConfig([
5757+ {
5858+ client: 'fetch',
5959+ input: 'path/to/openapi_one.json',
6060+ output: 'src/client_one',
6161+ },
6262+ {
6363+ client: 'axios',
6464+ input: 'path/to/openapi_two.json',
6565+ output: 'src/client_two',
6666+ },
6767+])
6868+``` -->
6969+7070+## Services
7171+7272+Services are abstractions on top of clients and serve the same purpose. By default, `@hey-api/openapi-ts` will generate a flat service layer. Your choice to use services comes down to personal preferences and bundle size considerations. You can learn more on the [Output](/openapi-ts/output#api-services) page.
7373+7474+## Enums
7575+7676+By default, `@hey-api/openapi-ts` will only emit enums as types. You may want to generate runtime artifacts. A good use case is iterating through possible field values without manually typing arrays. To emit runtime enums, set `types.enums` to a valid option.
44774578::: code-group
46794747-```js{2} [fetch]
8080+```js{5} [disabled]
4881export default {
4949- client: 'fetch',
5082 input: 'path/to/openapi.json',
5183 output: 'src/client',
8484+ types: {
8585+ enums: false,
8686+ },
5287}
5388```
54895555-```js{2} [fetch (beta)]
9090+```js{5} [javascript]
5691export default {
5757- client: '@hey-api/client-fetch',
5892 input: 'path/to/openapi.json',
5993 output: 'src/client',
9494+ types: {
9595+ enums: 'javascript',
9696+ },
6097}
6198```
62996363-```js{2} [axios]
100100+```js{5} [typescript]
64101export default {
6565- client: 'axios',
66102 input: 'path/to/openapi.json',
67103 output: 'src/client',
104104+ types: {
105105+ enums: 'typescript',
106106+ },
68107}
69108```
701097171-```js{2} [angular]
110110+:::
111111+112112+We recommend exporting enums as plain JavaScript objects. [TypeScript enums](https://www.typescriptlang.org/docs/handbook/enums.html) are not a type-level extension of JavaScript and pose [typing challenges](https://dev.to/ivanzm123/dont-use-enums-in-typescript-they-are-very-dangerous-57bh).
113113+114114+## JSON Schemas
115115+116116+By default, `@hey-api/openapi-ts` generates schemas from your OpenAPI specification. A great use case for schemas is client-side form input validation. If you're using OpenAPI 3.1, your [schemas](/openapi-ts/output#json-schemas) are JSON Schema compliant and can be used with other tools supporting JSON Schema. However, if you only want to validate form input, you probably don't want to include string descriptions inside your bundle. You can choose your preferred type using `schemas.type` option.
117117+118118+::: code-group
119119+120120+```js{5} [json]
72121export default {
7373- client: 'angular',
74122 input: 'path/to/openapi.json',
75123 output: 'src/client',
124124+ schemas: {
125125+ type: 'json'
126126+ },
76127}
77128```
781297979-```js{2} [node]
130130+```js{5} [form]
80131export default {
8181- client: 'node',
82132 input: 'path/to/openapi.json',
83133 output: 'src/client',
134134+ schemas: {
135135+ type: 'form'
136136+ },
84137}
85138```
861398787-```js{2} [xhr]
140140+```js{4} [disabled]
88141export default {
8989- client: 'xhr',
90142 input: 'path/to/openapi.json',
91143 output: 'src/client',
144144+ schemas: false,
92145}
93146```
9414795148:::
961499797-We support these clients:
9898-9999-- [angular](https://angular.io/) (using [RxJS](https://rxjs.dev/))
100100-- [axios](https://axios-http.com/)
101101-- [fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API)
102102-103103-We also support the legacy Node.js and XHR clients:
104104-105105-- [node](https://nodejs.org/) (using [node-fetch](https://www.npmjs.com/package/node-fetch))
106106-- [xhr](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest)
107107-108108-Optionally, you can use client packages to avoid generating a new client on every run:
109109-110110-- [fetch (beta)](https://developer.mozilla.org/docs/Web/API/Fetch_API)
111111-112112-::: tip
113113-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.
114114-:::
115115-116116-<!--
117117-TODO: uncomment after c12 supports multiple configs
118118-see https://github.com/unjs/c12/issues/92
119119--->
120120-<!-- ### Multiple Clients
121121-122122-If you want to generate multiple clients with a single `openapi-ts` command, you can provide an array of configuration objects.
123123-124124-```js
125125-import { defineConfig } from '@hey-api/openapi-ts';
126126-127127-export default defineConfig([
128128- {
129129- client: 'fetch',
130130- input: 'path/to/openapi_one.json',
131131- output: 'src/client_one',
132132- },
133133- {
134134- client: 'axios',
135135- input: 'path/to/openapi_two.json',
136136- output: 'src/client_two',
137137- },
138138-])
139139-``` -->
140140-141150## Formatting
142151143143-By default, `@hey-api/openapi-ts` will not automatically format your client. To enable this feature, set `output.format` to a valid formatter.
152152+By default, `@hey-api/openapi-ts` will not automatically format your output. To enable this feature, set `output.format` to a valid formatter.
144153145154::: code-group
146155···176185177186:::
178187179179-You can also prevent your client from being processed by formatters by adding your output path to the tool's ignore file (e.g. `.prettierignore`).
188188+You can also prevent your output from being formatted by adding your output path to the formatter's ignore file.
180189181190## Linting
182191183183-For performance reasons, `@hey-api/openapi-ts` does not automatically lint your client. To enable this feature, set `output.lint` to a valid linter.
192192+By default, `@hey-api/openapi-ts` will not automatically lint your output. To enable this feature, set `output.lint` to a valid linter.
184193185194::: code-group
186195···216225217226:::
218227219219-You can also prevent your client from being processed by linters by adding your output path to the tool's ignore file (e.g. `.eslintignore`).
220220-221221-## Enums
222222-223223-If you need to iterate through possible field values without manually typing arrays, you can export enums with
224224-225225-```js{5}
226226-export default {
227227- input: 'path/to/openapi.json',
228228- output: 'src/client',
229229- types: {
230230- enums: 'javascript',
231231- },
232232-}
233233-```
234234-235235-This will export enums as plain JavaScript objects. For example, `Foo` would become
236236-237237-```js
238238-export const Foo = {
239239- FOO: 'foo',
240240- BAR: 'bar',
241241-} as const;
242242-```
243243-244244-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
245245-246246-```js{5}
247247-export default {
248248- input: 'path/to/openapi.json',
249249- output: 'src/client',
250250- types: {
251251- enums: 'typescript',
252252- },
253253-}
254254-```
255255-256256-## JSON Schemas
257257-258258-By default, `@hey-api/openapi-ts` exports schemas from your OpenAPI specification as plain JavaScript objects. A great use case for schemas is client-side form input validation.
259259-260260-```ts
261261-import { $Schema } from 'client/schemas';
262262-263263-const maxInputLength = $Schema.properties.text.maxLength;
264264-265265-if (userInput.length > maxInputLength) {
266266- throw new Error(`String length cannot exceed ${maxInputLength} characters!`);
267267-}
268268-```
269269-270270-If you're using OpenAPI v3.1, your schemas are JSON Schema compliant and can be used with other tools supporting JSON Schema. However, if you only want to validate form input, you don't want to include string descriptions inside your bundle. Instead, use `form` type.
271271-272272-```js{5}
273273-export default {
274274- input: 'path/to/openapi.json',
275275- output: 'src/client',
276276- schemas: {
277277- type: 'form'
278278- },
279279-}
280280-```
281281-282282-If you don't need schemas at all, you can disable them with
283283-284284-```js{4}
285285-export default {
286286- input: 'path/to/openapi.json',
287287- output: 'src/client',
288288- schemas: false,
289289-}
290290-```
228228+You can also prevent your output from being linted by adding your output path to the linter's ignore file.
291229292230## Config API
293231294232You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/types/config.ts) interface.
295233296296-## Examples
297297-298298-You can view live examples on [StackBlitz](https://stackblitz.com/orgs/github/hey-api/collections/openapi-ts-examples).
234234+<!--@include: ../examples.md-->
+18-10
docs/openapi-ts/get-started.md
···17171818## Features
19192020-- works with CLI, Node.js, or npx
2020+- works with CLI, Node.js 18+, or npx
2121- supports OpenAPI 2.0, 3.0, and 3.1 specifications
2222- supports both JSON and YAML input files
2323- generates TypeScript interfaces, REST clients, and JSON Schemas
···3131npx @hey-api/openapi-ts -i path/to/openapi.json -o src/client
3232```
33333434-Congratulations on creating your first client! 🎉
3434+Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](/openapi-ts/output) page.
3535+3636+While you can already make API requests with the client you've just created, you will probably want to configure it or pin a specific version. Let's start by adding `@hey-api/openapi-ts` to your dependencies.
35373638## Installation
3739···55575658:::
57595858-If you want to use `@hey-api/openapi-ts` with CLI, add a script to your `package.json` file
6060+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.
6161+6262+### CLI
6363+6464+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.
59656066```json
6167"scripts": {
6262- "openapi-ts": "openapi-ts"
6868+ "openapi-ts": "openapi-ts -i path/to/openapi.json -o src/client"
6369}
6470```
65716666-You can also generate your client programmatically by importing `@hey-api/openapi-ts` in a TypeScript file.
7272+The above script can be executed by running `npm run openapi-ts` or equivalent command if you're not using npm.
7373+7474+### Node.js
7575+7676+You can also generate clients programmatically by importing `@hey-api/openapi-ts` in a TypeScript file.
67776878```ts
6979import { createClient } from '@hey-api/openapi-ts';
···7484});
7585```
76867777-::: warning
7878-You need to be running Node.js v18 or newer
7979-:::
8787+### Configuration
80888181-## Examples
8989+It is a good practice to extract your configuration into a separate file. Learn how to do that and discover available options on the [Configuration](/openapi-ts/configuration) page.
82908383-You can view live examples on [StackBlitz](https://stackblitz.com/orgs/github/hey-api/collections/openapi-ts-examples).
9191+<!--@include: ../examples.md-->
+1-3
docs/openapi-ts/interceptors.md
···109109Angular client does not currently support request interceptors.
110110:::
111111112112-## Examples
113113-114114-You can view live examples on [StackBlitz](https://stackblitz.com/orgs/github/hey-api/collections/openapi-ts-examples).
112112+<!--@include: ../examples.md-->
+5-5
docs/openapi-ts/migrating.md
···34343535You don't have to update imports from `core` directory. These will be addressed in later releases.
36363737-### Deprecated `useOptions`
3737+### Deprecated `base`
38383939-This config option is deprecated and will be removed.
3939+This config option is deprecated and will be removed in favor of [clients](./clients).
40404141-### Deprecated `base`
4141+### Deprecated `name`
42424343This config option is deprecated and will be removed in favor of [clients](./clients).
4444···46464747This config option is deprecated and will be removed in favor of [clients](./clients).
48484949-### Deprecated `name`
4949+### Deprecated `useOptions`
50505151-This config option is deprecated and will be removed in favor of [clients](./clients).
5151+This config option is deprecated and will be removed.
52525353## v0.46.0
5454
+262
docs/openapi-ts/output.md
···11+---
22+title: Output
33+description: Learn about files generated with @hey-api/openapi-ts.
44+---
55+66+# Output
77+88+Learn about files generated with `@hey-api/openapi-ts`.
99+1010+::: tip
1111+1212+Your actual output depends on your OpenAPI specification and Hey API configuration. It may contain a different number of files and their contents might differ.
1313+1414+:::
1515+1616+### Example
1717+1818+If you use the default configuration, your [project](https://stackblitz.com/edit/hey-api-example?file=openapi-ts.config.ts,src%2Fclient%2Fschemas.gen.ts,src%2Fclient%2Fservices.gen.ts,src%2Fclient%2Ftypes.gen.ts) might look something like this.
1919+2020+```md
2121+my-app/
2222+├── node_modules/
2323+├── src/
2424+│ ├── client/
2525+│ │ ├── core/
2626+│ │ ├── index.ts
2727+│ │ ├── schemas.gen.ts
2828+│ │ ├── services.gen.ts
2929+│ │ └── types.gen.ts
3030+│ └── index.ts
3131+└── package.json
3232+```
3333+3434+Let's go through each file in the `src/client` folder and explain what it looks like, what it does, and how to use it.
3535+3636+## TypeScript interfaces
3737+3838+TypeScript interfaces are located in the `types.gen.ts` file. This is the only file that does not impact your bundle size and runtime performance. It will get discarded during build time, unless you configured to emit runtime [enums](/openapi-ts/configuration#enums).
3939+4040+This file contains three different categories of interfaces created from your OpenAPI specification:
4141+4242+- components, parameters, and enums
4343+- operation request, response, and error data
4444+- operation tree interface
4545+4646+Depending on your OpenAPI specification and configuration, some of these categories might be missing or differ in your output (and that's okay!).
4747+4848+::: code-group
4949+5050+```ts [types.gen.ts]
5151+export type Pet = {
5252+ id?: number;
5353+ name: string;
5454+};
5555+5656+export type AddPetData = {
5757+ body: Pet;
5858+};
5959+6060+export type AddPetResponse = Pet;
6161+6262+export type $OpenApiTs = {
6363+ '/foo': {
6464+ post: {
6565+ req: AddPetData;
6666+ res: {
6767+ 200: Pet;
6868+ };
6969+ };
7070+ };
7171+};
7272+```
7373+7474+:::
7575+7676+As you can see, everything is exported from `types.gen.ts`. You can import individual exports in your application and use them as necessary.
7777+7878+## API Services
7979+8080+API services are located in the `services.gen.ts` file. This file contains abstractions for sending API requests which can be called instead of using the client directly. Whether you should use API services comes down to your personal preference and bundle size considerations. You have three options to choose from.
8181+8282+### Flat Services
8383+8484+This is the default setting. It supports tree-shaking and can lead to reduced bundle size over duplicated client calls. The method names are generated from operation IDs.
8585+8686+### Class Services
8787+8888+The previous default setting. It does not support tree-shaking which will lead to increased bundle sizes, but some prefer this option for syntax reasons. The class names are generated from operation tags and method names are generated from operation IDs.
8989+9090+### No Services
9191+9292+If you prefer to use clients directly or do not need the service layer, this is the option for you. Type support for clients is currently limited due to popularity of other options. If you'd like to use this option and need better types, [open an issue](https://github.com/hey-api/openapi-ts/issues).
9393+9494+### Configuration
9595+9696+You can choose your preferred style using the `services` config option.
9797+9898+::: code-group
9999+100100+```js{5} [flat]
101101+export default {
102102+ input: 'path/to/openapi.json',
103103+ output: 'src/client',
104104+ services: {
105105+ asClass: false,
106106+ },
107107+}
108108+```
109109+110110+```js{5} [class]
111111+export default {
112112+ input: 'path/to/openapi.json',
113113+ output: 'src/client',
114114+ services: {
115115+ asClass: true,
116116+ },
117117+}
118118+```
119119+120120+```js{4} [none]
121121+export default {
122122+ input: 'path/to/openapi.json',
123123+ output: 'src/client',
124124+ services: false,
125125+}
126126+```
127127+128128+:::
129129+130130+### Output
131131+132132+Below are different outputs depending on your chosen style. No services approach will not generate the `services.gen.ts` file.
133133+134134+::: code-group
135135+136136+```ts [flat]
137137+import { client, type Options } from '@hey-api/client-fetch';
138138+139139+import type { AddPetData, AddPetError, AddPetResponse } from './types.gen';
140140+141141+export const addPet = (options: Options<AddPetData>) =>
142142+ (options?.client ?? client).post<AddPetResponse, AddPetError>({
143143+ ...options,
144144+ url: '/pet',
145145+ });
146146+```
147147+148148+```ts [class]
149149+import { client, type Options } from '@hey-api/client-fetch';
150150+151151+import type { AddPetData, AddPetError, AddPetResponse } from './types.gen';
152152+153153+export class PetService {
154154+ public static addPet(options: Options<AddPetData>) {
155155+ return (options?.client ?? client).post<AddPetResponse, AddPetError>({
156156+ ...options,
157157+ url: '/pet',
158158+ });
159159+ }
160160+}
161161+```
162162+163163+:::
164164+165165+### Usage
166166+167167+This is how you'd make the same request using each approach.
168168+169169+::: code-group
170170+171171+```ts [flat]
172172+import { addPet } from './client/services.gen';
173173+174174+addPet({
175175+ body: {
176176+ name: 'Kitty',
177177+ },
178178+});
179179+```
180180+181181+```ts [class]
182182+import { PetService } from './client/services.gen';
183183+184184+PetService.addPet({
185185+ body: {
186186+ name: 'Kitty',
187187+ },
188188+});
189189+```
190190+191191+```ts [none]
192192+import { client } from '@hey-api/client-fetch';
193193+194194+client.post({
195195+ body: {
196196+ name: 'Kitty',
197197+ },
198198+ url: '/pet',
199199+});
200200+```
201201+202202+:::
203203+204204+## JSON Schemas
205205+206206+Schemas are located in the `schemas.gen.ts` file. This file contains runtime schemas generated from your OpenAPI specification definitions located in `#/components/schemas`. Starting with OpenAPI 3.1, these schemas are JSON Schema compliant.
207207+208208+```ts
209209+export const $Pet = {
210210+ required: ['name'],
211211+ properties: {
212212+ id: {
213213+ type: 'integer',
214214+ format: 'int64',
215215+ example: 10,
216216+ },
217217+ name: {
218218+ type: 'string',
219219+ example: 'doggie',
220220+ },
221221+ },
222222+ type: 'object',
223223+} as const;
224224+```
225225+226226+You may want to use schemas if you want to enforce form validations that aren't possible using only types, such as maximum field length.
227227+228228+```ts
229229+import { $Schema } from './client/schemas.gen';
230230+231231+const maxInputLength = $Schema.properties.text.maxLength;
232232+233233+if (userInput.length > maxInputLength) {
234234+ throw new Error(`Text length can't exceed ${maxInputLength} characters!`);
235235+}
236236+```
237237+238238+## Index
239239+240240+For convenience, every generated artifact is re-exported from `index.ts`. We recommend importing types, services, and schemas from their respective files to avoid ambiguity, but you can also use the index file.
241241+242242+```ts
243243+import type { Pet } from './client/types.gen';
244244+// or
245245+import type { Pet } from './client';
246246+```
247247+248248+## Core
249249+250250+Client core files are located in the `core` folder. This folder will include different files depending on which client you're using. If you're using standalone packages, this folder will not be generated at all.
251251+252252+For legacy clients, the [`OpenAPI`](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/templates/core/OpenAPI.hbs#L68-L84) configuration object will be most likely of interest. You can change its properties to set authorization tokens, base URL, and more.
253253+254254+```ts
255255+import { OpenAPI } from './client/core/OpenAPI';
256256+```
257257+258258+## Plugins
259259+260260+Different plugins may emit their own artifacts. These will be documented in their respective pages.
261261+262262+<!--@include: ../examples.md-->
···11# @hey-api/client-fetch
2233+## 0.1.3
44+55+### Patch Changes
66+77+- [#639](https://github.com/hey-api/openapi-ts/pull/639) [`820002f`](https://github.com/hey-api/openapi-ts/commit/820002ffe687b01c7a9b2250e19ddbafd1aaed71) Thanks [@mrlubos](https://github.com/mrlubos)! - fix: do not widen body type on optional prop
88+99+## 0.1.2
1010+1111+### Patch Changes
1212+1313+- fix: JSON stringify object headers ([#616](https://github.com/hey-api/openapi-ts/pull/616))
1414+1515+## 0.1.1
1616+1717+### Patch Changes
1818+1919+- fix: export Client interface ([#610](https://github.com/hey-api/openapi-ts/pull/610))
2020+321## 0.1.0
422523### Minor Changes
+1-1
packages/client-fetch/package.json
···11{
22 "name": "@hey-api/client-fetch",
33- "version": "0.1.0",
33+ "version": "0.1.3",
44 "type": "module",
55 "description": "Typesafe Fetch API client for your @hey-api/openapi-ts types",
66 "homepage": "https://heyapi.vercel.app/",
+8-7
packages/client-fetch/src/types.ts
···5656 | (string | number | boolean)[]
5757 | null
5858 | undefined
5959+ | unknown
5960 >;
6061 /**
6162 * The request method.
···141142 client?: Client;
142143};
143144144144-export type Options<T = unknown> = T extends { body: any; headers: any }
145145- ? OmitKeys<OptionsBase, 'body' | 'headers'> & T
146146- : T extends { body: any }
147147- ? OmitKeys<OptionsBase, 'body'> & T
148148- : T extends { headers: any }
149149- ? OmitKeys<OptionsBase, 'headers'> & T
150150- : OptionsBase & T;
145145+export type Options<T = unknown> = T extends { body?: any }
146146+ ? T extends { headers?: any }
147147+ ? OmitKeys<OptionsBase, 'body' | 'headers'> & T
148148+ : OmitKeys<OptionsBase, 'body'> & T & Pick<OptionsBase, 'headers'>
149149+ : T extends { headers?: any }
150150+ ? OmitKeys<OptionsBase, 'headers'> & T & Pick<OptionsBase, 'body'>
151151+ : OptionsBase & T;
+6-1
packages/client-fetch/src/utils.ts
···402402 mergedHeaders.append(key, v as string);
403403 }
404404 } else if (value !== undefined) {
405405- mergedHeaders.set(key, value as string);
405405+ // assume object headers are meant to be JSON stringified, i.e. their
406406+ // content value in OpenAPI specification is 'application/json'
407407+ mergedHeaders.set(
408408+ key,
409409+ typeof value === 'object' ? JSON.stringify(value) : (value as string),
410410+ );
406411 }
407412 }
408413 }
+24
packages/openapi-ts/CHANGELOG.md
···11# @hey-api/openapi-ts
2233+## 0.46.3
44+55+### Patch Changes
66+77+- [#594](https://github.com/hey-api/openapi-ts/pull/594) [`9878381`](https://github.com/hey-api/openapi-ts/commit/98783811e0c90705ddac2cc5e54c524aae634865) Thanks [@SimenB](https://github.com/SimenB)! - Add explicit type annotations to `Interceptors`
88+99+ This allows the generated code to work with TypeScript 5.5's new `isolatedDeclarations` configuration.
1010+1111+- [#635](https://github.com/hey-api/openapi-ts/pull/635) [`0b09940`](https://github.com/hey-api/openapi-ts/commit/0b0994050dbcb6c17e8b78ca1c77738fc8e0d498) Thanks [@mrlubos](https://github.com/mrlubos)! - fix: handle 1XX response status codes
1212+1313+- [#636](https://github.com/hey-api/openapi-ts/pull/636) [`498f459`](https://github.com/hey-api/openapi-ts/commit/498f45979b91bf93b319413c60492af94a08df48) Thanks [@mrlubos](https://github.com/mrlubos)! - fix: improve default response status code classification
1414+1515+## 0.46.2
1616+1717+### Patch Changes
1818+1919+- fix: do not transform property names for standalone clients ([#616](https://github.com/hey-api/openapi-ts/pull/616))
2020+2121+## 0.46.1
2222+2323+### Patch Changes
2424+2525+- fix: handle application/json content type in parameter definitions ([#614](https://github.com/hey-api/openapi-ts/pull/614))
2626+327## 0.46.0
428529### Minor Changes
+1-1
packages/openapi-ts/README.md
···10101111## Features
12121313-- works with CLI, Node.js, or npx
1313+- works with CLI, Node.js 18+, or npx
1414- supports OpenAPI 2.0, 3.0, and 3.1 specifications
1515- supports both JSON and YAML input files
1616- generates TypeScript interfaces, REST clients, and JSON Schemas
···11+import type { OpenApiParameter } from '../interfaces/OpenApiParameter';
22+import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
33+44+export const getParameterSchema = (
55+ definition: OpenApiParameter,
66+): OpenApiSchema | undefined => {
77+ if (definition.schema) {
88+ return definition.schema;
99+ }
1010+1111+ if (definition.content) {
1212+ // treat every media type the same for now, types should be modified to
1313+ // preserve this data so client knows which headers to use and how to
1414+ // parse response bodies
1515+ const contents = Object.entries(definition.content);
1616+ for (const [key, mediaTypeObject] of contents) {
1717+ if (mediaTypeObject.schema) {
1818+ const mediaType = key as keyof Required<OpenApiParameter>['content'];
1919+ return definition.content[mediaType].schema;
2020+ }
2121+ }
2222+ }
2323+};
···11import { compiler, type Property, type TypeNode } from '../../compiler';
22import type { Model } from '../../openApi';
33+import { transformTypeKeyName } from '../../openApi/common/parser/type';
34import type { Client } from '../../types/client';
44-import { getConfig } from '../config';
55+import { getConfig, isStandaloneClient } from '../config';
56import { enumValue } from '../enum';
66-import { escapeComment } from '../escape';
77+import { escapeComment, escapeName, unescapeName } from '../escape';
78import { unique } from '../unique';
89910const base = (model: Model) => {
···8485 return compiler.typedef.basic('unknown');
8586 }
86878888+ const config = getConfig();
8989+9090+ const isStandalone = isStandaloneClient(config);
9191+8792 const properties: Property[] = model.properties.map((property) => {
8893 let maybeRequired = property.isRequired ? '' : '?';
8994 let value = toType(property);
···99104 ],
100105 isReadOnly: property.isReadOnly,
101106 isRequired: maybeRequired === '',
102102- name: property.name,
107107+ name: isStandalone
108108+ ? escapeName(unescapeName(transformTypeKeyName(property.name)))
109109+ : // special test for 1XX status codes. We need a more robust system
110110+ // for escaping values depending on context in which they're printed,
111111+ // but since this works for standalone client, it's not worth it right now
112112+ /^\dXX$/.test(property.name)
113113+ ? escapeName(property.name)
114114+ : property.name,
103115 type: value,
104116 };
105117 });
···11+// This file is auto-generated by @hey-api/openapi-ts
22+export * from './schemas.gen';
33+export * from './services.gen';
44+export * from './types.gen';