Skip to content

Commit d45675e

Browse files
authored
Merge pull request #2990 from hey-api/feat/name-dedup
Remove placeholders
2 parents 0804fb8 + c3a81e8 commit d45675e

File tree

698 files changed

+15207
-6616
lines changed

Some content is hidden

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

698 files changed

+15207
-6616
lines changed

.changeset/clean-apes-divide.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
**output**: add `nameConflictResolver` option
6+
7+
## Name Conflicts
8+
9+
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.
10+
11+
```js
12+
export default {
13+
input: 'hey-api/backend', // sign up at app.heyapi.dev
14+
output: {
15+
nameConflictResolver({ attempt, baseName }) {
16+
return attempt === 0 ? baseName : `${baseName}_N${attempt + 1}`;
17+
},
18+
path: 'src/client',
19+
},
20+
};
21+
```
22+
23+
Example output:
24+
25+
```ts
26+
export type ChatCompletion = string;
27+
28+
export type ChatCompletion_N2 = number;
29+
```

.changeset/eight-rabbits-unite.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+
**output**: add `preferExportAll` option
6+
7+
### Prefer named exports
8+
9+
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.
10+
11+
While this change is merely cosmetic, you can set `output.preferExportAll` to `true` if you prefer to use the asterisk.
12+
13+
```js
14+
export default {
15+
input: 'hey-api/backend', // sign up at app.heyapi.dev
16+
output: {
17+
path: 'src/client',
18+
preferExportAll: true,
19+
},
20+
};
21+
```

.changeset/gentle-spoons-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/codegen-core': minor
3+
---
4+
5+
**symbols**: remove `placeholder` property

.changeset/plenty-walls-repeat.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@hey-api/openapi-ts': minor
3+
---
4+
5+
**parser**: removed `symbol:setValue:*` events
6+
7+
### Removed `symbol:setValue:*` events
8+
9+
These events have been removed in favor of `node:set:*` events.

.vscode/launch.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"skipFiles": ["<node_internals>/**"],
1616
"cwd": "${workspaceFolder}/dev",
1717
"runtimeExecutable": "node",
18-
"runtimeArgs": ["-r", "ts-node/register/transpile-only"],
19-
"program": "${workspaceFolder}/packages/openapi-ts/src/run.ts",
18+
"program": "${workspaceFolder}/packages/openapi-ts/dist/run.mjs",
2019
"env": {
2120
"DEBUG": "false"
2221
}

dev/openapi-ts.config.ts

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import path from 'node:path';
55
// @ts-ignore
66
import { customClientPlugin } from '@hey-api/custom-client/plugin';
77
// @ts-ignore
8-
import { defineConfig, utils } from '@hey-api/openapi-ts';
8+
import { defineConfig, reserved, utils } from '@hey-api/openapi-ts';
99

1010
// @ts-ignore
1111
import { myClientPlugin } from '../packages/openapi-ts-tests/main/test/custom/client/plugin';
1212
// @ts-ignore
1313
import { getSpecsPath } from '../packages/openapi-ts-tests/utils';
1414

