Skip to content

Commit 34bc6e7

Browse files
authored
Merge pull request #2718 from hey-api/feat/import-file-extension
feat(config): add output.importFileExtension option
2 parents 9c2401a + fcdd73b commit 34bc6e7

File tree

105 files changed

+23012
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+23012
-101
lines changed

.changeset/pretty-deers-change.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@hey-api/openapi-ts': minor
3+
---
4+
5+
refactor(config): replace 'off' with null to disable options
6+
7+
### Updated `output` options
8+
9+
We made the `output` configuration more consistent by using `null` to represent disabled options. This change does not affect boolean options.
10+
11+
```js
12+
export default {
13+
input: 'hey-api/backend', // sign up at app.heyapi.dev
14+
output: {
15+
format: null,
16+
lint: null,
17+
path: 'src/client',
18+
tsConfigPath: null,
19+
},
20+
};
21+
```

.changeset/red-bats-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
feat(config): add `output.importFileExtension` option

.changeset/refactor-pinia-colada-query.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,48 @@
33
---
44

55
feat(pinia-colada): query options use `defineQueryOptions`
6+
7+
### Updated Pinia Colada query options
8+
9+
Pinia Colada query options now use `defineQueryOptions` to improve reactivity support. Instead of calling the query options function, you can use one of the following approaches.
10+
11+
#### No params
12+
13+
```ts
14+
useQuery(getPetsQuery);
15+
```
16+
17+
#### Constant
18+
19+
```ts
20+
useQuery(getPetByIdQuery, () => ({
21+
path: {
22+
petId: 1,
23+
},
24+
}));
25+
```
26+
27+
#### Reactive
28+
29+
```ts
30+
const petId = ref<number | null>(1);
31+
32+
useQuery(getPetByIdQuery, () => ({
33+
path: {
34+
petId: petId.value,
35+
},
36+
}));
37+
```
38+
39+
#### Properties
40+
41+
```ts
42+
const petId = ref<number | null>(1);
43+
44+
useQuery(() => ({
45+
...getPetByIdQuery({
46+
path: { petId: petId.value as number },
47+
}),
48+
enabled: () => petId.value != null,
49+
}));
50+
```

docs/openapi-ts/configuration/output.md

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default {
8080
};
8181
```
8282

83-
```js [off]
83+
```js [disabled]
8484
export default {
8585
input: 'hey-api/backend', // sign up at app.heyapi.dev
8686
output: {
@@ -106,17 +106,77 @@ export default {
106106

107107
:::
108108

109+
## Import File Extension
110+
111+
You can customize the extension used for imported TypeScript files.
112+
113+
::: code-group
114+
115+
```js [default]
116+
export default {
117+
input: 'hey-api/backend', // sign up at app.heyapi.dev
118+
output: {
119+
importFileExtension: undefined, // [!code ++]
120+
path: 'src/client',
121+
},
122+
};
123+
```
124+
125+
```js [disabled]
126+
export default {
127+
input: 'hey-api/backend', // sign up at app.heyapi.dev
128+
output: {
129+
importFileExtension: null, // [!code ++]
130+
path: 'src/client',
131+
},
132+
};
133+
```
134+
135+
```js [js]
136+
export default {
137+
input: 'hey-api/backend', // sign up at app.heyapi.dev
138+
output: {
139+
importFileExtension: '.js', // [!code ++]
140+
path: 'src/client',
141+
},
142+
};
143+
```
144+
145+
```js [ts]
146+
export default {
147+
input: 'hey-api/backend', // sign up at app.heyapi.dev
148+
output: {
149+
importFileExtension: '.ts', // [!code ++]
150+
path: 'src/client',
151+
},
152+
};
153+
```
154+
155+
:::
156+
157+
By default, we don't add a file extension and let the runtime resolve it.
158+
159+
```js
160+
import foo from './foo';
161+
```
162+
163+
If we detect a [TSConfig file](#tsconfig-path) with `moduleResolution` option set to `nodenext`, we default the extension to `.js`.
164+
165+
```js
166+
import foo from './foo.js';
167+
```
168+
109169
## Format
110170

111-
To format your output folder contents, set `output.format` to a valid formatter.
171+
To format your output folder contents, set `format` to a valid formatter.
112172

113173
::: code-group
114174

115175
```js [disabled]
116176
export default {
117177
input: 'hey-api/backend', // sign up at app.heyapi.dev
118178
output: {
119-
format: false, // [!code ++]
179+
format: null, // [!code ++]
120180
path: 'src/client',
121181
},
122182
};
@@ -148,15 +208,15 @@ You can also prevent your output from being formatted by adding your output path
148208

149209
## Lint
150210

151-
To lint your output folder contents, set `output.lint` to a valid linter.
211+
To lint your output folder contents, set `lint` to a valid linter.
152212

153213
::: code-group
154214

