Skip to content

Commit 0b34586

Browse files
committed
chore: symbol ref
1 parent 944f14c commit 0b34586

Some content is hidden

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

94 files changed

+490
-413
lines changed

dev/openapi-ts.config.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default defineConfig(() => {
4141
// 'dutchie.json',
4242
// 'enum-names-values.yaml',
4343
// 'invalid',
44-
'full.yaml',
44+
// 'full.yaml',
4545
// 'object-property-names.yaml',
4646
// 'openai.yaml',
4747
// 'opencode.yaml',
@@ -53,7 +53,7 @@ export default defineConfig(() => {
5353
// 'validators.yaml',
5454
// 'validators-circular-ref.json',
5555
// 'validators-circular-ref-2.yaml',
56-
// 'zoom-video-sdk.json',
56+
'zoom-video-sdk.json',
5757
),
5858
// path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0',
5959
// path: 'http://localhost:4000/',
@@ -83,7 +83,7 @@ export default defineConfig(() => {
8383
// 'https://somefakedomain.com/openapi.yaml',
8484
],
8585
logs: {
86-
level: 'silent',
86+
// level: 'silent',
8787
path: './logs',
8888
},
8989
// name: 'foo',
@@ -263,7 +263,7 @@ export default defineConfig(() => {
263263
// },
264264
// include...
265265
// instance: true,
266-
name: '@hey-api/sdk',
266+
// name: '@hey-api/sdk',
267267
// operationId: false,
268268
// paramsStructure: 'flat',
269269
// responseStyle: 'data',
@@ -328,7 +328,7 @@ export default defineConfig(() => {
328328
// name: '{{name}}MO',
329329
name: 'options',
330330
},
331-
name: '@tanstack/react-query',
331+
// name: '@tanstack/react-query',
332332
queryKeys: {
333333
// name: '{{name}}QK',
334334
name: 'options',
@@ -374,7 +374,7 @@ export default defineConfig(() => {
374374
// definitions: 'z{{name}}Definition',
375375
exportFromIndex: true,
376376
// metadata: true,
377-
name: 'valibot',
377+
// name: 'valibot',
378378
// requests: {
379379
// case: 'PascalCase',
380380
// name: '{{name}}Data',
@@ -451,7 +451,7 @@ export default defineConfig(() => {
451451
},
452452
// exportFromIndex: true,
453453
metadata: true,
454-
name: 'zod',
454+
// name: 'zod',
455455
// requests: {
456456
// // case: 'SCREAMING_SNAKE_CASE',
457457
// // name: 'z{{name}}TestData',
@@ -528,7 +528,7 @@ export default defineConfig(() => {
528528
httpResources: {
529529
asClass: true,
530530
},
531-
name: '@angular/common',
531+
// name: '@angular/common',
532532
},
533533
{
534534
exportFromIndex: true,

packages/codegen-core/src/debug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export function debug(message: string, group: keyof typeof DEBUG_GROUPS) {
1414
const value = process.env.DEBUG;
1515
if (!value) return;
1616

17-
const groups = value.split(",").map(x => x.trim().toLowerCase());
17+
const groups = value.split(',').map((x) => x.trim().toLowerCase());
1818

1919
if (
2020
!(
21-
groups.includes("*") ||
22-
groups.includes("heyapi:*") ||
21+
groups.includes('*') ||
22+
groups.includes('heyapi:*') ||
2323
groups.includes(`heyapi:${group}`) ||
2424
groups.includes(group)
2525
)

packages/codegen-core/src/symbols/symbol.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class Symbol {
8484
*/
8585
private _name: string;
8686
/**
87-
* Root DSL node that defines this symbol.
87+
* Root node that defines this symbol.
8888
*
8989
* @private
9090
*/
@@ -311,14 +311,14 @@ export class Symbol {
311311
}
312312

313313
/**
314-
* Binds the DSL node that defines this symbol.
314+
* Binds the node that defines this symbol.
315315
*
316316
* This may only be set once.
317317
*/
318318
setRootNode(node: ISyntaxNode): void {
319319
this.assertCanonical();
320320
if (this._rootNode && this._rootNode !== node) {
321-
throw new Error('Symbol is already bound to a different root DSL node.');
321+
throw new Error('Symbol is already bound to a different root node.');
322322
}
323323
this._rootNode = node;
324324
}
@@ -344,7 +344,7 @@ export class Symbol {
344344
private assertCanonical(): void {
345345
if (this._canonical && this._canonical !== this) {
346346
const message = `Illegal mutation of stub symbol ${this.toString()} → canonical: ${this._canonical.toString()}`;
347-
debug(message, "symbol");
347+
debug(message, 'symbol');
348348
throw new Error(message);
349349
}
350350
}

packages/codegen-core/src/syntax-node.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { Symbol } from './symbols/symbol';
22

33
export interface ISyntaxNode {
44
/**
5-
* Return local names introduced by this node.
5+
* Collect symbols referenced directly by this node into the provided accumulator.
66
*/
7-
getLocalNames(): Iterable<string>;
7+
collectSymbols(out: Set<Symbol>): void;
88
/**
9-
* Return symbols referenced directly by this node.
9+
* Return local names introduced by this node.
1010
*/
11-
getSymbols(): Iterable<Symbol>;
11+
getLocalNames(): Iterable<string>;
1212
/**
1313
* Rewrite local identifiers based on a rename map.
1414
*/

packages/openapi-ts/src/ir/types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Symbol } from '@hey-api/codegen-core';
2+
13
import type { JsonSchemaDraft2020_12 } from '~/openApi/3.1.x/types/json-schema-draft-2020-12';
24
import type {
35
SecuritySchemeObject,
@@ -185,6 +187,10 @@ interface IRSchemaObject
185187
* follow a specific convention.
186188
*/
187189
propertyNames?: IRSchemaObject;
190+
/**
191+
* Reference to symbol instead of `$ref` string.
192+
*/
193+
symbolRef?: Symbol;
188194
/**
189195
* Each schema eventually resolves into `type`.
190196
*/

packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ export const createClientConfigType = ({
4949
p
5050
.optional()
5151
.type(
52-
$.type(symbolConfig.placeholder).generic(
52+
$.type(symbolConfig).generic(
5353
$.type.and(symbolDefaultClientOptions.placeholder, 'T'),
5454
),
5555
),
5656
)
5757
.returns(
58-
$.type(symbolConfig.placeholder).generic(
58+
$.type(symbolConfig).generic(
5959
$.type.and(
6060
$.type('Required').generic(
6161
symbolDefaultClientOptions.placeholder,

packages/openapi-ts/src/plugins/@hey-api/sdk/shared/typeOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const createTypeOptions = ({
8080
)
8181
.type(
8282
$.type.and(
83-
$.type(symbolClientOptions.placeholder).$if(
83+
$.type(symbolClientOptions).$if(
8484
isNuxtClient,
8585
(t) =>
8686
t

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ export const operationToType = ({
210210
const node = $.type
211211
.alias(symbol)
212212
.export()
213-
.type(
214-
$.type(symbolErrors.placeholder).idx(
215-
$.type(symbolErrors.placeholder).keyof(),
216-
),
217-
);
213+
.type($.type(symbolErrors).idx($.type(symbolErrors).keyof()));
218214
plugin.setSymbolValue(symbol, node);
219215
}
220216
}
@@ -269,11 +265,7 @@ export const operationToType = ({
269265
const node = $.type
270266
.alias(symbol)
271267
.export()
272-
.type(
273-
$.type(symbolResponses.placeholder).idx(
274-
$.type(symbolResponses.placeholder).keyof(),
275-
),
276-
);
268+
.type($.type(symbolResponses).idx($.type(symbolResponses).keyof()));
277269
plugin.setSymbolValue(symbol, node);
278270
}
279271
}

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Symbol } from '@hey-api/codegen-core';
2+
13
import type { IR } from '~/ir/types';
24
import { buildName } from '~/openApi/shared/utils/name';
35
import { createSchemaComment } from '~/plugins/shared/utils/schema';
@@ -12,7 +14,7 @@ const operationToDataType = ({
1214
state,
1315
}: IrSchemaToAstOptions & {
1416
operation: IR.OperationObject;
15-
}): string => {
17+
}): Symbol => {
1618
const data: IR.SchemaObject = {
1719
type: 'object',
1820
};
@@ -54,21 +56,7 @@ const operationToDataType = ({
5456
);
5557
plugin.setSymbolValue(symbolWebhookPayload, node);
5658

57-
plugin.registerSymbol({
58-
exported: true,
59-
kind: 'type',
60-
meta: {
61-
category: 'type',
62-
path: state.path.value,
63-
resource: 'definition',
64-
resourceId: symbolWebhookPayload.placeholder,
65-
tags: state.tags?.value,
66-
tool: 'typescript',
67-
},
68-
name: symbolWebhookPayload.name,
69-
placeholder: symbolWebhookPayload.placeholder,
70-
});
71-
data.properties.body = { $ref: symbolWebhookPayload.placeholder };
59+
data.properties.body = { symbolRef: symbolWebhookPayload };
7260
dataRequired.push('body');
7361
} else {
7462
data.properties.body = { type: 'never' };
@@ -112,7 +100,7 @@ const operationToDataType = ({
112100
);
113101
plugin.setSymbolValue(symbolWebhookRequest, node);
114102

115-
return symbolWebhookRequest.placeholder;
103+
return symbolWebhookRequest;
116104
};
117105

118106
export const webhookToType = ({
@@ -121,9 +109,9 @@ export const webhookToType = ({
121109
state,
122110
}: IrSchemaToAstOptions & {
123111
operation: IR.OperationObject;
124-
}): string => {
125-
const name = operationToDataType({ operation, plugin, state });
126-
return name;
112+
}): Symbol => {
113+
const symbol = operationToDataType({ operation, plugin, state });
114+
return symbol;
127115

128116
// don't handle webhook responses for now, users only need requestBody
129117
};

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)