Skip to content

Commit 458441d

Browse files
committed
docs: add advanced section to configuration
1 parent e35dc0b commit 458441d

File tree

5 files changed

+110
-91
lines changed

5 files changed

+110
-91
lines changed

.changeset/dry-jeans-ring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'@hey-api/openapi-ts': patch
33
---
44

5-
feat: add support for array configuration, input, and output objects
5+
feat: support multiple configurations

docs/openapi-ts/configuration.md

Lines changed: 102 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,65 +38,6 @@ export default {
3838

3939
Alternatively, you can use `openapi-ts.config.js` and configure the export statement depending on your project setup.
4040

41-
### Async config and factories
42-
43-
You can also export a function (sync or async) if you need to compute configuration dynamically (e.g., read env vars):
44-
45-
```js
46-
import { defineConfig } from '@hey-api/openapi-ts';
47-
48-
export default defineConfig(async () => {
49-
return {
50-
input: 'hey-api/backend',
51-
output: 'src/client',
52-
};
53-
});
54-
```
55-
56-
### Multiple configurations
57-
58-
You can also export an array to run multiple configurations in a single invocation (e.g., generate multiple clients):
59-
60-
```js
61-
import { defineConfig } from '@hey-api/openapi-ts';
62-
63-
export default defineConfig([
64-
{
65-
input: 'path/to/openapi_one.json',
66-
output: 'src/client_one',
67-
},
68-
{
69-
input: 'path/to/openapi_two.json',
70-
output: 'src/client_two',
71-
},
72-
]);
73-
```
74-
75-
<!--
76-
TODO: uncomment after c12 supports multiple configs
77-
see https://github.com/unjs/c12/issues/92
78-
-->
79-
<!-- ### Multiple Clients
80-
81-
If you want to generate multiple clients with a single `openapi-ts` command, you can provide an array of configuration objects.
82-
83-
```js
84-
import { defineConfig } from '@hey-api/openapi-ts';
85-
86-
export default defineConfig([
87-
{
88-
input: 'path/to/openapi_one.json',
89-
output: 'src/client_one',
90-
plugins: ['legacy/fetch'],
91-
},
92-
{
93-
input: 'path/to/openapi_two.json',
94-
output: 'src/client_two',
95-
plugins: ['legacy/axios'],
96-
},
97-
])
98-
``` -->
99-
10041
## Input
10142

10243
You must provide an input so we can load your OpenAPI specification.
@@ -197,6 +138,108 @@ Plugins are responsible for generating artifacts from your input. By default, He
197138

198139
You can learn more on the [Output](/openapi-ts/output) page.
199140

141+
## Advanced
142+
143+
More complex configuration scenarios can be handled by providing an array of inputs, outputs, or configurations.
144+
145+
### Multiple jobs
146+
147+
Throughout this documentation, we generally reference single job configurations. However, you can easily run multiple jobs by providing an array of configuration objects.
148+
149+
::: code-group
150+
151+
```js [config]
152+
export default [
153+
{
154+
input: 'foo.yaml',
155+
output: 'src/foo',
156+
},
157+
{
158+
input: 'bar.yaml',
159+
output: 'src/bar',
160+
},
161+
];
162+
```
163+
164+
```md [example]
165+
src/
166+
├── foo/
167+
│ ├── client/
168+
│ ├── core/
169+
│ ├── client.gen.ts
170+
│ ├── index.ts
171+
│ ├── sdk.gen.ts
172+
│ └── types.gen.ts
173+
└── bar/
174+
├── client/
175+
├── core/
176+
├── client.gen.ts
177+
├── index.ts
178+
├── sdk.gen.ts
179+
└── types.gen.ts
180+
```
181+
182+
:::
183+
184+
### Job matrix
185+
186+
Reusing configuration across multiple jobs is possible by defining a job matrix. You can create a job matrix by providing `input` and `output` arrays of matching length.
187+
188+
::: code-group
189+
190+
```js [config]
191+
export default {
192+
input: ['foo.yaml', 'bar.yaml'],
193+
output: ['src/foo', 'src/bar'],
194+
};
195+
```
196+
197+
```md [example]
198+
src/
199+
├── foo/
200+
│ ├── client/
201+
│ ├── core/
202+
│ ├── client.gen.ts
203+
│ ├── index.ts
204+
│ ├── sdk.gen.ts
205+
│ └── types.gen.ts
206+
└── bar/
207+
├── client/
208+
├── core/
209+
├── client.gen.ts
210+
├── index.ts
211+
├── sdk.gen.ts
212+
└── types.gen.ts
213+
```
214+
215+
:::
216+
217+
### Merging inputs
218+
219+
You can merge inputs by defining multiple inputs and a single output.
220+
221+
::: code-group
222+
223+
```js [config]
224+
export default {
225+
input: ['foo.yaml', 'bar.yaml'],
226+
output: 'src/client',
227+
};
228+
```
229+
230+
```md [example]
231+
src/
232+
└── client/
233+
├── client/
234+
├── core/
235+
├── client.gen.ts
236+
├── index.ts
237+
├── sdk.gen.ts
238+
└── types.gen.ts
239+
```
240+
241+
:::
242+
200243
## API
201244

202245
You 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.d.ts) interface.

