@hey-api/openapi-ts 0.33.2 → 0.34.0
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/dist/node/index.d.ts +2 -1
- package/dist/node/index.js +1 -1
- package/package.json +7 -9
- package/LICENSE +0 -21
- package/README.md +0 -238
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hey-api/openapi-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Turn your OpenAPI specification into a beautiful TypeScript client",
|
|
6
6
|
"homepage": "https://github.com/hey-api/openapi-ts/",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"build-types-check": "tsc --project tsconfig.check.json",
|
|
42
42
|
"build-types-roll": "rollup --config rollup.dts.config.ts --configPlugin typescript && rimraf temp",
|
|
43
43
|
"build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node",
|
|
44
|
-
"build-types": "run
|
|
45
|
-
"build": "run
|
|
44
|
+
"build-types": "npm run build-types-temp && npm run build-types-roll && npm run build-types-check",
|
|
45
|
+
"build": "npm run clean && npm run build-bundle && npm run build-types",
|
|
46
46
|
"clean": "rimraf dist test/generated test/e2e/generated coverage node_modules/.cache",
|
|
47
47
|
"dev": "rimraf dist && npm run build-bundle -- --watch",
|
|
48
48
|
"lint:fix": "eslint . --fix",
|
|
@@ -78,29 +78,27 @@
|
|
|
78
78
|
"@angular/platform-browser": "17.3.2",
|
|
79
79
|
"@angular/platform-browser-dynamic": "17.3.2",
|
|
80
80
|
"@angular/router": "17.3.2",
|
|
81
|
-
"@changesets/cli": "2.27.1",
|
|
82
81
|
"@rollup/plugin-commonjs": "25.0.7",
|
|
83
82
|
"@rollup/plugin-json": "6.1.0",
|
|
84
83
|
"@rollup/plugin-node-resolve": "15.2.3",
|
|
85
84
|
"@rollup/plugin-terser": "0.4.4",
|
|
86
85
|
"@rollup/plugin-typescript": "11.1.6",
|
|
87
|
-
"@svitejs/changesets-changelog-github-compact": "1.1.0",
|
|
88
86
|
"@types/cross-spawn": "6.0.6",
|
|
89
87
|
"@types/express": "4.17.21",
|
|
90
88
|
"@types/node": "20.12.2",
|
|
91
|
-
"@typescript-eslint/eslint-plugin": "7.
|
|
92
|
-
"@typescript-eslint/parser": "7.
|
|
89
|
+
"@typescript-eslint/eslint-plugin": "7.5.0",
|
|
90
|
+
"@typescript-eslint/parser": "7.5.0",
|
|
93
91
|
"@vitest/coverage-v8": "1.4.0",
|
|
94
|
-
"abort-controller": "3.0.0",
|
|
95
92
|
"axios": "1.6.8",
|
|
96
93
|
"cross-spawn": "7.0.3",
|
|
97
94
|
"eslint": "8.57.0",
|
|
98
95
|
"eslint-config-prettier": "9.1.0",
|
|
99
96
|
"eslint-plugin-prettier": "5.1.3",
|
|
100
97
|
"eslint-plugin-simple-import-sort": "12.0.0",
|
|
98
|
+
"eslint-plugin-sort-keys-fix": "1.1.2",
|
|
101
99
|
"express": "4.19.2",
|
|
100
|
+
"glob": "10.3.12",
|
|
102
101
|
"node-fetch": "3.3.2",
|
|
103
|
-
"npm-run-all2": "6.1.2",
|
|
104
102
|
"prettier": "3.2.5",
|
|
105
103
|
"puppeteer": "22.6.1",
|
|
106
104
|
"rimraf": "5.0.5",
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
# OpenAPI TypeScript 👋
|
|
2
|
-
|
|
3
|
-
> ✨ Turn your OpenAPI specification into a beautiful TypeScript client
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
- [Table of Contents](#table-of-contents)
|
|
7
|
-
- [About](#about)
|
|
8
|
-
- [Features](#features)
|
|
9
|
-
- [Quick Start](#quick-start)
|
|
10
|
-
- [Installation](#installation)
|
|
11
|
-
- [Configuration](#configuration)
|
|
12
|
-
- [Clients](#clients)
|
|
13
|
-
- [Formatting](#formatting)
|
|
14
|
-
- [Linting](#linting)
|
|
15
|
-
- [Enums](#enums)
|
|
16
|
-
- [Config API](#config-api)
|
|
17
|
-
- [Interceptors](#interceptors)
|
|
18
|
-
- [Migrating](#migrating)
|
|
19
|
-
- [Contributing](#contributing)
|
|
20
|
-
|
|
21
|
-
## About
|
|
22
|
-
|
|
23
|
-
`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!
|
|
24
|
-
|
|
25
|
-
## Features
|
|
26
|
-
|
|
27
|
-
- generate TypeScript clients from OpenAPI v2.0, v3.0, and v3.1 specifications
|
|
28
|
-
- support JSON or YAML input files
|
|
29
|
-
- handle external references using [JSON Schema $Ref Parser](https://github.com/APIDevTools/json-schema-ref-parser/)
|
|
30
|
-
- generate Fetch, Node-Fetch, Axios, Angular, or XHR HTTP clients
|
|
31
|
-
- can be used with CLI, Node.js, or npx
|
|
32
|
-
- abortable requests through cancellable promise pattern
|
|
33
|
-
|
|
34
|
-
## Quick Start
|
|
35
|
-
|
|
36
|
-
The fastest way to use `openapi-ts` is via npx
|
|
37
|
-
|
|
38
|
-
```sh
|
|
39
|
-
npx @hey-api/openapi-ts -i path/to/openapi.json -o src/client
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Congratulations on creating your first client! 🎉
|
|
43
|
-
|
|
44
|
-
## Installation
|
|
45
|
-
|
|
46
|
-
```sh
|
|
47
|
-
npm install @hey-api/openapi-ts --save-dev
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
or
|
|
51
|
-
|
|
52
|
-
```sh
|
|
53
|
-
yarn add @hey-api/openapi-ts -D
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
If you want to use `openapi-ts` with CLI, add a script to your `package.json` file
|
|
57
|
-
|
|
58
|
-
```json
|
|
59
|
-
"scripts": {
|
|
60
|
-
"openapi-ts": "openapi-ts"
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
You can also generate your client programmatically by importing `openapi-ts` in a `.ts` file.
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
import { createClient } from '@hey-api/openapi-ts'
|
|
68
|
-
|
|
69
|
-
createClient({
|
|
70
|
-
input: 'path/to/openapi.json',
|
|
71
|
-
output: 'src/client',
|
|
72
|
-
})
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
> ⚠️ You need to be running Node.js v18 or newer
|
|
76
|
-
|
|
77
|
-
## Configuration
|
|
78
|
-
|
|
79
|
-
`openapi-ts` supports loading configuration from a file inside your project root directory. You can either create a `openapi-ts.config.cjs` file
|
|
80
|
-
|
|
81
|
-
```cjs
|
|
82
|
-
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
83
|
-
module.exports = {
|
|
84
|
-
input: 'path/to/openapi.json',
|
|
85
|
-
output: 'src/client',
|
|
86
|
-
}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
or `openapi-ts.config.mjs`
|
|
90
|
-
|
|
91
|
-
```mjs
|
|
92
|
-
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
93
|
-
export default {
|
|
94
|
-
input: 'path/to/openapi.json',
|
|
95
|
-
output: 'src/client',
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Alternatively, you can use `openapi-ts.config.js` and configure the export statement depending on your project setup.
|
|
100
|
-
|
|
101
|
-
### Clients
|
|
102
|
-
|
|
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
|
-
|
|
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.
|
|
126
|
-
|
|
127
|
-
### Formatting
|
|
128
|
-
|
|
129
|
-
By default, `openapi-ts` will automatically format your client according to your project configuration. To disable automatic formatting, set `format` to false
|
|
130
|
-
|
|
131
|
-
```mjs
|
|
132
|
-
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
133
|
-
export default {
|
|
134
|
-
format: false,
|
|
135
|
-
input: 'path/to/openapi.json',
|
|
136
|
-
output: 'src/client',
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
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`).
|
|
141
|
-
|
|
142
|
-
### Linting
|
|
143
|
-
|
|
144
|
-
For performance reasons, `openapi-ts` does not automatically lint your client. To enable this feature, set `lint` to true
|
|
145
|
-
|
|
146
|
-
```mjs
|
|
147
|
-
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
148
|
-
export default {
|
|
149
|
-
input: 'path/to/openapi.json',
|
|
150
|
-
lint: true,
|
|
151
|
-
output: 'src/client',
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
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`).
|
|
156
|
-
|
|
157
|
-
### Enums
|
|
158
|
-
|
|
159
|
-
If you need to iterate through possible field values without manually typing arrays, you can export enums with
|
|
160
|
-
|
|
161
|
-
```mjs
|
|
162
|
-
/** @type {import('@hey-api/openapi-ts').UserConfig} */
|
|
163
|
-
export default {
|
|
164
|
-
enums: 'javascript',
|
|
165
|
-
input: 'path/to/openapi.json',
|
|
166
|
-
output: 'src/client',
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
This will export enums as plain JavaScript objects. For example, `Foo` would become
|
|
171
|
-
|
|
172
|
-
```ts
|
|
173
|
-
export const FooEnum = {
|
|
174
|
-
FOO: 'foo',
|
|
175
|
-
BAR: 'bar',
|
|
176
|
-
} as const;
|
|
177
|
-
```
|
|
178
|
-
|
|
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
|
|
180
|
-
|
|
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
|
-
}
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
### Config API
|
|
191
|
-
|
|
192
|
-
You can view the complete list of options in the [UserConfig](./src/types/config.ts) interface.
|
|
193
|
-
|
|
194
|
-
## Interceptors
|
|
195
|
-
|
|
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
|
|
197
|
-
|
|
198
|
-
```ts
|
|
199
|
-
OpenAPI.interceptors.request.use((request) => {
|
|
200
|
-
doSomethingWithRequest(request)
|
|
201
|
-
return request // <-- must return request
|
|
202
|
-
})
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
and an example response interceptor
|
|
206
|
-
|
|
207
|
-
```ts
|
|
208
|
-
OpenAPI.interceptors.response.use(async (response) => {
|
|
209
|
-
await doSomethingWithResponse(response) // async
|
|
210
|
-
return response // <-- must return response
|
|
211
|
-
})
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
If you need to remove an interceptor, pass the same function to `OpenAPI.interceptors.request.eject()` or `OpenAPI.interceptors.response.eject()`.
|
|
215
|
-
|
|
216
|
-
> ⚠️ Angular client does not currently support request interceptors.
|
|
217
|
-
|
|
218
|
-
## Migrating
|
|
219
|
-
|
|
220
|
-
While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features.
|
|
221
|
-
|
|
222
|
-
### v0.27.38
|
|
223
|
-
|
|
224
|
-
### `useOptions: true`
|
|
225
|
-
|
|
226
|
-
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.
|
|
227
|
-
|
|
228
|
-
```ts
|
|
229
|
-
import { DefaultService } from 'client' // <-- old client with array arguments
|
|
230
|
-
|
|
231
|
-
import { DefaultService } from 'client_v2' // <-- new client with options argument
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
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`.
|
|
235
|
-
|
|
236
|
-
## Contributing
|
|
237
|
-
|
|
238
|
-
Please refer to the [contributing guide](CONTRIBUTING.md) for how to install the project for development purposes.
|