Skip to content

Commit 8f6d5df

Browse files
committed
chore: arktype plugin
1 parent ebc84f5 commit 8f6d5df

File tree

27 files changed

+1698
-903
lines changed

27 files changed

+1698
-903
lines changed

.changeset/poor-grapes-knock.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+
**plugin(zod)**: implement `getName()` symbol hook

.changeset/stupid-crabs-joke.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+
**plugin(valibot)**: implement `getName()` symbol hook

.changeset/swift-llamas-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/shared": patch
3+
---
4+
5+
**parser**: add `getName()` symbol hook

dev/typescript/presets.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ export const presets = {
6969
{
7070
metadata: true,
7171
name: 'zod',
72+
"~hooks": {
73+
symbols: {
74+
getName({ meta, name, schema }) {
75+
console.log(name, meta, schema);
76+
return name;
77+
},
78+
},
79+
},
7280
},
7381
],
7482
} as const satisfies Record<string, () => ReadonlyArray<PluginConfig>>;

packages/openapi-python/src/plugins/pydantic/shared/export.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Symbol } from '@hey-api/codegen-core';
2-
import { applyNaming, pathToName } from '@hey-api/shared';
2+
import { applyNaming, buildSymbolIn, pathToName } from '@hey-api/shared';
33

44
import { $ } from '../../../py-dsl';
55
import type { PydanticPlugin } from '../types';
@@ -15,20 +15,26 @@ export function exportAst({
1515
namingAnchor,
1616
path,
1717
plugin,
18+
schema,
1819
tags,
1920
}: ProcessorContext & {
2021
final: PydanticFinal;
2122
}): void {
2223
const name = pathToName(path, { anchor: namingAnchor });
23-
const symbol = plugin.symbol(applyNaming(name, naming), {
24-
meta: {
25-
category: 'schema',
26-
path,
27-
tags,
28-
tool: 'pydantic',
29-
...meta,
30-
},
31-
});
24+
const symbol = plugin.registerSymbol(
25+
buildSymbolIn({
26+
meta: {
27+
category: 'schema',
28+
path,
29+
tags,
30+
tool: 'pydantic',
31+
...meta,
32+
},
33+
name: applyNaming(name, naming),
34+
plugin,
35+
schema,
36+
}),
37+
);
3238

3339
if (final.enumMembers) {
3440
exportEnumClass({ final, plugin, symbol });

packages/openapi-ts/src/plugins/@hey-api/typescript/shared/clientOptions.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IR } from '@hey-api/shared';
2-
import { applyNaming, parseUrl } from '@hey-api/shared';
2+
import { applyNaming, buildSymbolIn, parseUrl } from '@hey-api/shared';
33

44
import { getTypedConfig } from '../../../../config/utils';
55
import {
@@ -45,18 +45,19 @@ export const createClientOptions = ({
4545
types.push($.type.and($.type('string'), $.type.object()));
4646
}
4747

48-
const symbol = plugin.symbol(
49-
applyNaming('ClientOptions', {
50-
case: plugin.config.case,
51-
}),
52-
{
48+
const symbol = plugin.registerSymbol(
49+
buildSymbolIn({
5350
meta: {
5451
category: 'type',
5552
resource: 'client',
5653
role: 'options',
5754
tool: 'typescript',
5855
},
59-
},
56+
name: applyNaming('ClientOptions', {
57+
case: plugin.config.case,
58+
}),
59+
plugin,
60+
}),
6061
);
6162

6263
const node = $.type

packages/openapi-ts/src/plugins/@hey-api/typescript/shared/export.ts

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IR } from '@hey-api/shared';
2-
import { applyNaming, pathToName, toCase } from '@hey-api/shared';
2+
import { applyNaming, buildSymbolIn, pathToName, toCase } from '@hey-api/shared';
33
import { pathToJsonPointer } from '@hey-api/shared';
44

55
import { createSchemaComment } from '../../../../plugins/shared/utils/schema';
@@ -98,14 +98,19 @@ function buildEnumExport({
9898
? items.filter((item) => item.schema.const !== null)
9999
: items;
100100

101-
const symbolObject = plugin.symbol(applyNaming(name, plugin.config.definitions), {
102-
meta: {
103-
category: 'utility',
104-
resource: 'definition',
105-
resourceId,
106-
tool: 'typescript',
107-
},
108-
});
101+
const symbolObject = plugin.registerSymbol(
102+
buildSymbolIn({
103+
meta: {
104+
category: 'utility',
105+
resource: 'definition',
106+
resourceId,
107+
tool: 'typescript',
108+
},
109+
name: applyNaming(name, plugin.config.definitions),
110+
plugin,
111+
schema,
112+
}),
113+
);
109114

110115
const objectNode = $.const(symbolObject)
111116
.export()
@@ -126,14 +131,19 @@ function buildEnumExport({
126131
);
127132
plugin.node(objectNode);
128133

129-
const symbol = plugin.symbol(applyNaming(name, plugin.config.definitions), {
130-
meta: {
131-
category: 'type',
132-
resource: 'definition',
133-
resourceId,
134-
tool: 'typescript',
135-
},
136-
});
134+
const symbol = plugin.registerSymbol(
135+
buildSymbolIn({
136+
meta: {
137+
category: 'type',
138+
resource: 'definition',
139+
resourceId,
140+
tool: 'typescript',
141+
},
142+
name: applyNaming(name, plugin.config.definitions),
143+
plugin,
144+
schema,
145+
}),
146+
);
137147
const node = $.type
138148
.alias(symbol)
139149
.export()
@@ -149,14 +159,19 @@ function buildEnumExport({
149159
);
150160
if (hasInvalidTypes) return false;
151161

152-
const symbol = plugin.symbol(applyNaming(name, plugin.config.definitions), {
153-
meta: {
154-
category: 'type',
155-
resource: 'definition',
156-
resourceId,
157-
tool: 'typescript',
158-
},
159-
});
162+
const symbol = plugin.registerSymbol(
163+
buildSymbolIn({
164+
meta: {
165+
category: 'type',
166+
resource: 'definition',
167+
resourceId,
168+
tool: 'typescript',
169+
},
170+
name: applyNaming(name, plugin.config.definitions),
171+
plugin,
172+
schema,
173+
}),
174+
);
160175
const enumNode = $.enum(symbol)
161176
.export()
162177
.$if(plugin.config.comments && createSchemaComment(schema), (e, v) => e.doc(v))
@@ -203,16 +218,21 @@ export function exportAst({
203218
return;
204219
}
205220

206-
const symbol = plugin.symbol(applyNaming(name, naming), {
207-
meta: {
208-
category: 'type',
209-
path,
210-
resource: 'definition',
211-
resourceId: $ref,
212-
tags,
213-
tool: 'typescript',
214-
},
215-
});
221+
const symbol = plugin.registerSymbol(
222+
buildSymbolIn({
223+
meta: {
224+
category: 'type',
225+
path,
226+
resource: 'definition',
227+
resourceId: $ref,
228+
tags,
229+
tool: 'typescript',
230+
},
231+
name: applyNaming(name, naming),
232+
plugin,
233+
schema,
234+
}),
235+
);
216236

217237
const node = $.type
218238
.alias(symbol)

0 commit comments

Comments
 (0)