docs/openapi-ts/configuration/input.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You must provide an input so we can load your OpenAPI specification.
99

1010
## Input
1111

12-
The input can be a string path, URL, [API registry](#api-registry), an object containing any of these, or an object representing an OpenAPI specification. You can also pass an array of inputs to merge multiple specifications. Hey API supports all valid OpenAPI versions and file formats.
12+
The input can be a string path, URL, [API registry](#api-registry), an object containing any of these, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
1313

1414
::: code-group
1515

@@ -52,22 +52,10 @@ export default {
5252
```
5353
<!-- prettier-ignore-end -->
5454

55-
```js [array]
56-
export default {
57-
input: [
58-
// [!code ++]
59-
'hey-api/backend', // [!code ++]
60-
'./overrides/openapi.yaml', // [!code ++]
61-
], // [!code ++]
62-
};
63-
// When you pass multiple inputs as an array, `@hey-api/openapi-ts` bundles them into a single resolved OpenAPI
64-
// document. To avoid name collisions between files, component names may be prefixed with the input file’s base
65-
// name when needed (for example, `users.yaml` ➜ `users.*`). References across files are resolved, and
66-
// later inputs in the array can override earlier ones on conflict.
67-
```
68-
6955
:::
7056

57+
You can learn more about complex use cases in the [Advanced](/openapi-ts/configuration#advanced) section.
58+
7159
::: info
7260
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.
7361
:::

docs/openapi-ts/configuration/output.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,10 @@ export default {
3232
```
3333
<!-- prettier-ignore-end -->
3434

35-
```js [array]
36-
export default {
37-
input: 'hey-api/backend', // sign up at app.heyapi.dev
38-
output: [
39-
// [!code ++]
40-
'src/client', // [!code ++]
41-
{ path: 'src/client-formatted', format: 'prettier' }, // [!code ++]
42-
{ path: 'src/client-linted', lint: 'eslint', clean: false }, // [!code ++]
43-
], // [!code ++]
44-
};
45-
```
46-
47-
<!-- prettier-ignore-end -->
48-
4935
:::
5036

37+
You can learn more about complex use cases in the [Advanced](/openapi-ts/configuration#advanced) section.
38+
5139
## File Name
5240

5341
You can customize the naming and casing pattern for files using the `fileName` option.

packages/openapi-ts/src/utils/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ db e888888e
77
d8 Y88Y ~8b
88
dY "" "" Yb
99
8 88 88 8
10-
8 e8e 8 8
11-
Yb " eb ,b
10+
8 o 8 8
11+
Yb b8d eb ,b
1212
Yb_____Y ,b
1313
8 dY
1414
8 e 8

0 commit comments

Comments
 (0)