Skip to content

Commit 5898775

Browse files
committed
docs: add migration notes for 0.89.0
1 parent b6afac9 commit 5898775

File tree

24 files changed

+4745
-57
lines changed

24 files changed

+4745
-57
lines changed

dev/openapi-ts.config.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ export default defineConfig(() => {
107107
// indexFile: false,
108108
// lint: 'eslint',
109109
nameConflictResolver({ attempt, baseName }) {
110-
console.log('resolving conflict for:', { attempt, baseName });
110+
// console.log('resolving conflict for:', { attempt, baseName });
111111
return attempt === 0 ? baseName : `${baseName}_N${attempt + 1}`;
112112
},
113113
path: path.resolve(__dirname, '.gen'),
114-
preferExportAll: true,
114+
// preferExportAll: true,
115115
resolveModuleName: (moduleName) => {
116116
if (moduleName === 'valibot') {
117117
return 'valibot';
@@ -146,6 +146,14 @@ export default defineConfig(() => {
146146
},
147147
hooks: {
148148
events: {
149+
// 'node:set:after': ({ node, plugin }) => {
150+
// if (node) {
151+
// console.log(`(${plugin.name}) set node:`, node.symbol);
152+
// }
153+
// },
154+
// 'node:set:before': ({ node, plugin }) => {
155+
// console.log(`(${plugin.name}) setting node:`, node?.symbol?.id);
156+
// },
149157
// 'plugin:handler:after': ({ plugin }) => {
150158
// console.log(`(${plugin.name}): handler finished`);
151159
// },
@@ -171,12 +179,6 @@ export default defineConfig(() => {
171179
// );
172180
// }
173181
},
174-
// 'symbol:setValue:after': ({ plugin, symbol }) => {
175-
// console.log(`(${plugin.name}) set value:`, symbol.id);
176-
// },
177-
// 'symbol:setValue:before': ({ plugin, symbol }) => {
178-
// console.log(`(${plugin.name}) setting value:`, symbol.id);
179-
// },
180182
},
181183
operations: {
182184
getKind() {

docs/openapi-ts/configuration/output.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ export default {
108108

109109
:::
110110

111-
## Import File Extension
111+
## Module Extension
112112

113-
You can customize the extension used for imported TypeScript files.
113+
You can customize the extension used for TypeScript modules.
114114

115115
::: code-group
116116

@@ -258,6 +258,33 @@ export default {
258258

259259
You can also prevent your output from being linted by adding your output path to the linter's ignore file.
260260

261+
## Name Conflicts
262+
263+
As your project grows, the chances of name conflicts increase. We use a simple conflict resolver that appends numeric suffixes to duplicate identifiers. If you prefer a different strategy, you can provide your own `nameConflictResolver` function.
264+
265+
::: code-group
266+
267+
```js [config]
268+
export default {
269+
input: 'hey-api/backend', // sign up at app.heyapi.dev
270+
output: {
271+
nameConflictResolver({ attempt, baseName }) {
272+
// [!code ++]
273+
return attempt === 0 ? baseName : `${baseName}_N${attempt + 1}`; // [!code ++]
274+
}, // [!code ++]
275+
path: 'src/client',
276+
},
277+
};
278+
```
279+
280+
```ts [example]
281+
export type ChatCompletion = string;
282+
283+
export type ChatCompletion_N2 = number;
284+
```
285+
286+
:::
287+
261288
## TSConfig Path
262289

263290
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.

docs/openapi-ts/migrating.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ 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.89.0
11+
12+
### Prefer named exports
13+
14+
This release changes the default for `index.ts` to prefer named exports. Named exports may lead to better IDE and bundler performance compared to asterisk (`*`) as your tooling doesn't have to inspect the underlying module to discover exports.
15+
16+
While this change is merely cosmetic, you can set `output.preferExportAll` to `true` if you prefer to use the asterisk.
17+
18+
```js
19+
export default {
20+
input: 'hey-api/backend', // sign up at app.heyapi.dev
21+
output: {
22+
path: 'src/client',
23+
preferExportAll: true, // [!code ++]
24+
},
25+
};
26+
```
27+
28+
### Removed `symbol:setValue:*` events
29+
30+
These events have been removed in favor of `node:set:*` events.
31+
1032
## v0.88.0
1133

1234
### Removed `compiler` and `tsc` exports

docs/openapi-ts/output.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,5 @@ export default {
111111
};
112112
```
113113

114-
::: warning
115-
Re-exporting additional files from index file may result in broken output due to naming conflicts.
116-
:::
117-
118114
<!--@include: ../partials/examples.md-->
119115
<!--@include: ../partials/sponsors.md-->

packages/codegen-core/src/planner/planner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,10 @@ export class Planner {
384384
const ok = kinds.every((kind) => canShareName(symbol.kind, kind));
385385
if (ok) break;
386386

387+
const language = symbol.node?.language || symbol.file?.language;
387388
const resolver =
388-
(symbol.node?.language
389-
? this.project.nameConflictResolvers[symbol.node.language]
390-
: undefined) ?? this.project.defaultNameConflictResolver;
389+
(language ? this.project.nameConflictResolvers[language] : undefined) ??
390+
this.project.defaultNameConflictResolver;
391391
const resolvedName = resolver({ attempt, baseName });
392392
if (!resolvedName) {
393393
throw new Error(`Unresolvable name conflict: ${symbol.toString()}`);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { type ClientOptions, type Config, createClient, createConfig } from './client';
4+
import type { ClientOptions as ClientOptions2 } from './types.gen';
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>());

0 commit comments

Comments
 (0)