155215
```js [disabled]
156216
export default {
157217
input: 'hey-api/backend', // sign up at app.heyapi.dev
158218
output: {
159-
lint: false, // [!code ++]
219+
lint: null, // [!code ++]
160220
path: 'src/client',
161221
},
162222
};
@@ -198,10 +258,20 @@ You can also prevent your output from being linted by adding your output path to
198258

199259
## TSConfig Path
200260

201-
We use the [TSConfig file](https://www.typescriptlang.org/tsconfig/) to generate output matching your project's settings. By default, we attempt to find a TSConfig file starting from the location of the `@hey-api/openapi-ts` configuration file and traversing up. If your file is located in a different place or you want to disable this setting, set `output.tsConfigPath` to a string.
261+
We use the [TSConfig file](https://www.typescriptlang.org/tsconfig/) to generate output matching your project's settings. By default, we attempt to find a TSConfig file starting from the location of the `@hey-api/openapi-ts` configuration file and traversing up.
202262

203263
::: code-group
204264

265+
```js [default]
266+
export default {
267+
input: 'hey-api/backend', // sign up at app.heyapi.dev
268+
output: {
269+
path: 'src/client',
270+
tsConfigPath: undefined, // [!code ++]
271+
},
272+
};
273+
```
274+
205275
```js [custom]
206276
export default {
207277
input: 'hey-api/backend', // sign up at app.heyapi.dev
@@ -212,12 +282,12 @@ export default {
212282
};
213283
```
214284

215-
```js [off]
285+
```js [disabled]
216286
export default {
217287
input: 'hey-api/backend', // sign up at app.heyapi.dev
218288
output: {
219289
path: 'src/client',
220-
tsConfigPath: 'off', // [!code ++]
290+
tsConfigPath: null, // [!code ++]
221291
},
222292
};
223293
```
@@ -226,7 +296,7 @@ export default {
226296

227297
## Custom Files
228298

229-
By default, you can't keep custom files in the `output.path` folder because it's emptied on every run. If you're sure you need to disable this behavior, set `output.clean` to `false`.
299+
By default, you can't keep custom files in the `path` folder because it's emptied on every run. If you're sure you need to disable this behavior, set `clean` to `false`.
230300

231301
```js
232302
export default {
@@ -239,7 +309,7 @@ export default {
239309
```
240310

241311
::: warning
242-
Setting `output.clean` to `false` may result in broken output. Ensure you typecheck your code.
312+
Setting `clean` to `false` may result in broken output. Ensure you typecheck your code.
243313
:::
244314

245315
<!--@include: ../../partials/examples.md-->

docs/openapi-ts/migrating.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,68 @@ description: Migrating to @hey-api/openapi-ts.
77

88
While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. If you run into a problem with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues).
99

10+
## v0.85.0
11+
12+
### Updated `output` options
13+
14+
We made the `output` configuration more consistent by using `null` to represent disabled options. This change does not affect boolean options.
15+
16+
```js
17+
export default {
18+
input: 'hey-api/backend', // sign up at app.heyapi.dev
19+
output: {
20+
format: false, // [!code --]
21+
format: null, // [!code ++]
22+
lint: false, // [!code --]
23+
lint: null, // [!code ++]
24+
path: 'src/client',
25+
tsConfigPath: 'off', // [!code --]
26+
tsConfigPath: null, // [!code ++]
27+
},
28+
};
29+
```
30+
31+
### Updated Pinia Colada query options
32+
33+
Pinia Colada query options now use `defineQueryOptions` to improve reactivity support. Instead of calling the query options function, you can use one of the following approaches.
34+
35+
::: code-group
36+
37+
```ts [no params]
38+
useQuery(getPetsQuery);
39+
```
40+
41+
```ts [constant]
42+
useQuery(getPetByIdQuery, () => ({
43+
path: {
44+
petId: 1,
45+
},
46+
}));
47+
```
48+
49+
```ts [reactive]
50+
const petId = ref<number | null>(1);
51+
52+
useQuery(getPetByIdQuery, () => ({
53+
path: {
54+
petId: petId.value,
55+
},
56+
}));
57+
```
58+
59+
```ts [properties]
60+
const petId = ref<number | null>(1);
61+
62+
useQuery(() => ({
63+
...getPetByIdQuery({
64+
path: { petId: petId.value as number },
65+
}),
66+
enabled: () => petId.value != null,
67+
}));
68+
```
69+
70+
:::
71+
1072
## v0.84.0
1173

1274
### Symbol API
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { type ClientOptions, type Config, createClient, createConfig } from './client/index.ts';
4+
import type { ClientOptions as ClientOptions2 } from './types.gen.ts';
5+
6+
/**
7+
* The `createClientConfig()` function will be called on client initialization
8+
* and the returned object will become the client's initial configuration.
9+
*
10+
* You may want to initialize your client this way instead of calling
11+
* `setConfig()`. This is useful for example if you're using Next.js
12+
* to ensure your client always has the correct values.
13+
*/
14+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
15+
16+
export const client = createClient(createConfig<ClientOptions2>({
17+
baseURL: 'http://localhost:3000/base'
18+
}));

0 commit comments

Comments
 (0)