···11+---
22+"@hey-api/openapi-ts": patch
33+---
44+55+fix(docs): ensure README is shown on NPMJS
+244
packages/openapi-ts/README.md
···11+# OpenAPI TypeScript 👋
22+33+> ✨ Turn your OpenAPI specification into a beautiful TypeScript client
44+55+## Table of Contents
66+- [Table of Contents](#table-of-contents)
77+- [About](#about)
88+- [Features](#features)
99+- [Quick Start](#quick-start)
1010+- [Installation](#installation)
1111+- [Configuration](#configuration)
1212+ - [Clients](#clients)
1313+ - [Formatting](#formatting)
1414+ - [Linting](#linting)
1515+ - [Enums](#enums)
1616+ - [Config API](#config-api)
1717+- [Interceptors](#interceptors)
1818+- [Migrating](#migrating)
1919+- [Contributing](#contributing)
2020+2121+## About
2222+2323+`openapi-ts` started as a fork of [openapi-typescript-codegen](https://github.com/ferdikoomen/openapi-typescript-codegen). We created it after the original project became [unmaintained](https://github.com/ferdikoomen/openapi-typescript-codegen/issues/1276#issuecomment-1302392146) to add support for OpenAPI v3.1. We plan to resolve the most pressing issues in the original project – open an issue if you'd like to prioritise your use case!
2424+2525+## Features
2626+2727+- generate TypeScript clients from OpenAPI v2.0, v3.0, and v3.1 specifications
2828+- support JSON or YAML input files
2929+- handle external references using [JSON Schema $Ref Parser](https://github.com/APIDevTools/json-schema-ref-parser/)
3030+- generate Fetch, Node-Fetch, Axios, Angular, or XHR HTTP clients
3131+- can be used with CLI, Node.js, or npx
3232+- abortable requests through cancellable promise pattern
3333+3434+## Quick Start
3535+3636+The fastest way to use `openapi-ts` is via npx
3737+3838+```sh
3939+npx @hey-api/openapi-ts -i path/to/openapi.json -o src/client
4040+```
4141+4242+Congratulations on creating your first client! 🎉
4343+4444+## Installation
4545+4646+```sh
4747+npm install @hey-api/openapi-ts --save-dev
4848+```
4949+5050+or
5151+5252+```sh
5353+yarn add @hey-api/openapi-ts -D
5454+```
5555+5656+or
5757+5858+```sh
5959+pnpm add @hey-api/openapi-ts -D
6060+```
6161+6262+If you want to use `openapi-ts` with CLI, add a script to your `package.json` file
6363+6464+```json
6565+"scripts": {
6666+ "openapi-ts": "openapi-ts"
6767+}
6868+```
6969+7070+You can also generate your client programmatically by importing `openapi-ts` in a `.ts` file.
7171+7272+```ts
7373+import { createClient } from '@hey-api/openapi-ts'
7474+7575+createClient({
7676+ input: 'path/to/openapi.json',
7777+ output: 'src/client',
7878+})
7979+```
8080+8181+> ⚠️ You need to be running Node.js v18 or newer
8282+8383+## Configuration
8484+8585+`openapi-ts` supports loading configuration from a file inside your project root directory. You can either create a `openapi-ts.config.cjs` file
8686+8787+```cjs
8888+/** @type {import('@hey-api/openapi-ts').UserConfig} */
8989+module.exports = {
9090+ input: 'path/to/openapi.json',
9191+ output: 'src/client',
9292+}
9393+```
9494+9595+or `openapi-ts.config.mjs`
9696+9797+```mjs
9898+/** @type {import('@hey-api/openapi-ts').UserConfig} */
9999+export default {
100100+ input: 'path/to/openapi.json',
101101+ output: 'src/client',
102102+}
103103+```
104104+105105+Alternatively, you can use `openapi-ts.config.js` and configure the export statement depending on your project setup.
106106+107107+### Clients
108108+109109+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
110110+111111+```mjs
112112+/** @type {import('@hey-api/openapi-ts').UserConfig} */
113113+export default {
114114+ client: 'fetch',
115115+ input: 'path/to/openapi.json',
116116+ output: 'src/client',
117117+}
118118+```
119119+120120+We support these clients:
121121+122122+- [angular](https://angular.io/) (using [RxJS](https://rxjs.dev/))
123123+- [axios](https://axios-http.com/)
124124+- [fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API)
125125+126126+We also support the legacy Node.js and XHR clients:
127127+128128+- [node](https://nodejs.org/) (using [node-fetch](https://www.npmjs.com/package/node-fetch))
129129+- [xhr](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest)
130130+131131+> ⚠️ 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.
132132+133133+### Formatting
134134+135135+By default, `openapi-ts` will automatically format your client according to your project configuration. To disable automatic formatting, set `format` to false
136136+137137+```mjs
138138+/** @type {import('@hey-api/openapi-ts').UserConfig} */
139139+export default {
140140+ format: false,
141141+ input: 'path/to/openapi.json',
142142+ output: 'src/client',
143143+}
144144+```
145145+146146+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`).
147147+148148+### Linting
149149+150150+For performance reasons, `openapi-ts` does not automatically lint your client. To enable this feature, set `lint` to true
151151+152152+```mjs
153153+/** @type {import('@hey-api/openapi-ts').UserConfig} */
154154+export default {
155155+ input: 'path/to/openapi.json',
156156+ lint: true,
157157+ output: 'src/client',
158158+}
159159+```
160160+161161+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`).
162162+163163+### Enums
164164+165165+If you need to iterate through possible field values without manually typing arrays, you can export enums with
166166+167167+```mjs
168168+/** @type {import('@hey-api/openapi-ts').UserConfig} */
169169+export default {
170170+ enums: 'javascript',
171171+ input: 'path/to/openapi.json',
172172+ output: 'src/client',
173173+}
174174+```
175175+176176+This will export enums as plain JavaScript objects. For example, `Foo` would become
177177+178178+```ts
179179+export const FooEnum = {
180180+ FOO: 'foo',
181181+ BAR: 'bar',
182182+} as const;
183183+```
184184+185185+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
186186+187187+```mjs
188188+/** @type {import('@hey-api/openapi-ts').UserConfig} */
189189+export default {
190190+ enums: 'typescript',
191191+ input: 'path/to/openapi.json',
192192+ output: 'src/client',
193193+}
194194+```
195195+196196+### Config API
197197+198198+You can view the complete list of options in the [UserConfig](./src/types/config.ts) interface.
199199+200200+## Interceptors
201201+202202+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
203203+204204+```ts
205205+OpenAPI.interceptors.request.use((request) => {
206206+ doSomethingWithRequest(request)
207207+ return request // <-- must return request
208208+})
209209+```
210210+211211+and an example response interceptor
212212+213213+```ts
214214+OpenAPI.interceptors.response.use(async (response) => {
215215+ await doSomethingWithResponse(response) // async
216216+ return response // <-- must return response
217217+})
218218+```
219219+220220+If you need to remove an interceptor, pass the same function to `OpenAPI.interceptors.request.eject()` or `OpenAPI.interceptors.response.eject()`.
221221+222222+> ⚠️ Angular client does not currently support request interceptors.
223223+224224+## Migrating
225225+226226+While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features.
227227+228228+### v0.27.38
229229+230230+### `useOptions: true`
231231+232232+By default, generated clients will use a single object argument to pass values to API calls. This is a significant change from the previous default of unspecified array of arguments. If migrating your application in one go isn't feasible, we recommend deprecating your old client and generating a new client.
233233+234234+```ts
235235+import { DefaultService } from 'client' // <-- old client with array arguments
236236+237237+import { DefaultService } from 'client_v2' // <-- new client with options argument
238238+```
239239+240240+This way, you can gradually switch over to the new syntax as you update parts of your code. Once you've removed all instances of `client` imports, you can safely delete the old `client` folder and find and replace all `client_v2` calls to `client`.
241241+242242+## Contributing
243243+244244+Please refer to the [contributing guide](CONTRIBUTING.md) for how to install the project for development purposes.