15+
reserved.runtime.set((list) => [...list, 'Agent']);
16+
reserved.type.set((list) => [...list, 'Agent']);
17+
1518
// @ts-ignore
1619
export default defineConfig(() => {
1720
// ...
@@ -39,15 +42,19 @@ export default defineConfig(() => {
3942
'3.1.x',
4043
// 'circular.yaml',
4144
// 'dutchie.json',
45+
// 'enum-names-values.yaml',
4246
// 'invalid',
4347
// 'full.yaml',
48+
// 'sdk-method-class-conflict.yaml',
4449
// 'object-property-names.yaml',
45-
// 'openai.yaml',
46-
'opencode.yaml',
50+
'openai.yaml',
51+
// 'opencode.yaml',
4752
// 'pagination-ref.yaml',
4853
// 'sdk-instance.yaml',
54+
// 'sdk-nested-classes.yaml',
4955
// 'string-with-format.yaml',
5056
// 'transformers.json',
57+
// 'transformers-recursive.json',
5158
// 'type-format.yaml',
5259
// 'validators.yaml',
5360
// 'validators-circular-ref.json',
@@ -96,10 +103,21 @@ export default defineConfig(() => {
96103
// suffix: '.meh',
97104
// },
98105
// format: 'prettier',
99-
importFileExtension: '.ts',
106+
// importFileExtension: '.js',
100107
// indexFile: false,
101108
// lint: 'eslint',
109+
nameConflictResolver({ attempt, baseName }) {
110+
// console.log('resolving conflict for:', { attempt, baseName });
111+
return attempt === 0 ? baseName : `${baseName}_N${attempt + 1}`;
112+
},
102113
path: path.resolve(__dirname, '.gen'),
114+
// preferExportAll: true,
115+
resolveModuleName: (moduleName) => {
116+
if (moduleName === 'valibot') {
117+
return 'valibot';
118+
}
119+
return;
120+
},
103121
// tsConfigPath: path.resolve(
104122
// __dirname,
105123
// 'tsconfig',
@@ -128,6 +146,14 @@ export default defineConfig(() => {
128146
},
129147
hooks: {
130148
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+
// },
131157
// 'plugin:handler:after': ({ plugin }) => {
132158
// console.log(`(${plugin.name}): handler finished`);
133159
// },
@@ -153,12 +179,6 @@ export default defineConfig(() => {
153179
// );
154180
// }
155181
},
156-
// 'symbol:setValue:after': ({ plugin, symbol }) => {
157-
// console.log(`(${plugin.name}) set value:`, symbol.id);
158-
// },
159-
// 'symbol:setValue:before': ({ plugin, symbol }) => {
160-
// console.log(`(${plugin.name}) setting value:`, symbol.id);
161-
// },
162182
},
163183
operations: {
164184
getKind() {
@@ -236,6 +256,7 @@ export default defineConfig(() => {
236256
// error: '他們_error_{{name}}',
237257
// name: '你們_errors_{{name}}',
238258
// },
259+
// exportFromIndex: false,
239260
name: '@hey-api/typescript',
240261
// requests: '我們_data_{{name}}',
241262
// responses: {
@@ -261,10 +282,10 @@ export default defineConfig(() => {
261282
// fields.unwrap('path')
262283
// },
263284
// include...
264-
// instance: true,
285+
instance: true,
265286
name: '@hey-api/sdk',
266287
// operationId: false,
267-
paramsStructure: 'flat',
288+
// paramsStructure: 'flat',
268289
// responseStyle: 'data',
269290
// signature: 'auto',
270291
// signature: 'client',
@@ -305,16 +326,18 @@ export default defineConfig(() => {
305326
// case: 'SCREAMING_SNAKE_CASE',
306327
// comments: false,
307328
exportFromIndex: true,
308-
// infiniteQueryKeys: {
309-
// name: '{{name}}IQK',
310-
// },
329+
infiniteQueryKeys: {
330+
// name: '{{name}}IQK',
331+
// name: 'options',
332+
},
311333
infiniteQueryOptions: {
312334
meta() {
313335
return {
314336
custom: 'value',
315337
};
316338
},
317339
// name: '{{name}}IQO',
340+
// name: 'options',
318341
},
319342
mutationOptions: {
320343
meta() {
@@ -323,10 +346,12 @@ export default defineConfig(() => {
323346
};
324347
},
325348
// name: '{{name}}MO',
349+
// name: 'options',
326350
},
327351
name: '@tanstack/react-query',
328352
queryKeys: {
329353
// name: '{{name}}QK',
354+
// name: 'options',
330355
tags: true,
331356
},
332357
// queryOptions: false,
@@ -336,7 +361,8 @@ export default defineConfig(() => {
336361
// custom: 'value',
337362
// }
338363
// },
339-
name: '{{name}}QO',
364+
// name: '{{name}}QO',
365+
// name: 'options',
340366
},
341367
useQuery: true,
342368
'~hooks': {
@@ -365,18 +391,18 @@ export default defineConfig(() => {
365391
{
366392
// case: 'SCREAMING_SNAKE_CASE',
367393
// comments: false,
368-
// definitions: 'z{{name}}Definition',
394+
definitions: 'z{{name}}',
369395
exportFromIndex: true,
370396
// metadata: true,
371397
// name: 'valibot',
372398
// requests: {
373399
// case: 'PascalCase',
374400
// name: '{{name}}Data',
375401
// },
376-
// responses: {
377-
// // case: 'snake_case',
378-
// name: 'z{{name}}TestResponse',
379-
// },
402+
responses: {
403+
// case: 'snake_case',
404+
name: 'z{{name}}TestResponse',
405+
},
380406
// webhooks: {
381407
// name: 'q{{name}}CoolWebhook',
382408
// },
@@ -416,17 +442,23 @@ export default defineConfig(() => {
416442
// 'date-time': ({ $, pipes }) => pipes.push($('v').attr('isoDateTime').call()),
417443
},
418444
},
419-
validator({ $, schema, v }) {
420-
return [
421-
$.const('parsed').assign(
422-
$(v.placeholder)
423-
.attr('safeParseAsync')
424-
.call(schema.placeholder, 'data')
425-
.await(),
426-
),
427-
$('parsed').return(),
428-
];
429-
},
445+
// validator({ $, plugin, schema, v }) {
446+
// const vShadow = plugin.symbol('v');
447+
// const test = plugin.symbol('test');
448+
// const e = plugin.symbol('err');
449+
// return [
450+
// $.const(vShadow).assign($.literal('hi')),
451+
// $('console').attr('log').call(vShadow),
452+
// $.try(
453+
// $.const(test).assign($.literal('test')),
454+
// $('console').attr('log').call($.literal('hi'), test),
455+
// ).catchArg(e),
456+
// $.const('parsed').assign(
457+
// $(v).attr('safeParseAsync').call(schema, 'data').await(),
458+
// ),
459+
// $('parsed').return(),
460+
// ];
461+
// },
430462
},
431463
},
432464
{
@@ -443,7 +475,7 @@ export default defineConfig(() => {
443475
// infer: 'D{{name}}ZodType',
444476
// },
445477
},
446-
// exportFromIndex: true,
478+
exportFromIndex: true,
447479
metadata: true,
448480
// name: 'zod',
449481
// requests: {
@@ -496,17 +528,14 @@ export default defineConfig(() => {
496528
// 'date-time': ({ $ }) => $('z').attr('date').call(),
497529
},
498530
},
499-
validator({ $, schema }) {
500-
return [
501-
$.const('parsed').assign(
502-
$(schema.placeholder)
503-
.attr('safeParseAsync')
504-
.call('data')
505-
.await(),
506-
),
507-
$('parsed').return(),
508-
];
509-
},
531+
// validator({ $, schema }) {
532+
// return [
533+
// $.const('parsed').assign(
534+
// $(schema).attr('safeParseAsync').call('data').await(),
535+
// ),
536+
// $('parsed').return(),
537+
// ];
538+
// },
510539
},
511540
},
512541
{
@@ -527,7 +556,7 @@ export default defineConfig(() => {
527556
{
528557
exportFromIndex: true,
529558
// mutationOptions: '{{name}}Mutationssss',
530-
// name: '@pinia/colada',
559+
name: '@pinia/colada',
531560
// queryOptions: {
532561
// name: '{{name}}Queryyyyy',
533562
// },
@@ -546,7 +575,6 @@ export default defineConfig(() => {
546575
},
547576
},
548577
],
549-
// useOptions: false,
550578
// watch: 3_000,
551579
},
552580
// {

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ hero:
1515
text: Roadmap
1616
theme: alt
1717
image:
18-
alt: Two people looking at the blueprint
19-
src: /images/blueprint-640w.png
18+
alt: Two people looking at the TypeScript logo
19+
src: /images/hero-920w.png
2020

2121
features:
2222
- icon: <svg class="icon-openapi" width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 32"><path d="M8.96 18.397H.515l.005.123.014.238.007.102.022.275.006.061.033.304.003.03.043.327c.098.677.243 1.343.437 1.999l.003.008.1.326.006.018.093.276.025.07.087.24.04.107.078.2.06.149.065.154.086.188.05.114.105.225.035.072.126.256.02.039.154.293.033.057 7.235-4.366a5.754 5.754 0 0 1-.528-1.885ZM.914 22.27l.002.007.273-.085-.275.078ZM11.034 22.275l-5.97 5.967.092.085.255.227.203.172.055.045.232.187.03.024.255.196a.066.066 0 0 1 .01.007l1.113.752.04.024.219.13.134.076.128.072.232.126.032.017.658.32 3.213-7.805a5.719 5.719 0 0 1-.934-.623l.003.001ZM10.415 21.683l-.186-.219-.154-.199-.165-.233-.154-.241-7.22 4.349.371.584.03.044.002.003.388.547.009.011.008.011.176.229.21.261.045.055.173.203.076.087.15.171.084.092.039.042.114.12.046.047.2.204 5.956-5.956-.195-.209-.003-.003ZM18.31 22.272l-.2.154.016.025 4.342 7.209.594-.41c.42-.31.827-.645 1.22-1.007l-5.949-5.947-.023-.024ZM21.92 30.003l.01-.006-.01.006Zm-.005.003ZM21.929 29.994l.057-.028-.001-.002-.056.033v-.003Zm-.01.009-.002.001.002-.001ZM21.916 30.006l-.011-.018.01.018Zm.004-.003.01-.005-.01.005Z" fill="#fff"></path><path d="m21.837 29.719-4.2-6.97-.25.139-.256.128a5.756 5.756 0 0 1-4.106.319l-.27-.095-.27-.095-3.207 7.788.024.009.024.009.007.003.615.235a14.262 14.262 0 0 0 3.007.708l.349.038.056.005.28.023.095.006.245.014.15.006.195.007.348.004c.788 0 1.575-.066 2.352-.196l.04-.006.246-.045.143-.027.145-.03.24-.053.044-.01a14.241 14.241 0 0 0 3.398-1.267l.209-.115.424-.238-.007-.02.01.018.014-.008.056-.034-.15-.25Zm-10.8-16.335.2-.155-.015-.024-4.343-7.206-.595.41c-.42.31-.827.645-1.218 1.006l5.948 5.945.024.024ZM4.654 7.808l-.395.413c-.44.476-.841.971-1.203 1.491l-.052.075-.121.178-.123.188-.045.068a14.135 14.135 0 0 0-2.2 7.035l-.007.286-.005.285h8.424l.013-.285.016-.286a5.716 5.716 0 0 1 1.27-3.068c.058-.073.128-.142.192-.212.065-.07.124-.144.192-.212L4.654 7.808Zm17.38-2.09L22 5.695l-.224-.132-.13-.075-.132-.073-.228-.123-.036-.019a14.74 14.74 0 0 0-1.52-.686l-.04-.015-.342-.124a14.216 14.216 0 0 0-2.839-.673l-.118-.016-.119-.013-.228-.025-.064-.006-.273-.023-.342-.02-.124-.006v8.444c.433.045.862.138 1.279.279l6.216-6.211a13.96 13.96 0 0 0-.703-.461h.002ZM7.363 5.692l.147.244-.147-.244Zm0 0L7.36 5.69l.004.002Z" fill="#fff"></path><path d="m14.388 3.664-.285.005a14.24 14.24 0 0 0-1.78.184l-.04.007-.247.044-.143.027-.145.03-.24.053-.043.01a14.252 14.252 0 0 0-3.4 1.268l-.705.398v.001l4.349 7.219.25-.14a5.727 5.727 0 0 1 2.141-.657l.285-.022s.19-.01.286-.01V3.658c-.095 0-.19.003-.285.005h.002ZM28.827 17.131l-.014-.227-.007-.113-.022-.267-.006-.07-.032-.297-.002-.024-.002-.012-.043-.32-.001-.01a14.164 14.164 0 0 0-.436-1.992l-.003-.013-.094-.304-.013-.04-.091-.272-.026-.074-.086-.235-.043-.111-.075-.194-.063-.153-.063-.15-.083-.191-.049-.108-.107-.228-.033-.069-.128-.259-.018-.035-.149-.286c-.002-.003-.003-.007-.006-.01a14.217 14.217 0 0 0-.806-1.308l-6.217 6.218c.14.415.233.844.278 1.279h8.444l-.004-.125ZM20.42 17.828l-.013.285-.016.286a5.709 5.709 0 0 1-1.27 3.068c-.057.073-.128.142-.192.212s-.123.144-.191.212l5.956 5.956c.067-.068.13-.138.197-.206l.197-.207c.44-.477.843-.977 1.206-1.496l.043-.06.13-.193.113-.173.057-.084a14.13 14.13 0 0 0 2.196-7.03l.007-.285.005-.286H20.42Z" fill="#fff"></path></svg>

0 commit comments

Comments
 (0)