Skip to content

Commit 769ea6a

Browse files
committed
chore: arktype plugin
1 parent ebc84f5 commit 769ea6a

File tree

12 files changed

+276
-161
lines changed

12 files changed

+276
-161
lines changed

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)

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

Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { IR } from '@hey-api/shared';
2-
import { applyNaming } from '@hey-api/shared';
3-
import { operationResponsesMap } from '@hey-api/shared';
4-
import { deduplicateSchema } from '@hey-api/shared';
2+
import {
3+
applyNaming,
4+
buildSymbolIn,
5+
deduplicateSchema,
6+
operationResponsesMap,
7+
} from '@hey-api/shared';
58

69
import { $ } from '../../../../ts-dsl';
710
import type { HeyApiTypeScriptPlugin } from '../types';
@@ -117,17 +120,22 @@ export const operationToType = ({
117120
schema: data,
118121
});
119122

120-
const dataSymbol = plugin.symbol(applyNaming(operation.id, plugin.config.requests), {
121-
meta: {
122-
category: 'type',
123-
path,
124-
resource: 'operation',
125-
resourceId: operation.id,
126-
role: 'data',
127-
tags,
128-
tool: 'typescript',
129-
},
130-
});
123+
const dataSymbol = plugin.registerSymbol(
124+
buildSymbolIn({
125+
meta: {
126+
category: 'type',
127+
path,
128+
resource: 'operation',
129+
resourceId: operation.id,
130+
role: 'data',
131+
tags,
132+
tool: 'typescript',
133+
},
134+
name: applyNaming(operation.id, plugin.config.requests),
135+
operation,
136+
plugin,
137+
}),
138+
);
131139
const dataNode = $.type
132140
.alias(dataSymbol)
133141
.export()
@@ -149,30 +157,31 @@ export const operationToType = ({
149157
schema: errors,
150158
});
151159

152-
const errorsSymbol = plugin.symbol(applyNaming(operation.id, plugin.config.errors), {
153-
meta: {
154-
category: 'type',
155-
path,
156-
resource: 'operation',
157-
resourceId: operation.id,
158-
role: 'errors',
159-
tags,
160-
tool: 'typescript',
161-
},
162-
});
160+
const errorsSymbol = plugin.registerSymbol(
161+
buildSymbolIn({
162+
meta: {
163+
category: 'type',
164+
path,
165+
resource: 'operation',
166+
resourceId: operation.id,
167+
role: 'errors',
168+
tags,
169+
tool: 'typescript',
170+
},
171+
name: applyNaming(operation.id, plugin.config.errors),
172+
operation,
173+
plugin,
174+
}),
175+
);
163176
const errorsNode = $.type
164177
.alias(errorsSymbol)
165178
.export()
166179
.type(errorsResult?.type ?? $.type('never'));
167180
plugin.node(errorsNode);
168181

169182
if (error) {
170-
const errorSymbol = plugin.symbol(
171-
applyNaming(operation.id, {
172-
case: plugin.config.errors.case,
173-
name: plugin.config.errors.error,
174-
}),
175-
{
183+
const errorSymbol = plugin.registerSymbol(
184+
buildSymbolIn({
176185
meta: {
177186
category: 'type',
178187
path,
@@ -182,7 +191,13 @@ export const operationToType = ({
182191
tags,
183192
tool: 'typescript',
184193
},
185-
},
194+
name: applyNaming(operation.id, {
195+
case: plugin.config.errors.case,
196+
name: plugin.config.errors.error,
197+
}),
198+
operation,
199+
plugin,
200+
}),
186201
);
187202
const errorNode = $.type
188203
.alias(errorSymbol)
@@ -205,30 +220,31 @@ export const operationToType = ({
205220
schema: responses,
206221
});
207222

208-
const responsesSymbol = plugin.symbol(applyNaming(operation.id, plugin.config.responses), {
209-
meta: {
210-
category: 'type',
211-
path,
212-
resource: 'operation',
213-
resourceId: operation.id,
214-
role: 'responses',
215-
tags,
216-
tool: 'typescript',
217-
},
218-
});
223+
const responsesSymbol = plugin.registerSymbol(
224+
buildSymbolIn({
225+
meta: {
226+
category: 'type',
227+
path,
228+
resource: 'operation',
229+
resourceId: operation.id,
230+
role: 'responses',
231+
tags,
232+
tool: 'typescript',
233+
},
234+
name: applyNaming(operation.id, plugin.config.responses),
235+
operation,
236+
plugin,
237+
}),
238+
);
219239
const responsesNode = $.type
220240
.alias(responsesSymbol)
221241
.export()
222242
.type(responsesResult?.type ?? $.type('never'));
223243
plugin.node(responsesNode);
224244

225245
if (response) {
226-
const responseSymbol = plugin.symbol(
227-
applyNaming(operation.id, {
228-
case: plugin.config.responses.case,
229-
name: plugin.config.responses.response,
230-
}),
231-
{
246+
const responseSymbol = plugin.registerSymbol(
247+
buildSymbolIn({
232248
meta: {
233249
category: 'type',
234250
path,
@@ -238,7 +254,13 @@ export const operationToType = ({
238254
tags,
239255
tool: 'typescript',
240256
},
241-
},
257+
name: applyNaming(operation.id, {
258+
case: plugin.config.responses.case,
259+
name: plugin.config.responses.response,
260+
}),
261+
operation,
262+
plugin,
263+
}),
242264
);
243265
const responseNode = $.type
244266
.alias(responseSymbol)

0 commit comments

Comments
 (0)