From 2b253c05a9f0981a71eec1269593b9266185b77c Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 23 Nov 2025 09:07:51 +0800 Subject: [PATCH] feat: canonical symbols --- dev/openapi-ts.config.ts | 15 +- docs/package.json | 2 +- docs/scripts/optimize-images.js | 13 + .../openapi-ts-openai/src/client/types.gen.ts | 122 +++---- .../codegen-core/src/__tests__/bimap.test.ts | 13 +- .../codegen-core/src/__tests__/files.test.ts | 2 + .../src/__tests__/symbols.test.ts | 67 ++-- packages/codegen-core/src/bimap/bimap.ts | 28 +- packages/codegen-core/src/bimap/types.d.ts | 4 +- packages/codegen-core/src/bindings/utils.ts | 10 +- .../types.d.ts => extensions.d.ts} | 0 packages/codegen-core/src/files/registry.ts | 1 + packages/codegen-core/src/files/types.d.ts | 4 + packages/codegen-core/src/index.ts | 7 +- .../src/{output/types.d.ts => output.d.ts} | 0 packages/codegen-core/src/project/project.ts | 8 +- packages/codegen-core/src/project/types.d.ts | 4 +- packages/codegen-core/src/renderer/types.d.ts | 2 +- packages/codegen-core/src/symbols/registry.ts | 46 +-- packages/codegen-core/src/symbols/symbol.ts | 316 ++++++++++++++++++ packages/codegen-core/src/symbols/types.d.ts | 46 +-- packages/codegen-core/src/syntax-node.d.ts | 20 ++ packages/codegen-core/tsconfig.base.json | 2 + packages/codegen-core/tsconfig.json | 1 - .../plugins/valibot/default/valibot.gen.ts | 2 +- .../plugins/valibot/default/valibot.gen.ts | 2 +- .../3.0.x/validators/valibot.gen.ts | 4 +- .../plugins/valibot/default/valibot.gen.ts | 2 +- .../validators-circular-ref-2/valibot.gen.ts | 2 +- .../validators-circular-ref/valibot.gen.ts | 4 +- .../3.1.x/validators-metadata/valibot.gen.ts | 4 +- .../3.1.x/validators-types/valibot.gen.ts | 4 +- .../3.1.x/validators/valibot.gen.ts | 4 +- .../method-class-conflict/class/sdk.gen.ts | 38 +-- .../2.0.x/mini/default/zod.gen.ts | 2 +- .../__snapshots__/2.0.x/v3/default/zod.gen.ts | 2 +- .../__snapshots__/2.0.x/v4/default/zod.gen.ts | 2 +- .../3.0.x/mini/circular/zod.gen.ts | 10 +- .../3.0.x/mini/default/zod.gen.ts | 2 +- .../3.0.x/mini/validators/zod.gen.ts | 4 +- .../3.0.x/v3/circular/zod.gen.ts | 10 +- .../__snapshots__/3.0.x/v3/default/zod.gen.ts | 2 +- .../3.0.x/v3/validators/zod.gen.ts | 4 +- .../3.0.x/v4/circular/zod.gen.ts | 10 +- .../__snapshots__/3.0.x/v4/default/zod.gen.ts | 2 +- .../3.0.x/v4/validators/zod.gen.ts | 4 +- .../3.1.x/mini/default/zod.gen.ts | 2 +- .../mini/validators-circular-ref-2/zod.gen.ts | 2 +- .../mini/validators-circular-ref/zod.gen.ts | 4 +- .../3.1.x/mini/validators-dates/zod.gen.ts | 4 +- .../3.1.x/mini/validators-metadata/zod.gen.ts | 4 +- .../3.1.x/mini/validators-types/zod.gen.ts | 4 +- .../3.1.x/mini/validators/zod.gen.ts | 4 +- .../__snapshots__/3.1.x/v3/default/zod.gen.ts | 2 +- .../v3/validators-circular-ref-2/zod.gen.ts | 2 +- .../v3/validators-circular-ref/zod.gen.ts | 4 +- .../3.1.x/v3/validators-dates/zod.gen.ts | 4 +- .../3.1.x/v3/validators-metadata/zod.gen.ts | 4 +- .../3.1.x/v3/validators-types/zod.gen.ts | 4 +- .../3.1.x/v3/validators/zod.gen.ts | 4 +- .../__snapshots__/3.1.x/v4/default/zod.gen.ts | 2 +- .../v4/validators-circular-ref-2/zod.gen.ts | 2 +- .../v4/validators-circular-ref/zod.gen.ts | 4 +- .../3.1.x/v4/validators-dates/zod.gen.ts | 4 +- .../3.1.x/v4/validators-metadata/zod.gen.ts | 4 +- .../3.1.x/v4/validators-types/zod.gen.ts | 4 +- .../3.1.x/v4/validators/zod.gen.ts | 4 +- .../2.0.x/mini/default/zod.gen.ts | 2 +- .../__snapshots__/2.0.x/v3/default/zod.gen.ts | 2 +- .../__snapshots__/2.0.x/v4/default/zod.gen.ts | 2 +- .../3.0.x/mini/circular/zod.gen.ts | 10 +- .../3.0.x/mini/default/zod.gen.ts | 2 +- .../3.0.x/mini/validators/zod.gen.ts | 4 +- .../3.0.x/v3/circular/zod.gen.ts | 10 +- .../__snapshots__/3.0.x/v3/default/zod.gen.ts | 2 +- .../3.0.x/v3/validators/zod.gen.ts | 4 +- .../3.0.x/v4/circular/zod.gen.ts | 10 +- .../__snapshots__/3.0.x/v4/default/zod.gen.ts | 2 +- .../3.0.x/v4/validators/zod.gen.ts | 4 +- .../3.1.x/mini/default/zod.gen.ts | 2 +- .../mini/validators-circular-ref-2/zod.gen.ts | 2 +- .../mini/validators-circular-ref/zod.gen.ts | 4 +- .../3.1.x/mini/validators-dates/zod.gen.ts | 4 +- .../3.1.x/mini/validators-metadata/zod.gen.ts | 4 +- .../3.1.x/mini/validators-types/zod.gen.ts | 4 +- .../3.1.x/mini/validators/zod.gen.ts | 4 +- .../__snapshots__/3.1.x/v3/default/zod.gen.ts | 2 +- .../v3/validators-circular-ref-2/zod.gen.ts | 2 +- .../v3/validators-circular-ref/zod.gen.ts | 4 +- .../3.1.x/v3/validators-dates/zod.gen.ts | 4 +- .../3.1.x/v3/validators-metadata/zod.gen.ts | 4 +- .../3.1.x/v3/validators-types/zod.gen.ts | 4 +- .../3.1.x/v3/validators/zod.gen.ts | 4 +- .../__snapshots__/3.1.x/v4/default/zod.gen.ts | 2 +- .../v4/validators-circular-ref-2/zod.gen.ts | 2 +- .../v4/validators-circular-ref/zod.gen.ts | 4 +- .../3.1.x/v4/validators-dates/zod.gen.ts | 4 +- .../3.1.x/v4/validators-metadata/zod.gen.ts | 4 +- .../3.1.x/v4/validators-types/zod.gen.ts | 4 +- .../3.1.x/v4/validators/zod.gen.ts | 4 +- .../src/generate/__tests__/renderer.test.ts | 6 +- packages/openapi-ts/src/generate/renderer.ts | 70 ++-- .../plugins/@angular/common/httpRequests.ts | 22 +- .../plugins/@angular/common/httpResources.ts | 12 +- .../plugins/@hey-api/client-core/client.ts | 5 +- .../client-core/createClientConfig.ts | 6 +- .../src/plugins/@hey-api/schemas/plugin.ts | 15 +- .../src/plugins/@hey-api/sdk/shared/class.ts | 20 +- .../plugins/@hey-api/sdk/shared/functions.ts | 5 +- .../@hey-api/sdk/shared/typeOptions.ts | 6 +- .../plugins/@hey-api/transformers/plugin.ts | 5 +- .../typescript/shared/clientOptions.ts | 4 +- .../@hey-api/typescript/shared/export.ts | 88 ++++- .../@hey-api/typescript/shared/operation.ts | 30 +- .../@hey-api/typescript/shared/webhook.ts | 12 +- .../@hey-api/typescript/shared/webhooks.ts | 4 +- .../plugins/@hey-api/typescript/v1/plugin.ts | 30 +- .../@hey-api/typescript/v1/toAst/string.ts | 12 +- .../plugins/@pinia/colada/mutationOptions.ts | 5 +- .../src/plugins/@pinia/colada/queryKey.ts | 12 +- .../src/plugins/@pinia/colada/queryOptions.ts | 6 +- .../plugins/@tanstack/query-core/queryKey.ts | 12 +- .../query-core/v5/infiniteQueryOptions.ts | 8 +- .../query-core/v5/mutationOptions.ts | 5 +- .../@tanstack/query-core/v5/queryOptions.ts | 6 +- .../@tanstack/query-core/v5/useQuery.ts | 5 +- .../src/plugins/arktype/shared/export.ts | 8 +- .../src/plugins/arktype/v2/plugin.ts | 3 - .../openapi-ts/src/plugins/fastify/plugin.ts | 7 +- .../openapi-ts/src/plugins/swr/v2/useSwr.ts | 5 +- .../src/plugins/valibot/shared/export.ts | 4 +- .../src/plugins/valibot/shared/operation.ts | 2 - .../src/plugins/valibot/shared/webhook.ts | 1 - .../src/plugins/valibot/v1/plugin.ts | 1 - .../openapi-ts/src/plugins/zod/mini/plugin.ts | 3 - .../src/plugins/zod/shared/export.ts | 8 +- .../src/plugins/zod/shared/operation.ts | 6 - .../src/plugins/zod/shared/webhook.ts | 3 - .../openapi-ts/src/plugins/zod/v3/plugin.ts | 3 - .../openapi-ts/src/plugins/zod/v4/plugin.ts | 3 - packages/openapi-ts/src/ts-dsl/base.ts | 56 +++- packages/openapi-ts/src/ts-dsl/decl/class.ts | 67 ++-- .../openapi-ts/src/ts-dsl/decl/decorator.ts | 27 +- packages/openapi-ts/src/ts-dsl/decl/enum.ts | 17 +- packages/openapi-ts/src/ts-dsl/decl/field.ts | 6 + packages/openapi-ts/src/ts-dsl/decl/func.ts | 31 +- packages/openapi-ts/src/ts-dsl/decl/getter.ts | 6 + packages/openapi-ts/src/ts-dsl/decl/init.ts | 6 + packages/openapi-ts/src/ts-dsl/decl/member.ts | 6 + packages/openapi-ts/src/ts-dsl/decl/method.ts | 6 + packages/openapi-ts/src/ts-dsl/decl/param.ts | 6 + .../openapi-ts/src/ts-dsl/decl/pattern.ts | 6 + packages/openapi-ts/src/ts-dsl/decl/setter.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/array.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/as.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/attr.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/await.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/binary.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/call.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/expr.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/id.ts | 6 + .../openapi-ts/src/ts-dsl/expr/literal.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/new.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/object.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/prefix.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/prop.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/regexp.ts | 6 + .../openapi-ts/src/ts-dsl/expr/template.ts | 6 + .../openapi-ts/src/ts-dsl/expr/ternary.ts | 6 + packages/openapi-ts/src/ts-dsl/expr/typeof.ts | 6 + packages/openapi-ts/src/ts-dsl/layout/doc.ts | 6 + packages/openapi-ts/src/ts-dsl/layout/hint.ts | 6 + .../openapi-ts/src/ts-dsl/layout/newline.ts | 6 + packages/openapi-ts/src/ts-dsl/layout/note.ts | 6 + .../openapi-ts/src/ts-dsl/mixins/apply.ts | 1 - packages/openapi-ts/src/ts-dsl/mixins/args.ts | 6 +- .../openapi-ts/src/ts-dsl/mixins/decorator.ts | 13 +- packages/openapi-ts/src/ts-dsl/mixins/do.ts | 6 +- packages/openapi-ts/src/ts-dsl/mixins/doc.ts | 9 +- packages/openapi-ts/src/ts-dsl/mixins/hint.ts | 9 +- .../openapi-ts/src/ts-dsl/mixins/modifiers.ts | 71 ++-- packages/openapi-ts/src/ts-dsl/mixins/note.ts | 9 +- .../openapi-ts/src/ts-dsl/mixins/param.ts | 6 +- .../openapi-ts/src/ts-dsl/mixins/pattern.ts | 6 +- .../openapi-ts/src/ts-dsl/mixins/type-args.ts | 6 +- .../src/ts-dsl/mixins/type-params.ts | 6 +- .../openapi-ts/src/ts-dsl/mixins/value.ts | 6 +- packages/openapi-ts/src/ts-dsl/stmt/if.ts | 6 + packages/openapi-ts/src/ts-dsl/stmt/return.ts | 6 + packages/openapi-ts/src/ts-dsl/stmt/stmt.ts | 6 + packages/openapi-ts/src/ts-dsl/stmt/throw.ts | 6 + packages/openapi-ts/src/ts-dsl/stmt/var.ts | 19 +- packages/openapi-ts/src/ts-dsl/token.ts | 6 + packages/openapi-ts/src/ts-dsl/type/alias.ts | 19 +- packages/openapi-ts/src/ts-dsl/type/and.ts | 6 + packages/openapi-ts/src/ts-dsl/type/attr.ts | 30 +- packages/openapi-ts/src/ts-dsl/type/expr.ts | 41 ++- packages/openapi-ts/src/ts-dsl/type/func.ts | 6 + .../openapi-ts/src/ts-dsl/type/idx-sig.ts | 6 + packages/openapi-ts/src/ts-dsl/type/idx.ts | 6 + .../openapi-ts/src/ts-dsl/type/literal.ts | 6 + packages/openapi-ts/src/ts-dsl/type/mapped.ts | 6 + packages/openapi-ts/src/ts-dsl/type/object.ts | 6 + .../openapi-ts/src/ts-dsl/type/operator.ts | 6 + packages/openapi-ts/src/ts-dsl/type/or.ts | 6 + packages/openapi-ts/src/ts-dsl/type/param.ts | 6 + packages/openapi-ts/src/ts-dsl/type/prop.ts | 6 + packages/openapi-ts/src/ts-dsl/type/query.ts | 6 + .../openapi-ts/src/ts-dsl/type/template.ts | 6 + packages/openapi-ts/src/ts-dsl/type/tuple.ts | 6 + 210 files changed, 1523 insertions(+), 745 deletions(-) rename packages/codegen-core/src/{extensions/types.d.ts => extensions.d.ts} (100%) rename packages/codegen-core/src/{output/types.d.ts => output.d.ts} (100%) create mode 100644 packages/codegen-core/src/symbols/symbol.ts create mode 100644 packages/codegen-core/src/syntax-node.d.ts diff --git a/dev/openapi-ts.config.ts b/dev/openapi-ts.config.ts index d22b6b933..9f2aaffb2 100644 --- a/dev/openapi-ts.config.ts +++ b/dev/openapi-ts.config.ts @@ -39,8 +39,9 @@ export default defineConfig(() => { '3.1.x', // 'circular.yaml', // 'dutchie.json', + 'enum-names-values.yaml', // 'invalid', - 'full.yaml', + // 'full.yaml', // 'object-property-names.yaml', // 'openai.yaml', // 'opencode.yaml', @@ -217,7 +218,7 @@ export default defineConfig(() => { { // baseUrl: false, // exportFromIndex: true, - name: '@hey-api/client-angular', + // name: '@hey-api/client-angular', // runtimeConfigPath: path.resolve(__dirname, 'hey-api.ts'), // runtimeConfigPath: './src/hey-api.ts', // strictBaseUrl: true, @@ -265,7 +266,7 @@ export default defineConfig(() => { name: '@hey-api/sdk', // operationId: false, // paramsStructure: 'flat', - responseStyle: 'data', + // responseStyle: 'data', // signature: 'auto', // signature: 'client', // signature: 'object', @@ -293,13 +294,13 @@ export default defineConfig(() => { { // bigInt: true, dates: true, - name: '@hey-api/transformers', + // name: '@hey-api/transformers', }, { - name: 'fastify', + // name: 'fastify', }, { - name: 'swr', + // name: 'swr', }, { // case: 'SCREAMING_SNAKE_CASE', @@ -362,7 +363,7 @@ export default defineConfig(() => { }, }, { - name: 'arktype', + // name: 'arktype', types: { infer: true, }, diff --git a/docs/package.json b/docs/package.json index d6b803f50..34794fcd7 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,7 +1,7 @@ { "name": "@docs/openapi-ts", "version": "0.10.4", - "description": "Documentation for OpenaAPI TypeScript.", + "description": "Documentation for OpenAPI TypeScript.", "private": true, "type": "module", "scripts": { diff --git a/docs/scripts/optimize-images.js b/docs/scripts/optimize-images.js index 2bc7898f9..fca42f964 100644 --- a/docs/scripts/optimize-images.js +++ b/docs/scripts/optimize-images.js @@ -31,6 +31,19 @@ const images = [ ], source: 'bricks.png', }, + // { + // sizes: [ + // { + // formats: ['png'], + // width: 300, + // }, + // { + // formats: ['png'], + // width: 640, + // }, + // ], + // source: 'hero.png', + // }, { sizes: [ { diff --git a/examples/openapi-ts-openai/src/client/types.gen.ts b/examples/openapi-ts-openai/src/client/types.gen.ts index ac7532f67..449f08aca 100644 --- a/examples/openapi-ts-openai/src/client/types.gen.ts +++ b/examples/openapi-ts-openai/src/client/types.gen.ts @@ -259,8 +259,8 @@ export const AssistantSupportedModels = { GPT_3_5_TURBO_16K_0613: 'gpt-3.5-turbo-16k-0613', } as const; -export type AssistantSupportedModels = - (typeof AssistantSupportedModels)[keyof typeof AssistantSupportedModels]; +export type AssistantSupportedModels2 = + (typeof AssistantSupportedModels2)[keyof typeof AssistantSupportedModels2]; /** * Code interpreter tool @@ -378,8 +378,8 @@ export const AudioResponseFormat = { * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt`. For `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`, the only supported format is `json`. * */ -export type AudioResponseFormat = - (typeof AudioResponseFormat)[keyof typeof AudioResponseFormat]; +export type AudioResponseFormat2 = + (typeof AudioResponseFormat2)[keyof typeof AudioResponseFormat2]; /** * A log of a user action or configuration change within this organization. @@ -389,7 +389,7 @@ export type AuditLog = { * The ID of this log. */ id: string; - type: AuditLogEventType; + type: AuditLogEventType2; /** * The Unix timestamp (in seconds) of the event. */ @@ -949,8 +949,8 @@ export const AuditLogEventType = { /** * The event type. */ -export type AuditLogEventType = - (typeof AuditLogEventType)[keyof typeof AuditLogEventType]; +export type AuditLogEventType2 = + (typeof AuditLogEventType2)[keyof typeof AuditLogEventType2]; /** * Auto Chunking Strategy @@ -1911,8 +1911,8 @@ export const ChatCompletionRole = { /** * The role of the author of a message */ -export type ChatCompletionRole = - (typeof ChatCompletionRole)[keyof typeof ChatCompletionRole]; +export type ChatCompletionRole2 = + (typeof ChatCompletionRole2)[keyof typeof ChatCompletionRole2]; /** * Options for streaming response. Only set this when you set `stream: true`. @@ -2698,7 +2698,7 @@ export type CreateAssistantRequest = { * ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models) for descriptions of them. * */ - model: string | AssistantSupportedModels; + model: string | AssistantSupportedModels2; /** * The name of the assistant. The maximum length is 256 characters. * @@ -2714,7 +2714,7 @@ export type CreateAssistantRequest = { * */ instructions?: string; - reasoning_effort?: ReasoningEffort; + reasoning_effort?: ReasoningEffort2; /** * A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. * @@ -2815,8 +2815,8 @@ export type CreateChatCompletionRequest = CreateModelResponseProperties & { */ model: ModelIdsShared; modalities?: ResponseModalities; - verbosity?: Verbosity; - reasoning_effort?: ReasoningEffort; + verbosity?: Verbosity2; + reasoning_effort?: ReasoningEffort2; /** * An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and [reasoning tokens](https://platform.openai.com/docs/guides/reasoning). * @@ -2856,7 +2856,7 @@ export type CreateChatCompletionRequest = CreateModelResponseProperties & { type: 'approximate'; approximate: WebSearchLocation; }; - search_context_size?: WebSearchContextSize; + search_context_size?: WebSearchContextSize2; }; /** * An integer between 0 and 20 specifying the number of most likely tokens to @@ -3077,7 +3077,7 @@ export type CreateChatCompletionResponse = { * The model used for the chat completion. */ model: string; - service_tier?: ServiceTier; + service_tier?: ServiceTier2; /** * This fingerprint represents the backend configuration that the model runs with. * @@ -3151,7 +3151,7 @@ export type CreateChatCompletionStreamResponse = { * The model to generate the completion. */ model: string; - service_tier?: ServiceTier; + service_tier?: ServiceTier2; /** * This fingerprint represents the backend configuration that the model runs with. * Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism. @@ -3859,7 +3859,7 @@ export type CreateFileRequest = { * */ file: Blob | File; - purpose: FilePurpose; + purpose: FilePurpose2; expires_after?: FileExpirationAfter; }; @@ -4065,7 +4065,7 @@ export type CreateImageEditRequest = { * */ user?: string; - input_fidelity?: ImageInputFidelity; + input_fidelity?: ImageInputFidelity2; /** * Edit the image in streaming mode. Defaults to `false`. See the * [Image generation guide](https://platform.openai.com/docs/guides/image-generation) for more information. @@ -4498,7 +4498,7 @@ export type CreateResponse = CreateModelResponseProperties & * enrolled in the zero data retention program). * */ - include?: Array; + include?: Array; /** * Whether to allow the model to run tool calls in parallel. * @@ -4538,8 +4538,8 @@ export type CreateRunRequest = { /** * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used. */ - model?: string | AssistantSupportedModels; - reasoning_effort?: ReasoningEffort; + model?: string | AssistantSupportedModels2; + reasoning_effort?: ReasoningEffort2; /** * Overrides the [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant) of the assistant. This is useful for modifying the behavior on a per-run basis. */ @@ -4836,7 +4836,7 @@ export type CreateTranscriptionRequest = { * */ prompt?: string; - response_format?: AudioResponseFormat; + response_format?: AudioResponseFormat2; /** * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. * @@ -4866,7 +4866,7 @@ export type CreateTranscriptionRequest = { * the models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`. * */ - include?: Array; + include?: Array; }; /** @@ -5746,7 +5746,7 @@ export type EvalResponsesSource = { /** * Optional reasoning effort parameter. This is a query parameter used to select responses. */ - reasoning_effort?: ReasoningEffort; + reasoning_effort?: ReasoningEffort2; /** * Sampling temperature. This is a query parameter used to select responses. */ @@ -6181,8 +6181,8 @@ export const FileSearchRanker = { /** * The ranker to use for the file search. If not specified will use the `auto` ranker. */ -export type FileSearchRanker = - (typeof FileSearchRanker)[keyof typeof FileSearchRanker]; +export type FileSearchRanker2 = + (typeof FileSearchRanker2)[keyof typeof FileSearchRanker2]; /** * File search tool call ranking options @@ -6193,7 +6193,7 @@ export type FileSearchRanker = * */ export type FileSearchRankingOptions = { - ranker?: FileSearchRanker; + ranker?: FileSearchRanker2; /** * The score threshold for the file search. All values must be a floating point number between 0 and 1. */ @@ -7313,7 +7313,7 @@ export type ImageGenTool = { * */ background?: 'transparent' | 'opaque' | 'auto'; - input_fidelity?: ImageInputFidelity; + input_fidelity?: ImageInputFidelity2; /** * Optional mask for inpainting. Contains `image_url` * (string, optional) and `file_id` (string, optional). @@ -7381,8 +7381,8 @@ export const ImageInputFidelity = { HIGH: 'high', LOW: 'low' } as const; * for `gpt-image-1`. Supports `high` and `low`. Defaults to `low`. * */ -export type ImageInputFidelity = - (typeof ImageInputFidelity)[keyof typeof ImageInputFidelity]; +export type ImageInputFidelity2 = + (typeof ImageInputFidelity2)[keyof typeof ImageInputFidelity2]; /** * Image generation response @@ -7494,7 +7494,7 @@ export const Includable = { * enrolled in the zero data retention program). * */ -export type Includable = (typeof Includable)[keyof typeof Includable]; +export type Includable2 = (typeof Includable2)[keyof typeof Includable2]; /** * Audio input @@ -8846,7 +8846,7 @@ export type ModelIdsResponses = | 'computer-use-preview' | 'computer-use-preview-2025-03-11'; -export type ModelIdsShared = string | ChatModel; +export type ModelIdsShared = string | ChatModel2; export type ModelResponseProperties = { metadata?: Metadata; @@ -8892,7 +8892,7 @@ export type ModelResponseProperties = { * */ prompt_cache_key?: string; - service_tier?: ServiceTier; + service_tier?: ServiceTier2; }; export type ModifyAssistantRequest = { @@ -8900,8 +8900,8 @@ export type ModifyAssistantRequest = { * ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models) for descriptions of them. * */ - model?: string | AssistantSupportedModels; - reasoning_effort?: ReasoningEffort; + model?: string | AssistantSupportedModels2; + reasoning_effort?: ReasoningEffort2; /** * The name of the assistant. The maximum length is 256 characters. * @@ -12424,7 +12424,7 @@ export type RealtimeTranscriptionSessionCreateResponse = { * */ export type Reasoning = { - effort?: ReasoningEffort; + effort?: ReasoningEffort2; /** * A summary of the reasoning performed by the model. This can be * useful for debugging and understanding the model's reasoning process. @@ -12468,8 +12468,8 @@ export const ReasoningEffort = { * on reasoning in a response. * */ -export type ReasoningEffort = - (typeof ReasoningEffort)[keyof typeof ReasoningEffort]; +export type ReasoningEffort2 = + (typeof ReasoningEffort2)[keyof typeof ReasoningEffort2]; /** * Reasoning @@ -12980,7 +12980,7 @@ export type ResponseCustomToolCallInputDoneEvent = { * */ export type ResponseError = { - code: ResponseErrorCode; + code: ResponseErrorCode2; /** * A human-readable description of the error. * @@ -13017,8 +13017,8 @@ export const ResponseErrorCode = { * The error code for the response. * */ -export type ResponseErrorCode = - (typeof ResponseErrorCode)[keyof typeof ResponseErrorCode]; +export type ResponseErrorCode2 = + (typeof ResponseErrorCode2)[keyof typeof ResponseErrorCode2]; /** * Emitted when an error occurs. @@ -13896,7 +13896,7 @@ export type ResponseProperties = { */ text?: { format?: TextResponseFormatConfiguration; - verbosity?: Verbosity; + verbosity?: Verbosity2; }; /** * An array of tools the model may call while generating a response. You @@ -13923,7 +13923,7 @@ export type ResponseProperties = { * */ tool_choice?: - | ToolChoiceOptions + | ToolChoiceOptions2 | ToolChoiceAllowed | ToolChoiceTypes | ToolChoiceFunction @@ -14765,7 +14765,7 @@ export type RunObject = { * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) used for execution of this run. */ assistant_id: string; - status: RunStatus; + status: RunStatus2; /** * Details on the action required to continue the run. Will be `null` if no action is required. */ @@ -15190,7 +15190,7 @@ export type RunStepDetailsToolCallsFileSearchObject = { * The ranking options for the file search. */ export type RunStepDetailsToolCallsFileSearchRankingOptionsObject = { - ranker: FileSearchRanker; + ranker: FileSearchRanker2; /** * The score threshold for the file search. All values must be a floating point number between 0 and 1. */ @@ -15537,7 +15537,7 @@ export const ServiceTier = { * When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter. * */ -export type ServiceTier = (typeof ServiceTier)[keyof typeof ServiceTier]; +export type ServiceTier2 = (typeof ServiceTier2)[keyof typeof ServiceTier2]; /** * Emitted for each chunk of audio data generated during speech synthesis. @@ -15933,8 +15933,8 @@ export const ToolChoiceOptions = { * `required` means the model must call one or more tools. * */ -export type ToolChoiceOptions = - (typeof ToolChoiceOptions)[keyof typeof ToolChoiceOptions]; +export type ToolChoiceOptions2 = + (typeof ToolChoiceOptions2)[keyof typeof ToolChoiceOptions2]; /** * Hosted tool @@ -16100,8 +16100,8 @@ export type TranscriptionChunkingStrategy = 'auto' | VadConfig; export const TranscriptionInclude = { LOGPROBS: 'logprobs' } as const; -export type TranscriptionInclude = - (typeof TranscriptionInclude)[keyof typeof TranscriptionInclude]; +export type TranscriptionInclude2 = + (typeof TranscriptionInclude2)[keyof typeof TranscriptionInclude2]; export type TranscriptionSegment = { /** @@ -17000,7 +17000,7 @@ export const Verbosity = { * Currently supported values are `low`, `medium`, and `high`. * */ -export type Verbosity = (typeof Verbosity)[keyof typeof Verbosity]; +export type Verbosity2 = (typeof Verbosity2)[keyof typeof Verbosity2]; export type VoiceIdsShared = | string @@ -17106,8 +17106,8 @@ export const WebSearchContextSize = { * search. One of `low`, `medium`, or `high`. `medium` is the default. * */ -export type WebSearchContextSize = - (typeof WebSearchContextSize)[keyof typeof WebSearchContextSize]; +export type WebSearchContextSize2 = + (typeof WebSearchContextSize2)[keyof typeof WebSearchContextSize2]; /** * Web search location @@ -18269,7 +18269,7 @@ export const FilePurpose = { * The intended purpose of the uploaded file. One of: - `assistants`: Used in the Assistants API - `batch`: Used in the Batch API - `fine-tune`: Used for fine-tuning - `vision`: Images used for vision fine-tuning - `user_data`: Flexible file type for any purpose - `evals`: Used for eval data sets * */ -export type FilePurpose = (typeof FilePurpose)[keyof typeof FilePurpose]; +export type FilePurpose2 = (typeof FilePurpose2)[keyof typeof FilePurpose2]; export type BatchError = { /** @@ -18451,7 +18451,7 @@ export const ChatModel = { GPT_3_5_TURBO_16K_0613: 'gpt-3.5-turbo-16k-0613', } as const; -export type ChatModel = (typeof ChatModel)[keyof typeof ChatModel]; +export type ChatModel2 = (typeof ChatModel2)[keyof typeof ChatModel2]; export type CreateThreadAndRunRequestWithoutStream = { /** @@ -18567,8 +18567,8 @@ export type CreateRunRequestWithoutStream = { /** * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used. */ - model?: string | AssistantSupportedModels; - reasoning_effort?: ReasoningEffort; + model?: string | AssistantSupportedModels2; + reasoning_effort?: ReasoningEffort2; /** * Overrides the [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant) of the assistant. This is useful for modifying the behavior on a per-run basis. */ @@ -18648,7 +18648,7 @@ export const RunStatus = { /** * The status of the run, which can be either `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, `incomplete`, or `expired`. */ -export type RunStatus = (typeof RunStatus)[keyof typeof RunStatus]; +export type RunStatus2 = (typeof RunStatus2)[keyof typeof RunStatus2]; /** * The delta containing the fields that have changed on the run step. @@ -20419,7 +20419,7 @@ export type ListAuditLogsData = { /** * Return only events with a `type` in one of these values. For example, `project.created`. For all options, see the documentation for the [audit log object](https://platform.openai.com/docs/api-reference/audit-logs/object). */ - 'event_types[]'?: Array; + 'event_types[]'?: Array; /** * Return only events performed by these actors. Can be a user ID, a service account ID, or an api key tracking ID. */ @@ -22143,7 +22143,7 @@ export type GetResponseData = { * parameter for Response creation above for more information. * */ - include?: Array; + include?: Array; /** * If set to true, the model response data will be streamed to the client * as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format). @@ -22251,7 +22251,7 @@ export type ListInputItemsData = { * parameter for Response creation above for more information. * */ - include?: Array; + include?: Array; }; url: '/responses/{response_id}/input_items'; }; diff --git a/packages/codegen-core/src/__tests__/bimap.test.ts b/packages/codegen-core/src/__tests__/bimap.test.ts index b28fe2665..2a4b25d96 100644 --- a/packages/codegen-core/src/__tests__/bimap.test.ts +++ b/packages/codegen-core/src/__tests__/bimap.test.ts @@ -8,11 +8,11 @@ describe('BiMap', () => { // set and get expect(bimap.set(1, 'a')).toBe(bimap); expect(bimap.set(2, 'b')).toBe(bimap); - // get, getKey + // get, getKeys expect(bimap.get(1)).toBe('a'); expect(bimap.get(2)).toBe('b'); - expect(bimap.getKey('a')).toBe(1); - expect(bimap.getKey('b')).toBe(2); + expect(bimap.getKeys('a')).toEqual(new Set([1])); + expect(bimap.getKeys('b')).toEqual(new Set([2])); // hasKey, hasValue expect(bimap.hasKey(1)).toBe(true); expect(bimap.hasKey(2)).toBe(true); @@ -52,13 +52,14 @@ describe('BiMap', () => { // Overwrite value for existing key bimap.set(1, 'z'); expect(bimap.get(1)).toBe('z'); - expect(bimap.getKey('z')).toBe(1); + expect(bimap.getKeys('z')).toEqual(new Set([1])); // Overwrite key for existing value bimap.set(3, 'z'); - expect(bimap.getKey('z')).toBe(3); - expect(bimap.get(1)).toBeUndefined(); + expect(bimap.getKeys('z')).toEqual(new Set([1, 3])); + expect(bimap.get(1)).toBe('z'); // Iteration after overwrite expect(Array.from(bimap)).toEqual([ + [1, 'z'], [2, 'y'], [3, 'z'], ]); diff --git a/packages/codegen-core/src/__tests__/files.test.ts b/packages/codegen-core/src/__tests__/files.test.ts index ef376d1a1..981194c1e 100644 --- a/packages/codegen-core/src/__tests__/files.test.ts +++ b/packages/codegen-core/src/__tests__/files.test.ts @@ -17,6 +17,7 @@ describe('FileRegistry', () => { extension: undefined, external: undefined, id: expect.any(Number), + localNames: new Set(), name: 'Foo', path: undefined, resolvedNames: expect.any(Object), @@ -58,6 +59,7 @@ describe('FileRegistry', () => { extension: undefined, external: undefined, id: expect.any(Number), + localNames: new Set(), name: 'Bar', path: '/bar', resolvedNames: expect.any(Object), diff --git a/packages/codegen-core/src/__tests__/symbols.test.ts b/packages/codegen-core/src/__tests__/symbols.test.ts index 6a1edc28d..142391724 100644 --- a/packages/codegen-core/src/__tests__/symbols.test.ts +++ b/packages/codegen-core/src/__tests__/symbols.test.ts @@ -13,18 +13,25 @@ describe('SymbolRegistry', () => { // Register a symbol with meta const symbol1 = registry.register({ - meta: { - foo: 'bar', - }, - placeholder: 'Foo', - }); - expect(symbol1).toEqual({ - id: expect.any(Number), - meta: { - foo: 'bar', - }, + meta: { foo: 'bar' }, + name: '', placeholder: 'Foo', }); + expect(symbol1).toEqual( + expect.objectContaining({ + _dependencies: new Set(), + exportFrom: [], + exported: false, + id: expect.any(Number), + importKind: 'named', + kind: 'var', + meta: { + foo: 'bar', + }, + name: '', + placeholder: 'Foo', + }), + ); // get by id and meta expect(registry.get(symbol1.id)).toEqual(symbol1); @@ -35,30 +42,33 @@ describe('SymbolRegistry', () => { expect(registry.isRegistered({ foo: 'bar' })).toBe(true); // Registering again with same meta creates a new symbol - const symbol1b = registry.register({ meta: { foo: 'bar' } }); + const symbol1b = registry.register({ + meta: { foo: 'bar' }, + name: '', + }); expect(symbol1b).not.toEqual(symbol1); - // Registering with id overrides the symbol - const symbol1c = registry.register({ id: symbol1.id }); - expect(symbol1c).not.toEqual(symbol1); - expect(symbol1c.id).toBe(symbol1.id); - // Reference returns same symbol const ref1 = registry.reference({ foo: 'bar' }); - expect(ref1).toEqual(symbol1c); + expect(ref1).toEqual(symbol1); // Register a new symbol with different meta const symbol2 = registry.register({ exportFrom: ['x'], meta: { bar: 'baz' }, + name: '', placeholder: 'Bar', }); - expect(symbol2).toEqual({ - exportFrom: ['x'], - id: expect.any(Number), - meta: { bar: 'baz' }, - placeholder: 'Bar', - }); + expect(symbol2).toEqual( + expect.objectContaining({ + dependencies: new Set(), + exportFrom: ['x'], + id: expect.any(Number), + meta: { bar: 'baz' }, + name: '', + placeholder: 'Bar', + }), + ); // Registered symbols are yielded in order const registered = Array.from(registry.registered()); @@ -79,6 +89,7 @@ describe('SymbolRegistry', () => { expect(registry.isRegistered(symRef.id)).toBe(false); const symRegistered = registry.register({ meta: { qux: true }, + name: '', placeholder: 'Qux', }); expect(registry.isRegistered(symRegistered.id)).toBe(true); @@ -122,11 +133,11 @@ describe('SymbolRegistry', () => { const refAD = registry.reference({ a: 0, d: 0 }); const refAC = registry.reference({ a: 0, c: 0 }); - expect(symC).toEqual(refA); - expect(symC).toEqual(refAB); - expect(symC).toEqual(refAC); - expect(symC).not.toEqual(refAD); - expect(symC).not.toEqual(refB); + expect(refA.canonical).toEqual(symC); + expect(refAB.canonical).toEqual(symC); + expect(refAC.canonical).toEqual(symC); + expect(refAD.canonical).not.toEqual(symC); + expect(refB.canonical).not.toEqual(symC); expect(symC.meta).toEqual({ a: 0, b: 0, c: 0 }); }); diff --git a/packages/codegen-core/src/bimap/bimap.ts b/packages/codegen-core/src/bimap/bimap.ts index 93f21afb9..d28794531 100644 --- a/packages/codegen-core/src/bimap/bimap.ts +++ b/packages/codegen-core/src/bimap/bimap.ts @@ -2,7 +2,7 @@ import type { IBiMap } from './types'; export class BiMap implements IBiMap { private map = new Map(); - private reverse = new Map(); + private reverse = new Map>(); delete(key: Key): boolean { const value = this.map.get(key); @@ -13,9 +13,11 @@ export class BiMap implements IBiMap { } deleteValue(value: Value): boolean { - const key = this.reverse.get(value); - if (key !== undefined) { - this.map.delete(key); + const keys = this.reverse.get(value); + if (keys) { + for (const key of keys) { + this.map.delete(key); + } } return this.reverse.delete(value); } @@ -28,7 +30,7 @@ export class BiMap implements IBiMap { return this.map.get(key); } - getKey(value: Value): Key | undefined { + getKeys(value: Value): Set | undefined { return this.reverse.get(value); } @@ -47,14 +49,18 @@ export class BiMap implements IBiMap { set(key: Key, value: Value): this { const oldValue = this.map.get(key); if (oldValue !== undefined && oldValue !== value) { - this.reverse.delete(oldValue); - } - const oldKey = this.reverse.get(value); - if (oldKey !== undefined && oldKey !== key) { - this.map.delete(oldKey); + const oldKeys = this.reverse.get(oldValue); + if (oldKeys) { + oldKeys.delete(key); + if (oldKeys.size === 0) { + this.reverse.delete(oldValue); + } + } } this.map.set(key, value); - this.reverse.set(value, key); + const keys = this.reverse.get(value) ?? new Set(); + keys.add(key); + this.reverse.set(value, keys); return this; } diff --git a/packages/codegen-core/src/bimap/types.d.ts b/packages/codegen-core/src/bimap/types.d.ts index c7b81aea3..529d71699 100644 --- a/packages/codegen-core/src/bimap/types.d.ts +++ b/packages/codegen-core/src/bimap/types.d.ts @@ -30,11 +30,11 @@ export interface IBiMap { */ get(key: Key): Value | undefined; /** - * Gets the key associated with a value. + * Gets the keys associated with a value. * * @param value The value to look up. */ - getKey(value: Value): Key | undefined; + getKeys(value: Value): Set | undefined; /** * Checks if a key exists in the map. * diff --git a/packages/codegen-core/src/bindings/utils.ts b/packages/codegen-core/src/bindings/utils.ts index 84cf003f4..f8e9cf12d 100644 --- a/packages/codegen-core/src/bindings/utils.ts +++ b/packages/codegen-core/src/bindings/utils.ts @@ -1,5 +1,5 @@ import type { IFileOut } from '../files/types'; -import type { ISymbolOut } from '../symbols/types'; +import type { Symbol } from '../symbols/symbol'; import type { IBinding } from './types'; export const createBinding = ({ @@ -10,7 +10,7 @@ export const createBinding = ({ }: { file: IFileOut; modulePath: string; - symbol: ISymbolOut; + symbol: Symbol; symbolFile: IFileOut; }): IBinding => { const names: Array = []; @@ -48,12 +48,12 @@ export const createBinding = ({ } } else if (symbol.name && fileResolvedName !== symbol.name) { name = symbol.name; - binding.aliases[name] = symbol.placeholder; + binding.aliases[name] = symbol.placeholder!; } } - names.push(name); + names.push(name!); if (symbol.kind === 'type') { - typeNames.push(name); + typeNames.push(name!); } } // cast type names to names to allow for cleaner API, diff --git a/packages/codegen-core/src/extensions/types.d.ts b/packages/codegen-core/src/extensions.d.ts similarity index 100% rename from packages/codegen-core/src/extensions/types.d.ts rename to packages/codegen-core/src/extensions.d.ts diff --git a/packages/codegen-core/src/files/registry.ts b/packages/codegen-core/src/files/registry.ts index cd89e62dd..e51ce85d3 100644 --- a/packages/codegen-core/src/files/registry.ts +++ b/packages/codegen-core/src/files/registry.ts @@ -100,6 +100,7 @@ export class FileRegistry implements IFileRegistry { ...result, ...file, // clone to avoid mutation id, + localNames: new Set(), resolvedNames: result?.resolvedNames ?? new BiMap(), symbols: result?.symbols ?? { body: [], diff --git a/packages/codegen-core/src/files/types.d.ts b/packages/codegen-core/src/files/types.d.ts index 892fbe2ea..9dc3ab505 100644 --- a/packages/codegen-core/src/files/types.d.ts +++ b/packages/codegen-core/src/files/types.d.ts @@ -52,6 +52,10 @@ export type IFileOut = IFileIn & { * Unique file ID. */ readonly id: number; + /** + * Names declared in local (non‑top‑level) scopes within this file. + */ + readonly localNames: Set; /** * Map holding resolved names for symbols in this file. */ diff --git a/packages/codegen-core/src/index.ts b/packages/codegen-core/src/index.ts index 22d8c0fd8..7fc9b52bc 100644 --- a/packages/codegen-core/src/index.ts +++ b/packages/codegen-core/src/index.ts @@ -4,19 +4,20 @@ export { createBinding, mergeBindings } from './bindings/utils'; export type { IProjectRenderMeta as ProjectRenderMeta, ISymbolMeta as SymbolMeta, -} from './extensions/types'; +} from './extensions'; export type { IFileOut as File, IFileIdentifier as FileIdentifier, IFileIn as FileIn, } from './files/types'; -export type { IOutput as Output } from './output/types'; +export type { IOutput as Output } from './output'; export { Project } from './project/project'; export type { IProject } from './project/types'; export type { IRenderer as Renderer } from './renderer/types'; export { renderIds } from './renderer/utils'; +export { Symbol } from './symbols/symbol'; export type { - ISymbolOut as Symbol, ISymbolIdentifier as SymbolIdentifier, ISymbolIn as SymbolIn, } from './symbols/types'; +export type { ISyntaxNode as SyntaxNode } from './syntax-node'; diff --git a/packages/codegen-core/src/output/types.d.ts b/packages/codegen-core/src/output.d.ts similarity index 100% rename from packages/codegen-core/src/output/types.d.ts rename to packages/codegen-core/src/output.d.ts diff --git a/packages/codegen-core/src/project/project.ts b/packages/codegen-core/src/project/project.ts index c479b5428..91ed73036 100644 --- a/packages/codegen-core/src/project/project.ts +++ b/packages/codegen-core/src/project/project.ts @@ -1,12 +1,12 @@ import path from 'node:path'; -import type { IProjectRenderMeta } from '../extensions/types'; +import type { IProjectRenderMeta } from '../extensions'; import { FileRegistry } from '../files/registry'; import type { IFileOut, IFileSelector } from '../files/types'; -import type { IOutput } from '../output/types'; +import type { IOutput } from '../output'; import type { IRenderer } from '../renderer/types'; import { SymbolRegistry } from '../symbols/registry'; -import type { ISymbolOut } from '../symbols/types'; +import type { Symbol } from '../symbols/symbol'; import type { IProject } from './types'; const externalSourceSymbol = '@'; @@ -133,7 +133,7 @@ export class Project implements IProject { return Array.from(fileIds ?? []).map((fileId) => this.files.get(fileId)!); } - private symbolToFileSelector(symbol: ISymbolOut): IFileSelector { + private symbolToFileSelector(symbol: Symbol): IFileSelector { if (symbol.external) { return [externalSourceSymbol, symbol.external]; } diff --git a/packages/codegen-core/src/project/types.d.ts b/packages/codegen-core/src/project/types.d.ts index 22d2c6ba7..bbb80fa75 100644 --- a/packages/codegen-core/src/project/types.d.ts +++ b/packages/codegen-core/src/project/types.d.ts @@ -1,6 +1,6 @@ -import type { IProjectRenderMeta } from '../extensions/types'; +import type { IProjectRenderMeta } from '../extensions'; import type { IFileOut, IFileRegistry } from '../files/types'; -import type { IOutput } from '../output/types'; +import type { IOutput } from '../output'; import type { IRenderer } from '../renderer/types'; import type { ISymbolRegistry } from '../symbols/types'; diff --git a/packages/codegen-core/src/renderer/types.d.ts b/packages/codegen-core/src/renderer/types.d.ts index 651d28c0c..7b36db787 100644 --- a/packages/codegen-core/src/renderer/types.d.ts +++ b/packages/codegen-core/src/renderer/types.d.ts @@ -1,4 +1,4 @@ -import type { IProjectRenderMeta } from '../extensions/types'; +import type { IProjectRenderMeta } from '../extensions'; import type { IFileOut } from '../files/types'; import type { IProject } from '../project/types'; diff --git a/packages/codegen-core/src/symbols/registry.ts b/packages/codegen-core/src/symbols/registry.ts index 00a6cd0e7..48ac0569b 100644 --- a/packages/codegen-core/src/symbols/registry.ts +++ b/packages/codegen-core/src/symbols/registry.ts @@ -1,11 +1,6 @@ -import type { ISymbolMeta } from '../extensions/types'; -import { wrapId } from '../renderer/utils'; -import type { - ISymbolIdentifier, - ISymbolIn, - ISymbolOut, - ISymbolRegistry, -} from './types'; +import type { ISymbolMeta } from '../extensions'; +import { Symbol } from './symbol'; +import type { ISymbolIdentifier, ISymbolIn, ISymbolRegistry } from './types'; type IndexEntry = [string, unknown]; type IndexKeySpace = ReadonlyArray; @@ -23,9 +18,9 @@ export class SymbolRegistry implements ISymbolRegistry { private registerOrder: Set = new Set(); private stubCache: Map = new Map(); private stubs: Set = new Set(); - private values: Map = new Map(); + private values: Map = new Map(); - get(identifier: ISymbolIdentifier): ISymbolOut | undefined { + get(identifier: ISymbolIdentifier): Symbol | undefined { return typeof identifier === 'number' ? this.values.get(identifier) : this.query(identifier)[0]; @@ -48,7 +43,7 @@ export class SymbolRegistry implements ISymbolRegistry { return symbol ? this.registerOrder.has(symbol.id) : false; } - query(filter: ISymbolMeta): ReadonlyArray { + query(filter: ISymbolMeta): ReadonlyArray { const cacheKey = this.buildCacheKey(filter); const cachedIds = this.queryCache.get(cacheKey); if (cachedIds) { @@ -87,33 +82,28 @@ export class SymbolRegistry implements ISymbolRegistry { return resultIds.map((symbolId) => this.values.get(symbolId)!); } - reference(meta: ISymbolMeta): ISymbolOut { + reference(meta: ISymbolMeta): Symbol { const [registered] = this.query(meta); if (registered) return registered; + const cacheKey = this.buildCacheKey(meta); const cachedId = this.stubCache.get(cacheKey); if (cachedId !== undefined) return this.values.get(cachedId)!; - const id = this.id; - const stub: ISymbolOut = { - id, - meta, - placeholder: wrapId(String(id)), - }; + + const stub = new Symbol({ meta, name: '' }, this.id); + this.values.set(stub.id, stub); this.stubs.add(stub.id); this.stubCache.set(cacheKey, stub.id); return stub; } - register(symbol: ISymbolIn): ISymbolOut { - const id = symbol.id !== undefined ? symbol.id : this.id; - const result: ISymbolOut = { - ...symbol, // clone to avoid mutation - id, - placeholder: symbol.placeholder ?? wrapId(String(id)), - }; + register(symbol: ISymbolIn): Symbol { + const result = new Symbol(symbol, this.id); + this.values.set(result.id, result); this.registerOrder.add(result.id); + if (result.meta) { const indexKeySpace = this.buildIndexKeySpace(result.meta); this.indexSymbol(result.id, indexKeySpace); @@ -123,7 +113,7 @@ export class SymbolRegistry implements ISymbolRegistry { return result; } - *registered(): IterableIterator { + *registered(): IterableIterator { for (const id of this.registerOrder.values()) { yield this.values.get(id)!; } @@ -192,7 +182,7 @@ export class SymbolRegistry implements ISymbolRegistry { return true; } - private replaceStubs(symbol: ISymbolOut, indexKeySpace: IndexKeySpace): void { + private replaceStubs(symbol: Symbol, indexKeySpace: IndexKeySpace): void { for (const stubId of this.stubs.values()) { const stub = this.values.get(stubId); if ( @@ -201,8 +191,8 @@ export class SymbolRegistry implements ISymbolRegistry { ) { const cacheKey = this.buildCacheKey(stub.meta); this.stubCache.delete(cacheKey); - this.values.set(stubId, Object.assign(stub, symbol)); this.stubs.delete(stubId); + stub.setCanonical(symbol); } } } diff --git a/packages/codegen-core/src/symbols/symbol.ts b/packages/codegen-core/src/symbols/symbol.ts new file mode 100644 index 000000000..47d78f495 --- /dev/null +++ b/packages/codegen-core/src/symbols/symbol.ts @@ -0,0 +1,316 @@ +import type { ISymbolMeta } from '../extensions'; +import type { IFileOut } from '../files/types'; +import { wrapId } from '../renderer/utils'; +import type { ISyntaxNode } from '../syntax-node'; +import type { ISymbolIn, SymbolImportKind, SymbolKind } from './types'; + +export class Symbol { + /** + * Canonical symbol this stub resolves to, if any. + * + * Stubs created during DSL construction may later be associated + * with a fully registered symbol. Once set, all property lookups + * should defer to the canonical symbol. + * + * @private + */ + private _canonical?: Symbol; + /** + * Private set of direct symbol dependencies. + * + * @private + */ + private readonly _dependencies = new Set(); + /** + * True if this symbol is exported from its defining file. + * + * @default false + */ + private _exported: boolean; + /** + * Names of files (without extension) from which this symbol is re-exported. + * + * @default [] + */ + private _exportFrom: ReadonlyArray; + /** + * External module name if this symbol is imported from a module not managed + * by the project (e.g. "zod", "lodash"). + * + * @default undefined + */ + private _external?: string; + /** + * The file this symbol is ultimately emitted into. + * + * @private + */ + private _file?: IFileOut; + /** + * The alias-resolved, conflict-free emitted name. + * + * @private + */ + private _finalName?: string; + /** + * Custom strategy to determine file output path. + * + * @returns The file path to output the symbol to, or undefined to fallback to default behavior. + */ + private _getFilePath?: (symbol: Symbol) => string | undefined; + /** + * How this symbol should be imported (namespace/default/named). + * + * @default 'named' + */ + private _importKind: SymbolImportKind; + /** + * Kind of symbol (class, type, alias, etc.). + * + * @default 'var' + */ + private _kind: SymbolKind; + /** + * Arbitrary user metadata. + * + * @default undefined + */ + private _meta?: ISymbolMeta; + /** + * Intended user-facing name before conflict resolution. + * + * @example "UserModel" + */ + private _name: string; + /** + * Root DSL node that defines this symbol. + * + * @private + */ + private _rootNode?: ISyntaxNode; + + /** + * Globally unique, stable symbol ID. + */ + readonly id: number; + /** + * Placeholder name for the symbol to be replaced later with the final value. + * + * @deprecated + * @example "_heyapi_31_" + */ + readonly placeholder: string; + + constructor(input: ISymbolIn, id: number) { + this._exported = input.exported ?? false; + this._exportFrom = input.exportFrom ?? []; + this._external = input.external; + this._getFilePath = input.getFilePath; + this.id = id; + this._importKind = input.importKind ?? 'named'; + this._kind = input.kind ?? 'var'; + this._meta = input.meta; + this._name = input.name; + this.placeholder = input.placeholder || wrapId(String(id)); + } + + /** + * Returns the canonical symbol for this instance. + * + * If this symbol was created as a stub, this getter returns + * the fully registered canonical symbol. Otherwise, it returns + * the symbol itself. + */ + get canonical(): Symbol { + return this._canonical ?? this; + } + + /** + * Read-only access to dependencies. + */ + get dependencies(): ReadonlySet { + return this.canonical._dependencies; + } + + /** + * Indicates whether this symbol is exported from its defining file. + */ + get exported(): boolean { + return this.canonical._exported; + } + + /** + * Names of files (without extension) that re-export this symbol. + */ + get exportFrom(): ReadonlyArray { + return this.canonical._exportFrom; + } + + /** + * External module from which this symbol originates, if any. + */ + get external(): string | undefined { + return this.canonical._external; + } + + /** + * Read‑only accessor for the assigned output file. + */ + get file(): IFileOut | undefined { + return this.canonical._file; + } + + /** + * Read‑only accessor for the resolved final emitted name. + */ + get finalName(): string { + return ( + this.canonical._finalName || + this.canonical.placeholder || + this.canonical.name + ); + } + + get getFilePath(): ((symbol: Symbol) => string | undefined) | undefined { + return this.canonical._getFilePath; + } + + /** + * How this symbol should be imported (named/default/namespace). + */ + get importKind(): SymbolImportKind { + return this.canonical._importKind; + } + + /** + * The symbol's kind (class, type, alias, variable, etc.). + */ + get kind(): SymbolKind { + return this.canonical._kind; + } + + /** + * Arbitrary user‑provided metadata associated with this symbol. + */ + get meta(): ISymbolMeta | undefined { + return this.canonical._meta; + } + + get name(): string { + return this.canonical._name; + } + + /** + * Read‑only accessor for the defining DSL root node. + */ + get rootNode(): ISyntaxNode | undefined { + return this.canonical._rootNode; + } + + /** + * Add a direct dependency on another symbol. + */ + addDependency(symbol: Symbol): void { + if (symbol !== this) this._dependencies.add(symbol); + } + + /** + * Marks this symbol as a stub and assigns its canonical symbol. + * + * After calling this, all semantic queries (name, kind, file, + * meta, etc.) should reflect the canonical symbol's values. + * + * @param symbol — The canonical symbol this stub should resolve to. + */ + setCanonical(symbol: Symbol): void { + this._canonical = symbol; + } + + /** + * Marks the symbol as exported from its file. + * + * @param exported — Whether the symbol is exported. + */ + setExported(exported: boolean): void { + this._exported = exported; + } + + /** + * Records file names that re‑export this symbol. + * + * @param list — Source files re‑exporting this symbol. + */ + setExportFrom(list: ReadonlyArray): void { + this._exportFrom = list; + } + + /** + * Assigns the output file this symbol will be emitted into. + * + * This may only be set once. + */ + setFile(file: IFileOut): void { + if (this._file && this._file !== file) { + throw new Error('Symbol is already assigned to a different file.'); + } + this._file = file; + } + + /** + * Assigns the conflict‑resolved final local name for this symbol. + * + * This may only be set once. + */ + setFinalName(name: string): void { + if (this._finalName && this._finalName !== name) { + throw new Error('Symbol finalName has already been resolved.'); + } + this._finalName = name; + } + + /** + * Sets how this symbol should be imported. + * + * @param kind — The import strategy (named/default/namespace). + */ + setImportKind(kind: SymbolImportKind): void { + this._importKind = kind; + } + + /** + * Sets the symbol's kind (class, type, alias, variable, etc.). + * + * @param kind — The new symbol kind. + */ + setKind(kind: SymbolKind): void { + this._kind = kind; + } + + /** + * Updates the intended user‑facing name for this symbol. + * + * @param name — The new name. + */ + setName(name: string): void { + this._name = name; + } + + /** + * Binds the DSL node that defines this symbol. + * + * This may only be set once. + */ + setRootNode(node: ISyntaxNode): void { + if (this._rootNode && this._rootNode !== node) { + throw new Error('Symbol is already bound to a different root DSL node.'); + } + this._rootNode = node; + } + + /** + * Returns a debug‑friendly string representation identifying the symbol. + */ + toString(): string { + return `[Symbol ${this.name}#${this.id}]`; + } +} diff --git a/packages/codegen-core/src/symbols/types.d.ts b/packages/codegen-core/src/symbols/types.d.ts index 572a6cd6f..1c944d4a2 100644 --- a/packages/codegen-core/src/symbols/types.d.ts +++ b/packages/codegen-core/src/symbols/types.d.ts @@ -1,7 +1,20 @@ -import type { ISymbolMeta } from '../extensions/types'; +import type { ISymbolMeta } from '../extensions'; +import type { Symbol } from './symbol'; export type ISymbolIdentifier = number | ISymbolMeta; +export type SymbolImportKind = 'namespace' | 'default' | 'named'; + +export type SymbolKind = + | 'alias' // export { a as a2 } from 'a'; + | 'class' + | 'enum' + | 'function' + | 'interface' + | 'namespace' + | 'type' + | 'var'; + export type ISymbolIn = { /** * Array of file names (without extensions) from which this symbol is re-exported. @@ -27,19 +40,15 @@ export type ISymbolIn = { * * @returns The file path to output the symbol to, or undefined to fallback to default behavior. */ - getFilePath?: (symbol: ISymbolOut) => string | undefined; - /** - * Unique symbol ID. If one is not provided, it will be auto-generated. - */ - readonly id?: number; + getFilePath?: Symbol['getFilePath']; /** * Kind of import if this symbol represents an import. */ - importKind?: 'namespace' | 'default' | 'named'; + importKind?: SymbolImportKind; /** * Kind of symbol. */ - kind?: 'class' | 'function' | 'type'; + kind?: SymbolKind; /** * Arbitrary metadata about the symbol. * @@ -47,23 +56,22 @@ export type ISymbolIn = { */ meta?: ISymbolMeta; /** - * The desired name for the symbol within its file. If there are multiple symbols - * with the same desired name, this might not end up being the actual name. + * The intended, user-facing name of the symbol before any conflict resolution. + * It is **not** guaranteed to be the final emitted name — aliasing may occur if the + * file contains conflicting local identifiers or other symbols with the same intended name. * * @example "UserModel" */ - name?: string; + name: string; /** * Placeholder name for the symbol to be replaced later with the final value. * + * @deprecated * @example "_heyapi_31_" */ readonly placeholder?: string; }; -export type ISymbolOut = Omit & - Pick, 'id' | 'placeholder'>; - export interface ISymbolRegistry { /** * Get a symbol. @@ -71,7 +79,7 @@ export interface ISymbolRegistry { * @param identifier Symbol identifier to reference. * @returns The symbol, or undefined if not found. */ - get(identifier: ISymbolIdentifier): ISymbolOut | undefined; + get(identifier: ISymbolIdentifier): Symbol | undefined; /** * Returns the value associated with a symbol ID. * @@ -105,14 +113,14 @@ export interface ISymbolRegistry { * @param filter Metadata filter to query symbols by. * @returns Array of symbols matching the filter. */ - query(filter: ISymbolMeta): ReadonlyArray; + query(filter: ISymbolMeta): ReadonlyArray; /** * References a symbol. * * @param meta Metadata filter to reference symbol by. * @returns The referenced symbol. */ - reference(meta: ISymbolMeta): ISymbolOut; + reference(meta: ISymbolMeta): Symbol; /** * Register a symbol globally. * @@ -121,13 +129,13 @@ export interface ISymbolRegistry { * @param symbol Symbol to register. * @returns The registered symbol. */ - register(symbol: ISymbolIn): ISymbolOut; + register(symbol: ISymbolIn): Symbol; /** * Get all symbols in the order they were registered. * * @returns Array of all registered symbols, in insert order. */ - registered(): IterableIterator; + registered(): IterableIterator; /** * Sets a value for a symbol by its ID. * diff --git a/packages/codegen-core/src/syntax-node.d.ts b/packages/codegen-core/src/syntax-node.d.ts new file mode 100644 index 000000000..ca04a1bee --- /dev/null +++ b/packages/codegen-core/src/syntax-node.d.ts @@ -0,0 +1,20 @@ +import type { Symbol } from './symbols/symbol'; + +export interface ISyntaxNode { + /** + * Return local names introduced by this node. + */ + getLocalNames(): Iterable; + /** + * Return symbols referenced directly by this node. + */ + getSymbols(): Iterable; + /** + * Rewrite local identifiers based on a rename map. + */ + rewriteIdentifiers(map: Map): void; + /** + * Walk this node and its children with a visitor. + */ + traverse(visitor: (node: ISyntaxNode) => void): void; +} diff --git a/packages/codegen-core/tsconfig.base.json b/packages/codegen-core/tsconfig.base.json index 5afc381fb..23fc13547 100644 --- a/packages/codegen-core/tsconfig.base.json +++ b/packages/codegen-core/tsconfig.base.json @@ -1,6 +1,8 @@ { "compilerOptions": { + "composite": true, "declaration": true, + "declarationMap": true, "esModuleInterop": true, "module": "ESNext", "moduleResolution": "Bundler", diff --git a/packages/codegen-core/tsconfig.json b/packages/codegen-core/tsconfig.json index 89ceb3bfa..2f0d0f571 100644 --- a/packages/codegen-core/tsconfig.json +++ b/packages/codegen-core/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { - "declaration": false, "esModuleInterop": true, "resolveJsonModule": true, "skipLibCheck": true diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts index 49b25b351..f1d1a20c3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts @@ -267,7 +267,7 @@ export const vModelWithDictionary = v.object({ * This is a model with one property containing a circular reference */ export const vModelWithCircularReference: v.GenericSchema = v.object({ - prop: v.optional(v.lazy(() => vModelWithCircularReference)) + prop: v.optional(v.lazy(() => vModelWithCircularReference2)) }); /** diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts index 7d0f29978..300b40b87 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts @@ -343,7 +343,7 @@ export const vDeprecatedModel = v.object({ * This is a model with one property containing a circular reference */ export const vModelWithCircularReference: v.GenericSchema = v.object({ - prop: v.optional(v.lazy(() => vModelWithCircularReference)) + prop: v.optional(v.lazy(() => vModelWithCircularReference2)) }); /** diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/validators/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/validators/valibot.gen.ts index 8a3624bb4..2a9de6da4 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/validators/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/validators/valibot.gen.ts @@ -6,8 +6,8 @@ export const vBaz = v.optional(v.pipe(v.pipe(v.string(), v.regex(/foo\nbar/)), v export const vFoo: v.GenericSchema = v.optional(v.union([v.object({ foo: v.optional(v.pipe(v.string(), v.regex(/^\d{3}-\d{2}-\d{4}$/))), - bar: v.optional(v.lazy(() => vBar)), - baz: v.optional(v.array(v.lazy(() => vFoo))), + bar: v.optional(v.lazy(() => vBar2)), + baz: v.optional(v.array(v.lazy(() => vFoo2))), qux: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0)), 0) }), v.null()]), null); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts index f2c944329..b6a706cae 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts @@ -343,7 +343,7 @@ export const vDeprecatedModel = v.object({ * This is a model with one property containing a circular reference */ export const vModelWithCircularReference: v.GenericSchema = v.object({ - prop: v.optional(v.lazy(() => vModelWithCircularReference)) + prop: v.optional(v.lazy(() => vModelWithCircularReference2)) }); /** diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-circular-ref-2/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-circular-ref-2/valibot.gen.ts index 1dc875c6b..e687e2f6b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-circular-ref-2/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-circular-ref-2/valibot.gen.ts @@ -3,7 +3,7 @@ import * as v from 'valibot'; export const vBar: v.GenericSchema = v.strictObject({ - bar: v.union([v.array(v.lazy(() => vBar)), v.null()]) + bar: v.union([v.array(v.lazy(() => vBar2)), v.null()]) }); export const vFoo = v.strictObject({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-circular-ref/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-circular-ref/valibot.gen.ts index 090aa6a3a..6ce5d2980 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-circular-ref/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-circular-ref/valibot.gen.ts @@ -3,14 +3,14 @@ import * as v from 'valibot'; export const vBar: v.GenericSchema = v.object({ - bar: v.optional(v.array(v.lazy(() => vBar))) + bar: v.optional(v.array(v.lazy(() => vBar2))) }); export const vFoo = v.object({ foo: v.optional(vBar) }); -export const vBaz: v.GenericSchema = v.lazy(() => vQux); +export const vBaz: v.GenericSchema = v.lazy(() => vQux2); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-metadata/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-metadata/valibot.gen.ts index 149a0044b..c238f261c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-metadata/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-metadata/valibot.gen.ts @@ -13,8 +13,8 @@ export const vQux = v.record(v.string(), v.object({ */ export const vFoo: v.GenericSchema = v.optional(v.union([v.object({ foo: v.optional(v.pipe(v.pipe(v.string(), v.regex(/^\d{3}-\d{2}-\d{4}$/)), v.metadata({ description: 'This is foo property.' }))), - bar: v.optional(v.lazy(() => vBar)), - baz: v.optional(v.pipe(v.array(v.lazy(() => vFoo)), v.metadata({ description: 'This is baz property.' }))), + bar: v.optional(v.lazy(() => vBar2)), + baz: v.optional(v.pipe(v.array(v.lazy(() => vFoo4)), v.metadata({ description: 'This is baz property.' }))), qux: v.optional(v.pipe(v.pipe(v.number(), v.integer(), v.gtValue(0)), v.metadata({ description: 'This is qux property.' })), 0) }), v.null()]), null); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-types/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-types/valibot.gen.ts index b5a5dfce3..64eb904ba 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-types/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-types/valibot.gen.ts @@ -13,8 +13,8 @@ export const vQux = v.record(v.string(), v.object({ */ export const vFoo: v.GenericSchema = v.optional(v.union([v.object({ foo: v.optional(v.pipe(v.string(), v.regex(/^\d{3}-\d{2}-\d{4}$/))), - bar: v.optional(v.lazy(() => vBar)), - baz: v.optional(v.array(v.lazy(() => vFoo))), + bar: v.optional(v.lazy(() => vBar2)), + baz: v.optional(v.array(v.lazy(() => vFoo4))), qux: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0)), 0) }), v.null()]), null); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators/valibot.gen.ts index b5a5dfce3..64eb904ba 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators/valibot.gen.ts @@ -13,8 +13,8 @@ export const vQux = v.record(v.string(), v.object({ */ export const vFoo: v.GenericSchema = v.optional(v.union([v.object({ foo: v.optional(v.pipe(v.string(), v.regex(/^\d{3}-\d{2}-\d{4}$/))), - bar: v.optional(v.lazy(() => vBar)), - baz: v.optional(v.array(v.lazy(() => vFoo))), + bar: v.optional(v.lazy(() => vBar2)), + baz: v.optional(v.array(v.lazy(() => vFoo4))), qux: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0)), 0) }), v.null()]), null); diff --git a/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/class/sdk.gen.ts b/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/class/sdk.gen.ts index 18c322e48..2f1bff95d 100644 --- a/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/class/sdk.gen.ts +++ b/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/class/sdk.gen.ts @@ -39,7 +39,7 @@ export class AccountingCompanyMemberships { } public static get api() { - return Api; + return Api2; } } @@ -64,7 +64,7 @@ export class BankAccounts { } public static get api() { - return Api; + return Api2; } } @@ -89,7 +89,7 @@ export class BusinessAccountantAssignments { } public static get api() { - return Api; + return Api2; } } @@ -159,7 +159,7 @@ export class BusinessDocuments { } public static get api() { - return Api; + return Api2; } } @@ -172,7 +172,7 @@ export class BusinessDocumentsSummaries { } public static get api() { - return Api; + return Api2; } } @@ -231,7 +231,7 @@ export class Businesses { } public static get api() { - return Api; + return Api2; } } @@ -241,7 +241,7 @@ export class BusinessSummaries { } public static get api() { - return Api; + return Api2; } } @@ -277,7 +277,7 @@ export class Counterparties { } public static get api() { - return Api; + return Api2; } } @@ -302,7 +302,7 @@ export class DataBoxCredentials { } public static get api() { - return Api; + return Api2; } } @@ -312,7 +312,7 @@ export class DocumentTypes { } public static get api() { - return Api; + return Api2; } } @@ -363,7 +363,7 @@ export class Invitations { } public static get api() { - return Api; + return Api2; } } @@ -418,7 +418,7 @@ export class Invoices { } public static get api() { - return Api; + return Api2; } } @@ -439,7 +439,7 @@ export class InvoiceSettings { } public static get api() { - return Api; + return Api2; } } @@ -449,7 +449,7 @@ export class Licenses { } public static get api() { - return Api; + return Api2; } } @@ -494,7 +494,7 @@ export class PersonalDocuments { } public static get api() { - return Api; + return Api2; } } @@ -530,7 +530,7 @@ export class RecurringTasks { } public static get api() { - return Api; + return Api2; } } @@ -600,7 +600,7 @@ export class Tasks { } public static get api() { - return Api; + return Api2; } } @@ -693,7 +693,7 @@ export class Odata { } public static get accountingCompanies2() { - return AccountingCompanies; + return AccountingCompanies2; } static accountingCompanyMemberships2 = AccountingCompanyMemberships; @@ -735,7 +735,7 @@ export class Odata { export class MapIdentityApi { public static get api() { - return Api; + return Api2; } } diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts index e44daf15b..460a92e52 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts @@ -294,7 +294,7 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts index 99cb26f2e..0105d59cd 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts @@ -293,7 +293,7 @@ export const zModelWithDictionary = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => zModelWithCircularReference2).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts index bc91971e3..c108394b3 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts @@ -294,7 +294,7 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts index 1563aa737..cdd79ae78 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts @@ -4,29 +4,29 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => zQuux2)); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.lazy((): any => zBaz)); + return z.optional(z.lazy((): any => zBaz2)); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => zQuux2)); } }); export const zQux = z.union([ z.intersection(z.object({ type: z.literal('struct') - }), z.lazy(() => z.lazy((): any => zCorge))), + }), z.lazy(() => z.lazy((): any => zCorge2))), z.intersection(z.object({ type: z.literal('array') }), zFoo) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts index b6370f67c..192ec3f4f 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -392,7 +392,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts index cfa348c12..312cc05d2 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts @@ -8,10 +8,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo2))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts index 4caa3fbd4..8a00210b0 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts @@ -3,22 +3,22 @@ import { z } from 'zod'; export const zFoo: z.AnyZodObject = z.object({ - quux: z.lazy(() => zQuux).optional() + quux: z.lazy(() => zQuux2).optional() }); export const zBar: z.AnyZodObject = z.object({ - bar: z.lazy(() => zBar).optional(), - baz: z.lazy(() => zBaz).optional() + bar: z.lazy(() => zBar2).optional(), + baz: z.lazy(() => zBaz2).optional() }); export const zBaz: z.AnyZodObject = z.object({ - quux: z.lazy(() => zQuux).optional() + quux: z.lazy(() => zQuux2).optional() }); export const zQux: z.ZodTypeAny = z.union([ z.object({ type: z.literal('struct') - }).and(z.lazy(() => zCorge)), + }).and(z.lazy(() => zCorge2)), z.object({ type: z.literal('array') }).and(zFoo) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts index e7fb6be96..c4839a4e1 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -391,7 +391,7 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => zModelWithCircularReference2).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts index 9d727f32d..fb3dee2e9 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts @@ -7,8 +7,8 @@ export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo2)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts index 3b9c62d9d..fc6459c19 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts @@ -4,29 +4,29 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => zQuux2)); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.lazy((): any => zBaz)); + return z.optional(z.lazy((): any => zBaz2)); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => zQuux2)); } }); export const zQux = z.union([ z.object({ type: z.literal('struct') - }).and(z.lazy(() => z.lazy((): any => zCorge))), + }).and(z.lazy(() => z.lazy((): any => zCorge2))), z.object({ type: z.literal('array') }).and(zFoo) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts index 3f328c90d..5c2b4db65 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -392,7 +392,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts index 0daf7a0a6..c68523155 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts @@ -8,10 +8,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo2))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts index 7ca3c6f97..c9bcbd41e 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -395,7 +395,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts index 3a8f1806c..d1f109637 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/v4-mini'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => zBar)), + z.array(z.lazy((): any => zBar2)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts index dda5d4694..1a31df18a 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/v4-mini'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => zBar))); + return z.optional(z.array(z.lazy((): any => zBar2))); } }); @@ -12,7 +12,7 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => zQux); +export const zBaz = z.lazy((): any => zQux2); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts index 8ecedac9a..111c93c54 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts @@ -15,10 +15,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts index 789eb6d8a..b81bbff61 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts @@ -17,10 +17,10 @@ export const zFoo = z._default(z.union([ description: 'This is foo property.' })), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { + return z.optional(z.array(z.lazy((): any => zFoo4)).register(z.globalRegistry, { description: 'This is baz property.' })); }, diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts index a8353e832..477ec22ef 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts @@ -19,10 +19,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts index 304d89bb5..6573ca690 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts @@ -15,10 +15,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts index 75782a6a3..811635f69 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -394,7 +394,7 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => zModelWithCircularReference2).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts index f2c188be3..17d8767ab 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zBar: z.AnyZodObject = z.object({ bar: z.union([ - z.array(z.lazy(() => zBar)), + z.array(z.lazy(() => zBar2)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts index d1f4aaa4b..b345598be 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts @@ -3,14 +3,14 @@ import { z } from 'zod'; export const zBar: z.AnyZodObject = z.object({ - bar: z.array(z.lazy(() => zBar)).optional() + bar: z.array(z.lazy(() => zBar2)).optional() }); export const zFoo = z.object({ foo: zBar.optional() }); -export const zBaz: z.ZodTypeAny = z.lazy(() => zQux); +export const zBaz: z.ZodTypeAny = z.lazy(() => zQux2); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts index c9317d591..c95401299 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts @@ -14,8 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo4)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts index 58ea4d7b8..b6145c9a6 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts @@ -14,8 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe('This is foo property.').optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).describe('This is baz property.').optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo4)).describe('This is baz property.').optional(), qux: z.number().int().gt(0).describe('This is qux property.').optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts index c26d40cf3..a212842ca 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts @@ -18,8 +18,8 @@ export type QuxZodType = z.infer; export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo4)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts index 8e5318a8c..b1c07a86e 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts @@ -14,8 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo4)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts index 445c9f103..ad62250b4 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -395,7 +395,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts index 0560094fd..ee8197c49 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v4'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => zBar)), + z.array(z.lazy((): any => zBar2)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts index 7bd218fcb..f79413d94 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v4'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => zBar))); + return z.optional(z.array(z.lazy((): any => zBar2))); } }); @@ -12,7 +12,7 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => zQux); +export const zBaz = z.lazy((): any => zQux2); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts index 5781d917f..112a30355 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts @@ -15,10 +15,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts index c3c88f810..2e20f5b8e 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts @@ -17,10 +17,10 @@ export const zFoo = z.union([ description: 'This is foo property.' })), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { + return z.optional(z.array(z.lazy((): any => zFoo4)).register(z.globalRegistry, { description: 'This is baz property.' })); }, diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts index b2d4ca717..8813506b6 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts @@ -19,10 +19,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts index 15238b2a7..6601c24f4 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts @@ -15,10 +15,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts index e00616a4b..2620039bd 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts @@ -294,7 +294,7 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts index 93c84d92c..5f6638135 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts @@ -293,7 +293,7 @@ export const zModelWithDictionary = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => zModelWithCircularReference2).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts index f2848ba82..6f19e6c24 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts @@ -294,7 +294,7 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts index 7cced9697..d96af8123 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts @@ -4,29 +4,29 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => zQuux2)); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.lazy((): any => zBaz)); + return z.optional(z.lazy((): any => zBaz2)); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => zQuux2)); } }); export const zQux = z.union([ z.intersection(z.object({ type: z.literal('struct') - }), z.lazy(() => z.lazy((): any => zCorge))), + }), z.lazy(() => z.lazy((): any => zCorge2))), z.intersection(z.object({ type: z.literal('array') }), zFoo) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts index 9734ab8f1..9506b878d 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -392,7 +392,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts index 7a5c78486..a41e99873 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts @@ -8,10 +8,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo2))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts index 89c43bbd9..75646c4eb 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts @@ -3,22 +3,22 @@ import { z } from 'zod/v3'; export const zFoo: z.AnyZodObject = z.object({ - quux: z.lazy(() => zQuux).optional() + quux: z.lazy(() => zQuux2).optional() }); export const zBar: z.AnyZodObject = z.object({ - bar: z.lazy(() => zBar).optional(), - baz: z.lazy(() => zBaz).optional() + bar: z.lazy(() => zBar2).optional(), + baz: z.lazy(() => zBaz2).optional() }); export const zBaz: z.AnyZodObject = z.object({ - quux: z.lazy(() => zQuux).optional() + quux: z.lazy(() => zQuux2).optional() }); export const zQux: z.ZodTypeAny = z.union([ z.object({ type: z.literal('struct') - }).and(z.lazy(() => zCorge)), + }).and(z.lazy(() => zCorge2)), z.object({ type: z.literal('array') }).and(zFoo) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts index dc5b79a54..3fbd59e4e 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -391,7 +391,7 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => zModelWithCircularReference2).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts index bdddc5775..ebbe71b83 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts @@ -7,8 +7,8 @@ export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo2)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts index 8da477654..00911017c 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts @@ -4,29 +4,29 @@ import { z } from 'zod'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => zQuux2)); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.lazy((): any => zBaz)); + return z.optional(z.lazy((): any => zBaz2)); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => zQuux2)); } }); export const zQux = z.union([ z.object({ type: z.literal('struct') - }).and(z.lazy(() => z.lazy((): any => zCorge))), + }).and(z.lazy(() => z.lazy((): any => zCorge2))), z.object({ type: z.literal('array') }).and(zFoo) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts index 925cc7bf2..9d4c97f48 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -392,7 +392,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts index 944f96e47..adde4f7f0 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts @@ -8,10 +8,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo2))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts index 45ebeaf53..84828113f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -395,7 +395,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts index 6014595af..4ed3f70ef 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/mini'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => zBar)), + z.array(z.lazy((): any => zBar2)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts index ee8b0c76e..39b46eb56 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/mini'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => zBar))); + return z.optional(z.array(z.lazy((): any => zBar2))); } }); @@ -12,7 +12,7 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => zQux); +export const zBaz = z.lazy((): any => zQux2); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts index 9ac32990c..ceb1549b4 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts @@ -15,10 +15,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts index e263d218e..fb296fd0d 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts @@ -17,10 +17,10 @@ export const zFoo = z._default(z.union([ description: 'This is foo property.' })), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { + return z.optional(z.array(z.lazy((): any => zFoo4)).register(z.globalRegistry, { description: 'This is baz property.' })); }, diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts index 669174c0a..65fbcd47c 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts @@ -19,10 +19,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts index b786abd75..62cbdbe1b 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts @@ -15,10 +15,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts index 6d118b7c7..3fe7311bf 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -394,7 +394,7 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => zModelWithCircularReference2).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts index 4d47e4d61..fa92f18d5 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v3'; export const zBar: z.AnyZodObject = z.object({ bar: z.union([ - z.array(z.lazy(() => zBar)), + z.array(z.lazy(() => zBar2)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts index 02708822c..402e1414b 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts @@ -3,14 +3,14 @@ import { z } from 'zod/v3'; export const zBar: z.AnyZodObject = z.object({ - bar: z.array(z.lazy(() => zBar)).optional() + bar: z.array(z.lazy(() => zBar2)).optional() }); export const zFoo = z.object({ foo: zBar.optional() }); -export const zBaz: z.ZodTypeAny = z.lazy(() => zQux); +export const zBaz: z.ZodTypeAny = z.lazy(() => zQux2); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts index 68a0a720f..bee23c297 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts @@ -14,8 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo4)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts index 10af4babe..e2ef988c4 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts @@ -14,8 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe('This is foo property.').optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).describe('This is baz property.').optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo4)).describe('This is baz property.').optional(), qux: z.number().int().gt(0).describe('This is qux property.').optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts index 2b0fa9eed..f837d12dd 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts @@ -18,8 +18,8 @@ export type QuxZodType = z.infer; export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo4)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts index 15850f6a2..9ebcd26ae 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts @@ -14,8 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => zBar2).optional(), + baz: z.array(z.lazy(() => zFoo4)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts index d490dd142..088a5b89e 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -395,7 +395,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => zModelWithCircularReference2)); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts index 696338aab..26841bbb9 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => zBar)), + z.array(z.lazy((): any => zBar2)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts index b62812954..9c5d6dae6 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => zBar))); + return z.optional(z.array(z.lazy((): any => zBar2))); } }); @@ -12,7 +12,7 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => zQux); +export const zBaz = z.lazy((): any => zQux2); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts index 515d9ad8b..3ce85de8f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts @@ -15,10 +15,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts index 995ccdb8a..35bbb17e8 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts @@ -17,10 +17,10 @@ export const zFoo = z.union([ description: 'This is foo property.' })), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { + return z.optional(z.array(z.lazy((): any => zFoo4)).register(z.globalRegistry, { description: 'This is baz property.' })); }, diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts index 033e85ced..c7065d54c 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts @@ -19,10 +19,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts index f73a35bac..e5188fb7f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts @@ -15,10 +15,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => zBar2)); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => zFoo4))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts/src/generate/__tests__/renderer.test.ts b/packages/openapi-ts/src/generate/__tests__/renderer.test.ts index f9bf7bc89..a6a1b1081 100644 --- a/packages/openapi-ts/src/generate/__tests__/renderer.test.ts +++ b/packages/openapi-ts/src/generate/__tests__/renderer.test.ts @@ -5,16 +5,16 @@ import { TypeScriptRenderer } from '../renderer'; // Minimal local BiMap for tests to avoid importing runtime-only class class LocalBiMap { private map = new Map(); - private reverse = new Map(); + private reverse = new Map>(); get(key: Key) { return this.map.get(key); } - getKey(value: Value) { + getKeys(value: Value) { return this.reverse.get(value); } set(key: Key, value: Value) { this.map.set(key, value); - this.reverse.set(value, key); + this.reverse.set(value, new Set([key])); return this; } hasValue(value: Value) { diff --git a/packages/openapi-ts/src/generate/renderer.ts b/packages/openapi-ts/src/generate/renderer.ts index 26c802a48..b163bbb48 100644 --- a/packages/openapi-ts/src/generate/renderer.ts +++ b/packages/openapi-ts/src/generate/renderer.ts @@ -1,7 +1,6 @@ import path from 'node:path'; import type { - BiMap, Binding, File, IProject, @@ -491,12 +490,46 @@ export class TypeScriptRenderer implements Renderer { return lines; } - private getUniqueName(base: string, names: BiMap): string { - let index = 2; - let name = base; - while (names.hasValue(name)) { - name = `${base}${index}`; - index += 1; + private getUniqueName({ + base, + file, + index, + project, + symbol, + }: { + base: string; + file: File; + index: number; + project: IProject; + symbol: Symbol; + }): string { + let name = index > 1 ? `${base}${index}` : base; + if (!file.resolvedNames.hasValue(name)) { + return name; + } + const conflictIds = file.resolvedNames.getKeys(name) ?? new Set(); + const conflictSymbols = [...conflictIds] + .map((id) => project.symbols.get(id)) + .filter((s): s is NonNullable => s !== undefined); + if (conflictSymbols.length > 0) { + const conflictKinds = conflictSymbols.map((s) => s.kind); + // avoid conflicts between class and type of the same name + if ( + (symbol.kind === 'type' && + (conflictKinds.includes('type') || + conflictKinds.includes('class'))) || + (symbol.kind !== 'type' && + conflictKinds.some((kind) => kind !== 'type')) || + (symbol.kind === 'class' && conflictKinds.includes('type')) + ) { + name = this.getUniqueName({ + base, + file, + index: index + 1, + project, + symbol, + }); + } } return name; } @@ -516,22 +549,13 @@ export class TypeScriptRenderer implements Renderer { if (!symbol.name) return; const [symbolFile] = project.symbolIdToFiles(symbol.id); const symbolFileResolvedName = symbolFile?.resolvedNames.get(symbol.id); - let name = ensureValidIdentifier(symbolFileResolvedName ?? symbol.name); - const conflictId = file.resolvedNames.getKey(name); - if (conflictId !== undefined) { - const conflictSymbol = project.symbols.get(conflictId); - if (conflictSymbol) { - const kinds = [conflictSymbol.kind, symbol.kind]; - if ( - kinds.every((kind) => kind === 'type') || - kinds.every((kind) => kind !== 'type') || - // avoid conflicts between class and type of the same name - (kinds.includes('class') && kinds.includes('type')) - ) { - name = this.getUniqueName(name, file.resolvedNames); - } - } - } + const name = this.getUniqueName({ + base: ensureValidIdentifier(symbolFileResolvedName ?? symbol.name), + file, + index: 1, + project, + symbol, + }); file.resolvedNames.set(symbol.id, name); return name; } diff --git a/packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts b/packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts index 1da2efb65..c1d9b5dec 100644 --- a/packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts +++ b/packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts @@ -133,7 +133,6 @@ const generateAngularClassRequests = ({ resource: '@angular/core.Injectable', }); const symbolClass = plugin.registerSymbol({ - exported: true, meta: { category: 'utility', resource: 'class', @@ -148,11 +147,11 @@ const generateAngularClassRequests = ({ name: currentClass.className, }), }); - const node = $.class(symbolClass.placeholder) - .export(symbolClass.exported) + const node = $.class(symbolClass) + .export() .$if(currentClass.root, (c) => c.decorator( - symbolInjectable.placeholder, + symbolInjectable, $.object().prop('providedIn', $.literal('root')), ), ) @@ -181,7 +180,6 @@ const generateAngularFunctionRequests = ({ }); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'utility', resource: 'operation', @@ -269,10 +267,10 @@ const generateAngularRequestMethod = ({ .param('options', (p) => p .required(isRequiredOptions) - .type(`${symbolOptions.placeholder}<${dataType}, ThrowOnError>`), + .type($.type(symbolOptions).generic(dataType).generic('ThrowOnError')), ) .generic('ThrowOnError', (g) => g.extends('boolean').default(false)) - .returns(`${symbolHttpRequest.placeholder}`) + .returns($.type(symbolHttpRequest).generic('unknown')) .do( $.return( generateRequestCallExpression({ @@ -314,18 +312,20 @@ const generateAngularRequestFunction = ({ }); const dataType = symbolDataType?.placeholder || 'unknown'; - return $.const(symbol.placeholder) - .export(symbol.exported) + return $.const(symbol) + .export() .$if(createOperationComment(operation), (c, v) => c.doc(v)) .assign( $.func() .param('options', (p) => p .required(isRequiredOptions) - .type(`${symbolOptions.placeholder}<${dataType}, ThrowOnError>`), + .type( + $.type(symbolOptions).generic(dataType).generic('ThrowOnError'), + ), ) .generic('ThrowOnError', (g) => g.extends('boolean').default(false)) - .returns(`${symbolHttpRequest.placeholder}`) + .returns($.type(symbolHttpRequest).generic('unknown')) .do( $.return( generateRequestCallExpression({ diff --git a/packages/openapi-ts/src/plugins/@angular/common/httpResources.ts b/packages/openapi-ts/src/plugins/@angular/common/httpResources.ts index be5ecd8ec..92960cf27 100644 --- a/packages/openapi-ts/src/plugins/@angular/common/httpResources.ts +++ b/packages/openapi-ts/src/plugins/@angular/common/httpResources.ts @@ -136,7 +136,6 @@ const generateAngularClassServices = ({ resource: '@angular/core.Injectable', }); const symbolClass = plugin.registerSymbol({ - exported: true, name: buildName({ config: { case: 'preserve', @@ -145,11 +144,11 @@ const generateAngularClassServices = ({ name: currentClass.className, }), }); - const node = $.class(symbolClass.placeholder) - .export(symbolClass.exported) + const node = $.class(symbolClass) + .export() .$if(currentClass.root, (c) => c.decorator( - symbolInjectable.placeholder, + symbolInjectable, $.object().prop('providedIn', $.literal('root')), ), ) @@ -178,7 +177,6 @@ const generateAngularFunctionServices = ({ }); const symbol = plugin.registerSymbol({ - exported: true, name: plugin.config.httpResources.methodNameBuilder(operation), }); const node = generateAngularResourceFunction({ @@ -387,8 +385,8 @@ const generateAngularResourceFunction = ({ }); const dataType = symbolDataType?.placeholder || 'unknown'; - return $.const(symbol.placeholder) - .export(symbol.exported) + return $.const(symbol) + .export() .$if(createOperationComment(operation), (c, v) => c.doc(v)) .assign( $.func() diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts b/packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts index 70a5710a9..398ab7b44 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts @@ -85,14 +85,13 @@ export const createClient: PluginHandler = ({ plugin }) => { ]; const symbolClient = plugin.registerSymbol({ - exported: true, meta: { category: 'client', }, name: 'client', }); - const statement = $.const(symbolClient.placeholder) - .export(symbolClient.exported) + const statement = $.const(symbolClient) + .export() .assign( $(symbolCreateClient.placeholder).$if( symbolCreateClientConfig, diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts b/packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts index 6e7529554..fa5447282 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts @@ -23,14 +23,12 @@ export const createClientConfigType = ({ name: 'ClientOptions', }); const symbolCreateClientConfig = plugin.registerSymbol({ - exported: true, - kind: 'type', name: 'CreateClientConfig', }); const typeCreateClientConfig = $.type - .alias(symbolCreateClientConfig.placeholder) - .export(symbolCreateClientConfig.exported) + .alias(symbolCreateClientConfig) + .export() .doc([ 'The `createClientConfig()` function will be called on client initialization', "and the returned object will become the client's initial configuration.", diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts index 349c4c69c..d62d62780 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts @@ -369,7 +369,6 @@ const schemasV2_0_X = ({ for (const name in context.spec.definitions) { const schema = context.spec.definitions[name]!; const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', resource: 'definition', @@ -383,8 +382,8 @@ const schemasV2_0_X = ({ plugin, schema, }); - const statement = $.const(symbol.placeholder) - .export(symbol.exported) + const statement = $.const(symbol) + .export() .assign( $( $.fromValue(obj, { @@ -410,7 +409,6 @@ const schemasV3_0_X = ({ for (const name in context.spec.components.schemas) { const schema = context.spec.components.schemas[name]!; const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', resource: 'definition', @@ -424,8 +422,8 @@ const schemasV3_0_X = ({ plugin, schema, }); - const statement = $.const(symbol.placeholder) - .export(symbol.exported) + const statement = $.const(symbol) + .export() .assign( $( $.fromValue(obj, { @@ -451,7 +449,6 @@ const schemasV3_1_X = ({ for (const name in context.spec.components.schemas) { const schema = context.spec.components.schemas[name]!; const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', resource: 'definition', @@ -465,8 +462,8 @@ const schemasV3_1_X = ({ plugin, schema, }); - const statement = $.const(symbol.placeholder) - .export(symbol.exported) + const statement = $.const(symbol) + .export() .assign( $( $.fromValue(obj, { diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts index 6e607ad8f..dbb572377 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts @@ -56,8 +56,7 @@ const createRegistryClass = ({ }): TsDsl => { const defaultKey = 'defaultKey'; const instances = 'instances'; - return $.class(symbol.placeholder) - .export(symbol.exported) + return $.class(symbol) .generic('T') .field(defaultKey, (f) => f.private().readonly().assign($.literal('default')), @@ -122,8 +121,7 @@ const createClientClass = ({ category: 'external', resource: 'client.Client', }); - return $.class(symbol.placeholder) - .export(symbol.exported) + return $.class(symbol) .field('client', (f) => f.protected().type(symbolClient.placeholder)) .newline() .init((i) => @@ -311,8 +309,6 @@ export const generateClassSdk = ({ const symbolHeyApiClient = plugin.config.instance ? plugin.registerSymbol({ - exported: false, - kind: 'class', meta: { category: 'utility', resource: 'class', @@ -324,8 +320,6 @@ export const generateClassSdk = ({ : undefined; const symbolHeyApiRegistry = plugin.config.instance ? plugin.registerSymbol({ - exported: false, - kind: 'class', meta: { category: 'utility', resource: 'class', @@ -420,8 +414,6 @@ export const generateClassSdk = ({ } const symbol = plugin.registerSymbol({ - exported: true, - kind: 'class', meta: { category: 'utility', resource: 'class', @@ -485,15 +477,15 @@ export const generateClassSdk = ({ currentClass.nodes.unshift(registryNode, $.newline()); } - const node = $.class(symbol.placeholder) - .export(symbol.exported) - .extends(symbolHeyApiClient?.placeholder) + const node = $.class(symbol) + .export() + .extends(symbolHeyApiClient) .$if(currentClass.root && isAngularClient, (c) => c.decorator( plugin.referenceSymbol({ category: 'external', resource: '@angular/core.Injectable', - }).placeholder, + }), $.object().prop('providedIn', $.literal('root')), ), ) diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/functions.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/functions.ts index eefe826ad..51f662890 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/functions.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/functions.ts @@ -67,7 +67,6 @@ export const generateFlatSdk = ({ plugin, }); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'sdk', path: event._path, @@ -82,8 +81,8 @@ export const generateFlatSdk = ({ plugin, }), }); - const node = $.const(symbol.placeholder) - .export(symbol.exported) + const node = $.const(symbol) + .export() .$if(createOperationComment(operation), (c, v) => c.doc(v)) .assign( $.func() diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/typeOptions.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/typeOptions.ts index af87dda6f..ed1e67dba 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/typeOptions.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/typeOptions.ts @@ -35,8 +35,6 @@ export const createTypeOptions = ({ name: 'Options', }); const symbolOptions = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', resource: 'client-options', @@ -46,8 +44,8 @@ export const createTypeOptions = ({ }); const typeOptions = $.type - .alias(symbolOptions.placeholder) - .export(symbolOptions.exported) + .alias(symbolOptions) + .export() .$if( isNuxtClient, (t) => diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts index 63563223c..c4c529ca8 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts @@ -337,7 +337,6 @@ export const handler: HeyApiTransformersPlugin['Handler'] = ({ plugin }) => { }); if (!nodes.length) return; const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'transform', resource: 'operation', @@ -352,8 +351,8 @@ export const handler: HeyApiTransformersPlugin['Handler'] = ({ plugin }) => { name: operation.id, }), }); - const value = $.const(symbol.placeholder) - .export(symbol.exported) + const value = $.const(symbol) + .export() .assign( // TODO: parser - add types, generate types without transforms $.func() diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/clientOptions.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/clientOptions.ts index 8c135d309..41d48dbae 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/clientOptions.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/clientOptions.ts @@ -51,8 +51,8 @@ export const createClientOptions = ({ } const node = $.type - .alias(symbolClientOptions.placeholder) - .export(symbolClientOptions.exported) + .alias(symbolClientOptions) + .export() .type( $.type .object() diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/export.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/export.ts index 21cf65a2f..10c325d4e 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/export.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/export.ts @@ -1,13 +1,14 @@ -import type { Symbol } from '@hey-api/codegen-core'; - import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; import { createSchemaComment } from '~/plugins/shared/utils/schema'; import type { MaybeTsDsl, TypeTsDsl } from '~/ts-dsl'; import { $ } from '~/ts-dsl'; +import { pathToJsonPointer, refToName } from '~/utils/ref'; import { numberRegExp } from '~/utils/regexp'; import { stringCase } from '~/utils/stringCase'; import type { HeyApiTypeScriptPlugin } from '../types'; +import type { IrSchemaToAstOptions } from './types'; const schemaToEnumObject = ({ plugin, @@ -83,14 +84,14 @@ const schemaToEnumObject = ({ export const exportType = ({ plugin, schema, - symbol, + state, type, -}: { - plugin: HeyApiTypeScriptPlugin['Instance']; +}: IrSchemaToAstOptions & { schema: IR.SchemaObject; - symbol: Symbol; type: MaybeTsDsl; }) => { + const $ref = pathToJsonPointer(state.path.value); + // root enums have an additional export if (schema.type === 'enum' && plugin.config.enums.enabled) { const enumObject = schemaToEnumObject({ plugin, schema }); @@ -106,7 +107,21 @@ export const exportType = ({ ); } - const objectNode = $.const(symbol.placeholder) + const symbolObject = plugin.registerSymbol({ + meta: { + category: 'utility', + path: state.path.value, + resource: 'definition', + resourceId: $ref, + tags: state.tags?.value, + tool: 'typescript', + }, + name: buildName({ + config: plugin.config.definitions, + name: refToName($ref), + }), + }); + const objectNode = $.const(symbolObject) .export() .$if(createSchemaComment(schema), (c, v) => c.doc(v)) .assign( @@ -118,17 +133,28 @@ export const exportType = ({ ), ).as('const'), ); + plugin.setSymbolValue(symbolObject, objectNode); + const symbol = plugin.registerSymbol({ + meta: { + category: 'type', + path: state.path.value, + resource: 'definition', + resourceId: $ref, + tags: state.tags?.value, + tool: 'typescript', + }, + name: buildName({ + config: plugin.config.definitions, + name: refToName($ref), + }), + }); const node = $.type - .alias(symbol.placeholder) + .alias(symbol) .export() .$if(createSchemaComment(schema), (t, v) => t.doc(v)) - .type( - $.type(symbol.placeholder) - .idx($.type(symbol.placeholder).typeof().keyof()) - .typeof(), - ); - plugin.setSymbolValue(symbol, [objectNode, node]); + .type($.type(symbol).idx($.type(symbol).typeof().keyof()).typeof()); + plugin.setSymbolValue(symbol, node); return; } else if ( plugin.config.enums.mode === 'typescript' || @@ -139,7 +165,21 @@ export const exportType = ({ (type) => type !== 'number' && type !== 'string', ); if (shouldCreateTypeScriptEnum) { - const enumNode = $.enum(symbol.placeholder) + const symbol = plugin.registerSymbol({ + meta: { + category: 'type', + path: state.path.value, + resource: 'definition', + resourceId: $ref, + tags: state.tags?.value, + tool: 'typescript', + }, + name: buildName({ + config: plugin.config.definitions, + name: refToName($ref), + }), + }); + const enumNode = $.enum(symbol) .export() .$if(createSchemaComment(schema), (e, v) => e.doc(v)) .const(plugin.config.enums.mode === 'typescript-const') @@ -156,9 +196,23 @@ export const exportType = ({ } } + const symbol = plugin.registerSymbol({ + meta: { + category: 'type', + path: state.path.value, + resource: 'definition', + resourceId: $ref, + tags: state.tags?.value, + tool: 'typescript', + }, + name: buildName({ + config: plugin.config.definitions, + name: refToName($ref), + }), + }); const node = $.type - .alias(symbol.placeholder) - .export(symbol.exported) + .alias(symbol) + .export() .$if(createSchemaComment(schema), (t, v) => t.doc(v)) .type(type); plugin.setSymbolValue(symbol, node); diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/operation.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/operation.ts index 8dec4b950..4f81c2196 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/operation.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/operation.ts @@ -121,8 +121,6 @@ const operationToDataType = ({ data.required = dataRequired; const symbol = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, @@ -138,8 +136,8 @@ const operationToDataType = ({ }), }); const node = $.type - .alias(symbol.placeholder) - .export(symbol.exported) + .alias(symbol) + .export() .type( irSchemaToAst({ plugin, @@ -164,8 +162,6 @@ export const operationToType = ({ if (errors) { const symbolErrors = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, @@ -181,8 +177,8 @@ export const operationToType = ({ }), }); const node = $.type - .alias(symbolErrors.placeholder) - .export(symbolErrors.exported) + .alias(symbolErrors) + .export() .type( irSchemaToAst({ plugin, @@ -194,8 +190,6 @@ export const operationToType = ({ if (error) { const symbol = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, @@ -214,8 +208,8 @@ export const operationToType = ({ }), }); const node = $.type - .alias(symbol.placeholder) - .export(symbol.exported) + .alias(symbol) + .export() .type( $.type(symbolErrors.placeholder).idx( $.type(symbolErrors.placeholder).keyof(), @@ -227,8 +221,6 @@ export const operationToType = ({ if (responses) { const symbolResponses = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, @@ -244,8 +236,8 @@ export const operationToType = ({ }), }); const node = $.type - .alias(symbolResponses.placeholder) - .export(symbolResponses.exported) + .alias(symbolResponses) + .export() .type( irSchemaToAst({ plugin, @@ -257,8 +249,6 @@ export const operationToType = ({ if (response) { const symbol = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, @@ -277,8 +267,8 @@ export const operationToType = ({ }), }); const node = $.type - .alias(symbol.placeholder) - .export(symbol.exported) + .alias(symbol) + .export() .type( $.type(symbolResponses.placeholder).idx( $.type(symbolResponses.placeholder).keyof(), diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhook.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhook.ts index a4a0e3518..d50b96308 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhook.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhook.ts @@ -24,8 +24,6 @@ const operationToDataType = ({ if (operation.body) { const symbolWebhookPayload = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, @@ -44,8 +42,8 @@ const operationToDataType = ({ }), }); const node = $.type - .alias(symbolWebhookPayload.placeholder) - .export(symbolWebhookPayload.exported) + .alias(symbolWebhookPayload) + .export() .$if(createSchemaComment(operation.body.schema), (t, v) => t.doc(v)) .type( irSchemaToAst({ @@ -88,8 +86,6 @@ const operationToDataType = ({ data.required = dataRequired; const symbolWebhookRequest = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, @@ -105,8 +101,8 @@ const operationToDataType = ({ }), }); const node = $.type - .alias(symbolWebhookRequest.placeholder) - .export(symbolWebhookRequest.exported) + .alias(symbolWebhookRequest) + .export() .type( irSchemaToAst({ plugin, diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhooks.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhooks.ts index 08f22cd11..81bd4e4f9 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhooks.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhooks.ts @@ -16,8 +16,8 @@ export const createWebhooks = ({ if (!webhookNames.length) return; const node = $.type - .alias(symbolWebhooks.placeholder) - .export(symbolWebhooks.exported) + .alias(symbolWebhooks) + .export() .type($.type.or(...webhookNames)); plugin.setSymbolValue(symbolWebhooks, node); }; diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/v1/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/v1/plugin.ts index f677cf41b..4754a671e 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/v1/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/v1/plugin.ts @@ -5,7 +5,6 @@ import type { SchemaWithType } from '~/plugins'; import { toRefs } from '~/plugins/shared/utils/refs'; import type { MaybeTsDsl, TypeTsDsl } from '~/ts-dsl'; import { $ } from '~/ts-dsl'; -import { pathToJsonPointer, refToName } from '~/utils/ref'; import { createClientOptions } from '../shared/clientOptions'; import { exportType } from '../shared/export'; @@ -29,7 +28,7 @@ export const irSchemaToAst = ({ resource: 'definition', resourceId: schema.$ref, }); - return $.type(symbol.placeholder); + return $.type(symbol); } if (schema.type) { @@ -72,31 +71,10 @@ const handleComponent = ({ schema: IR.SchemaObject; }) => { const type = irSchemaToAst({ plugin, schema, state }); - - // Don't tag enums as 'type' since they export runtime artifacts (values) - const isEnum = schema.type === 'enum' && plugin.config.enums.enabled; - - const $ref = pathToJsonPointer(state.path.value); - const symbol = plugin.registerSymbol({ - exported: true, - kind: isEnum ? undefined : 'type', - meta: { - category: 'type', - path: state.path.value, - resource: 'definition', - resourceId: $ref, - tags: state.tags?.value, - tool: 'typescript', - }, - name: buildName({ - config: plugin.config.definitions, - name: refToName($ref), - }), - }); exportType({ plugin, schema, - symbol, + state, type, }); }; @@ -104,8 +82,6 @@ const handleComponent = ({ export const handlerV1: HeyApiTypeScriptPlugin['Handler'] = ({ plugin }) => { // reserve identifier for ClientOptions const symbolClientOptions = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', resource: 'client', @@ -121,8 +97,6 @@ export const handlerV1: HeyApiTypeScriptPlugin['Handler'] = ({ plugin }) => { }); // reserve identifier for Webhooks const symbolWebhooks = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', resource: 'webhook', diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/v1/toAst/string.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/v1/toAst/string.ts index a9f13fa0c..a3208ad27 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/v1/toAst/string.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/v1/toAst/string.ts @@ -50,14 +50,12 @@ export const stringToAst = ({ if (!plugin.getSymbol(queryTypeId)) { const symbolTypeId = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: queryTypeId, name: 'TypeID', }); const nodeTypeId = $.type - .alias(symbolTypeId.placeholder) - .export(symbolTypeId.exported) + .alias(symbolTypeId) + .export() .generic('T', (g) => g.extends('string')) .type( $.type.template().add($.type('T')).add('_').add($.type('string')), @@ -67,8 +65,6 @@ export const stringToAst = ({ const symbolTypeId = plugin.referenceSymbol(queryTypeId); const symbolTypeName = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: query, name: stringCase({ case: plugin.config.case, @@ -76,8 +72,8 @@ export const stringToAst = ({ }), }); const node = $.type - .alias(symbolTypeName.placeholder) - .export(symbolTypeName.exported) + .alias(symbolTypeName) + .export() .type($.type(symbolTypeId.placeholder).generic($.type.literal(type))); plugin.setSymbolValue(symbolTypeName, node); } diff --git a/packages/openapi-ts/src/plugins/@pinia/colada/mutationOptions.ts b/packages/openapi-ts/src/plugins/@pinia/colada/mutationOptions.ts index 843544c70..e5c30310a 100644 --- a/packages/openapi-ts/src/plugins/@pinia/colada/mutationOptions.ts +++ b/packages/openapi-ts/src/plugins/@pinia/colada/mutationOptions.ts @@ -72,14 +72,13 @@ export const createMutationOptions = ({ o.prop('meta', v), ); const symbolMutationOptions = plugin.registerSymbol({ - exported: true, name: buildName({ config: plugin.config.mutationOptions, name: operation.id, }), }); - const statement = $.const(symbolMutationOptions.placeholder) - .export(symbolMutationOptions.exported) + const statement = $.const(symbolMutationOptions) + .export() .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v), ) diff --git a/packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts b/packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts index 444c95124..097f87aca 100644 --- a/packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts +++ b/packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts @@ -66,7 +66,7 @@ export const createQueryKeyFunction = ({ name: 'serializeQueryKeyValue', }); - const fn = $.const(symbolCreateQueryKey.placeholder).assign( + const fn = $.const(symbolCreateQueryKey).assign( $.func() .param('id', (p) => p.type('string')) .param('options', (p) => p.optional().type(TOptionsType)) @@ -163,8 +163,6 @@ export const createQueryKeyType = ({ tool: 'sdk', }); const symbolQueryKeyType = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', resource: 'QueryKey', @@ -173,8 +171,8 @@ export const createQueryKeyType = ({ name: 'QueryKey', }); const queryKeyType = $.type - .alias(symbolQueryKeyType.placeholder) - .export(symbolQueryKeyType.exported) + .alias(symbolQueryKeyType) + .export() .generic(TOptionsType, (g) => g.extends($.type(symbolOptions.placeholder))) .type( $.type.tuple( @@ -210,8 +208,8 @@ export const queryKeyStatement = ({ }) => { const typeData = useTypeData({ operation, plugin }); const { strippedTypeData } = getPublicTypeData({ plugin, typeData }); - const statement = $.const(symbol.placeholder) - .export(symbol.exported) + const statement = $.const(symbol) + .export() .assign( $.func() .param('options', (p) => diff --git a/packages/openapi-ts/src/plugins/@pinia/colada/queryOptions.ts b/packages/openapi-ts/src/plugins/@pinia/colada/queryOptions.ts index 54d553926..c837637e5 100644 --- a/packages/openapi-ts/src/plugins/@pinia/colada/queryOptions.ts +++ b/packages/openapi-ts/src/plugins/@pinia/colada/queryOptions.ts @@ -51,7 +51,6 @@ export const createQueryOptions = ({ let keyExpression: ReturnType; if (plugin.config.queryKeys.enabled) { const symbolQueryKey = plugin.registerSymbol({ - exported: true, name: buildName({ config: plugin.config.queryKeys, name: operation.id, @@ -125,7 +124,6 @@ export const createQueryOptions = ({ ); const symbolQueryOptionsFn = plugin.registerSymbol({ - exported: true, meta: { category: 'hook', resource: 'operation', @@ -142,8 +140,8 @@ export const createQueryOptions = ({ category: 'external', resource: `${plugin.name}.defineQueryOptions`, }); - const statement = $.const(symbolQueryOptionsFn.placeholder) - .export(symbolQueryOptionsFn.exported) + const statement = $.const(symbolQueryOptionsFn) + .export() .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v), ) diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts index f4aaa51ff..11528dbfb 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts @@ -53,7 +53,7 @@ export const createQueryKeyFunction = ({ .generic(TOptionsType) .idx(0); - const fn = $.const(symbolCreateQueryKey.placeholder).assign( + const fn = $.const(symbolCreateQueryKey).assign( $.func() .param('id', (p) => p.type('string')) .param('options', (p) => p.optional().type(TOptionsType)) @@ -132,8 +132,6 @@ export const createQueryKeyType = ({ plugin }: { plugin: PluginInstance }) => { tool: 'sdk', }); const symbolQueryKeyType = plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', resource: 'QueryKey', @@ -142,8 +140,8 @@ export const createQueryKeyType = ({ plugin }: { plugin: PluginInstance }) => { name: 'QueryKey', }); const queryKeyType = $.type - .alias(symbolQueryKeyType.placeholder) - .export(symbolQueryKeyType.exported) + .alias(symbolQueryKeyType) + .export() .generic(TOptionsType, (g) => g.extends(symbolOptions.placeholder)) .type( $.type.tuple( @@ -176,8 +174,8 @@ export const queryKeyStatement = ({ typeQueryKey?: string; }) => { const typeData = useTypeData({ operation, plugin }); - const statement = $.const(symbol.placeholder) - .export(symbol.exported) + const statement = $.const(symbol) + .export() .assign( $.func() .param('options', (p) => diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts index e958e3b76..5b1138f2a 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts @@ -36,7 +36,7 @@ const createInfiniteParamsFunction = ({ }), }); - const fn = $.const(symbolCreateInfiniteParams.placeholder).assign( + const fn = $.const(symbolCreateInfiniteParams).assign( $.func() .generic('K', (g) => g.extends( @@ -169,7 +169,6 @@ export const createInfiniteQueryOptions = ({ }); const symbolInfiniteQueryKey = plugin.registerSymbol({ - exported: true, name: buildName({ config: plugin.config.infiniteQueryKeys, name: operation.id, @@ -231,14 +230,13 @@ export const createInfiniteQueryOptions = ({ } const symbolInfiniteQueryOptionsFn = plugin.registerSymbol({ - exported: true, name: buildName({ config: plugin.config.infiniteQueryOptions, name: operation.id, }), }); - const statement = $.const(symbolInfiniteQueryOptionsFn.placeholder) - .export(symbolInfiniteQueryOptionsFn.exported) + const statement = $.const(symbolInfiniteQueryOptionsFn) + .export() .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v), ) diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts index 3dc0fbdd0..ca109cab1 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts @@ -51,14 +51,13 @@ export const createMutationOptions = ({ const mutationOptionsFn = 'mutationOptions'; const symbolMutationOptions = plugin.registerSymbol({ - exported: true, name: buildName({ config: plugin.config.mutationOptions, name: operation.id, }), }); - const statement = $.const(symbolMutationOptions.placeholder) - .export(symbolMutationOptions.exported) + const statement = $.const(symbolMutationOptions) + .export() .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v), ) diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts index 72c678152..f355b3ac6 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts @@ -54,7 +54,6 @@ export const createQueryOptions = ({ }); const symbolQueryKey = plugin.registerSymbol({ - exported: true, name: buildName({ config: plugin.config.queryKeys, name: operation.id, @@ -107,7 +106,6 @@ export const createQueryOptions = ({ ); const symbolQueryOptionsFn = plugin.registerSymbol({ - exported: plugin.config.queryOptions.exported, meta: { category: 'hook', resource: 'operation', @@ -122,8 +120,8 @@ export const createQueryOptions = ({ }); // TODO: add type error // TODO: AxiosError - const statement = $.const(symbolQueryOptionsFn.placeholder) - .export(symbolQueryOptionsFn.exported) + const statement = $.const(symbolQueryOptionsFn) + .export(plugin.config.queryOptions.exported) .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v), ) diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/useQuery.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/useQuery.ts index dc5a22a10..e9101dff2 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/useQuery.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/useQuery.ts @@ -28,7 +28,6 @@ export const createUseQuery = ({ } const symbolUseQueryFn = plugin.registerSymbol({ - exported: true, name: buildName({ config: plugin.config.useQuery, name: operation.id, @@ -53,8 +52,8 @@ export const createUseQuery = ({ role: 'queryOptions', tool: plugin.name, }); - const statement = $.const(symbolUseQueryFn.placeholder) - .export(symbolUseQueryFn.exported) + const statement = $.const(symbolUseQueryFn) + .export() .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v), ) diff --git a/packages/openapi-ts/src/plugins/arktype/shared/export.ts b/packages/openapi-ts/src/plugins/arktype/shared/export.ts index b6dfbd4e5..96da51263 100644 --- a/packages/openapi-ts/src/plugins/arktype/shared/export.ts +++ b/packages/openapi-ts/src/plugins/arktype/shared/export.ts @@ -26,8 +26,8 @@ export const exportAst = ({ resource: 'arktype.type', }); - const statement = $.const(symbol.placeholder) - .export(symbol.exported) + const statement = $.const(symbol) + .export() .$if(plugin.config.comments && createSchemaComment(schema), (c, v) => c.doc(v), ) @@ -46,8 +46,8 @@ export const exportAst = ({ if (typeInferSymbol) { const inferType = $.type - .alias(typeInferSymbol.placeholder) - .export(typeInferSymbol.exported) + .alias(typeInferSymbol) + .export() .type( $.type(symbol.placeholder).attr(identifiers.type.infer).typeofType(), ); diff --git a/packages/openapi-ts/src/plugins/arktype/v2/plugin.ts b/packages/openapi-ts/src/plugins/arktype/v2/plugin.ts index 2392b4537..ff12e885d 100644 --- a/packages/openapi-ts/src/plugins/arktype/v2/plugin.ts +++ b/packages/openapi-ts/src/plugins/arktype/v2/plugin.ts @@ -243,7 +243,6 @@ const handleComponent = ({ const ast = irSchemaToAst({ plugin, schema, state }); const baseName = refToName($ref); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, @@ -259,8 +258,6 @@ const handleComponent = ({ }); const typeInferSymbol = plugin.config.definitions.types.infer.enabled ? plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, diff --git a/packages/openapi-ts/src/plugins/fastify/plugin.ts b/packages/openapi-ts/src/plugins/fastify/plugin.ts index 5185de5ad..33c701da2 100644 --- a/packages/openapi-ts/src/plugins/fastify/plugin.ts +++ b/packages/openapi-ts/src/plugins/fastify/plugin.ts @@ -154,8 +154,6 @@ export const handler: FastifyPlugin['Handler'] = ({ plugin }) => { }); const symbolRouteHandlers = plugin.registerSymbol({ - exported: true, - kind: 'type', name: 'RouteHandlers', }); @@ -174,9 +172,6 @@ export const handler: FastifyPlugin['Handler'] = ({ plugin }) => { }, ); - const node = $.type - .alias(symbolRouteHandlers.placeholder) - .export(symbolRouteHandlers.exported) - .type(type); + const node = $.type.alias(symbolRouteHandlers).export().type(type); plugin.setSymbolValue(symbolRouteHandlers, node); }; diff --git a/packages/openapi-ts/src/plugins/swr/v2/useSwr.ts b/packages/openapi-ts/src/plugins/swr/v2/useSwr.ts index ee528a80b..cec269e01 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/useSwr.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/useSwr.ts @@ -27,7 +27,6 @@ export const createUseSwr = ({ resource: 'swr', }); const symbolUseQueryFn = plugin.registerSymbol({ - exported: true, name: buildName({ config: plugin.config.useSwr, name: operation.id, @@ -48,8 +47,8 @@ export const createUseSwr = ({ ); } - const statement = $.const(symbolUseQueryFn.placeholder) - .export(symbolUseQueryFn.exported) + const statement = $.const(symbolUseQueryFn) + .export() .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v), ) diff --git a/packages/openapi-ts/src/plugins/valibot/shared/export.ts b/packages/openapi-ts/src/plugins/valibot/shared/export.ts index bb2c17863..d2c2f6dd6 100644 --- a/packages/openapi-ts/src/plugins/valibot/shared/export.ts +++ b/packages/openapi-ts/src/plugins/valibot/shared/export.ts @@ -24,8 +24,8 @@ export const exportAst = ({ resource: 'valibot.v', }); - const statement = $.const(symbol.placeholder) - .export(symbol.exported) + const statement = $.const(symbol) + .export() .$if(plugin.config.comments && createSchemaComment(schema), (c, v) => c.doc(v), ) diff --git a/packages/openapi-ts/src/plugins/valibot/shared/operation.ts b/packages/openapi-ts/src/plugins/valibot/shared/operation.ts index 8326bc177..7d36573c9 100644 --- a/packages/openapi-ts/src/plugins/valibot/shared/operation.ts +++ b/packages/openapi-ts/src/plugins/valibot/shared/operation.ts @@ -117,7 +117,6 @@ export const irOperationToAst = ({ const ast = getAst(schemaData, state.path.value); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, @@ -149,7 +148,6 @@ export const irOperationToAst = ({ const path = [...state.path.value, 'responses']; const ast = getAst(response, path); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path, diff --git a/packages/openapi-ts/src/plugins/valibot/shared/webhook.ts b/packages/openapi-ts/src/plugins/valibot/shared/webhook.ts index 6048db381..9c6c79bfc 100644 --- a/packages/openapi-ts/src/plugins/valibot/shared/webhook.ts +++ b/packages/openapi-ts/src/plugins/valibot/shared/webhook.ts @@ -116,7 +116,6 @@ export const irWebhookToAst = ({ const ast = getAst(schemaData, state.path.value); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, diff --git a/packages/openapi-ts/src/plugins/valibot/v1/plugin.ts b/packages/openapi-ts/src/plugins/valibot/v1/plugin.ts index 4361503b6..ab7a3ae7c 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/plugin.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/plugin.ts @@ -161,7 +161,6 @@ const handleComponent = ({ const ast = irSchemaToAst({ plugin, schema, state }); const baseName = refToName($ref); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, diff --git a/packages/openapi-ts/src/plugins/zod/mini/plugin.ts b/packages/openapi-ts/src/plugins/zod/mini/plugin.ts index 2df4a9ec0..69e0a87a0 100644 --- a/packages/openapi-ts/src/plugins/zod/mini/plugin.ts +++ b/packages/openapi-ts/src/plugins/zod/mini/plugin.ts @@ -183,7 +183,6 @@ const handleComponent = ({ const ast = irSchemaToAst({ plugin, schema, state }); const baseName = refToName($ref); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, @@ -199,8 +198,6 @@ const handleComponent = ({ }); const typeInferSymbol = plugin.config.definitions.types.infer.enabled ? plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, diff --git a/packages/openapi-ts/src/plugins/zod/shared/export.ts b/packages/openapi-ts/src/plugins/zod/shared/export.ts index 23eb65ce8..7890bc73f 100644 --- a/packages/openapi-ts/src/plugins/zod/shared/export.ts +++ b/packages/openapi-ts/src/plugins/zod/shared/export.ts @@ -26,8 +26,8 @@ export const exportAst = ({ resource: 'zod.z', }); - const statement = $.const(symbol.placeholder) - .export(symbol.exported) + const statement = $.const(symbol) + .export() .$if(plugin.config.comments && createSchemaComment(schema), (c, v) => c.doc(v), ) @@ -37,8 +37,8 @@ export const exportAst = ({ if (typeInferSymbol) { const inferType = $.type - .alias(typeInferSymbol.placeholder) - .export(typeInferSymbol.exported) + .alias(typeInferSymbol) + .export() .type( $.type(z.placeholder) .attr(identifiers.infer) diff --git a/packages/openapi-ts/src/plugins/zod/shared/operation.ts b/packages/openapi-ts/src/plugins/zod/shared/operation.ts index 1be803f1c..4a0497885 100644 --- a/packages/openapi-ts/src/plugins/zod/shared/operation.ts +++ b/packages/openapi-ts/src/plugins/zod/shared/operation.ts @@ -117,7 +117,6 @@ export const irOperationToAst = ({ const ast = getAst(schemaData, state.path.value); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, @@ -134,8 +133,6 @@ export const irOperationToAst = ({ }); const typeInferSymbol = plugin.config.requests.types.infer.enabled ? plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, @@ -169,7 +166,6 @@ export const irOperationToAst = ({ const path = [...state.path.value, 'responses']; const ast = getAst(response, path); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path, @@ -186,8 +182,6 @@ export const irOperationToAst = ({ }); const typeInferSymbol = plugin.config.responses.types.infer.enabled ? plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path, diff --git a/packages/openapi-ts/src/plugins/zod/shared/webhook.ts b/packages/openapi-ts/src/plugins/zod/shared/webhook.ts index eb1739263..86e581cd9 100644 --- a/packages/openapi-ts/src/plugins/zod/shared/webhook.ts +++ b/packages/openapi-ts/src/plugins/zod/shared/webhook.ts @@ -116,7 +116,6 @@ export const irWebhookToAst = ({ const ast = getAst(schemaData, state.path.value); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, @@ -133,8 +132,6 @@ export const irWebhookToAst = ({ }); const typeInferSymbol = plugin.config.webhooks.types.infer.enabled ? plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, diff --git a/packages/openapi-ts/src/plugins/zod/v3/plugin.ts b/packages/openapi-ts/src/plugins/zod/v3/plugin.ts index 03ef0ac0a..0a94278ee 100644 --- a/packages/openapi-ts/src/plugins/zod/v3/plugin.ts +++ b/packages/openapi-ts/src/plugins/zod/v3/plugin.ts @@ -171,7 +171,6 @@ const handleComponent = ({ const ast = irSchemaToAst({ plugin, schema, state }); const baseName = refToName($ref); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, @@ -187,8 +186,6 @@ const handleComponent = ({ }); const typeInferSymbol = plugin.config.definitions.types.infer.enabled ? plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, diff --git a/packages/openapi-ts/src/plugins/zod/v4/plugin.ts b/packages/openapi-ts/src/plugins/zod/v4/plugin.ts index db46ae0da..60e5e2aec 100644 --- a/packages/openapi-ts/src/plugins/zod/v4/plugin.ts +++ b/packages/openapi-ts/src/plugins/zod/v4/plugin.ts @@ -181,7 +181,6 @@ const handleComponent = ({ const ast = irSchemaToAst({ plugin, schema, state }); const baseName = refToName($ref); const symbol = plugin.registerSymbol({ - exported: true, meta: { category: 'schema', path: state.path.value, @@ -197,8 +196,6 @@ const handleComponent = ({ }); const typeInferSymbol = plugin.config.definitions.types.infer.enabled ? plugin.registerSymbol({ - exported: true, - kind: 'type', meta: { category: 'type', path: state.path.value, diff --git a/packages/openapi-ts/src/ts-dsl/base.ts b/packages/openapi-ts/src/ts-dsl/base.ts index 6290cede7..aab3fce87 100644 --- a/packages/openapi-ts/src/ts-dsl/base.ts +++ b/packages/openapi-ts/src/ts-dsl/base.ts @@ -1,14 +1,29 @@ +// TODO: symbol should be protected, but needs to be public to satisfy types +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; export type MaybeArray = T | ReadonlyArray; -export interface ITsDsl { +export interface ITsDsl extends SyntaxNode { + /** Render this DSL node into a concrete TypeScript AST node. */ $render(): T; } +export type Constructor = new (...args: ReadonlyArray) => T; + export abstract class TsDsl implements ITsDsl { + /** Walk this node and its children with a visitor. */ + abstract traverse(visitor: (node: SyntaxNode) => void): void; + + /** Render this DSL node into a concrete TypeScript AST node. */ abstract $render(): T; + /** Parent DSL node in the constructed syntax tree. */ + protected parent?: TsDsl; + + /** The codegen symbol associated with this node. */ + symbol?: Symbol; + /** Conditionally applies a callback to this builder. */ $if( this: T, @@ -84,6 +99,33 @@ export abstract class TsDsl implements ITsDsl { return this; } + /** Returns all locally declared names within this node. */ + getLocalNames(): Iterable { + return []; + } + + /** Returns all symbols referenced by this node (directly or through children). */ + getSymbols(): Iterable { + return []; + } + + /** Rewrites internal identifier nodes after final name resolution. */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + rewriteIdentifiers(_map: Map): void { + // noop + } + + /** Assigns the parent DSL node, enforcing a single-parent invariant. */ + setParent(parent: TsDsl): this { + if (this.parent && this.parent !== parent) { + throw new Error( + `DSL node already has a parent (${this.parent.constructor.name}); cannot reassign to ${parent.constructor.name}.`, + ); + } + this.parent = parent; + return this; + } + protected $maybeId( expr: T, ): T extends string ? ts.Identifier : T { @@ -132,6 +174,18 @@ export abstract class TsDsl implements ITsDsl { return this.unwrap(value as any) as TypeOfMaybe; } + /** Returns the root symbol associated with this DSL subtree. */ + protected getRootSymbol(): Symbol | undefined { + // eslint-disable-next-line @typescript-eslint/no-this-alias + let n: TsDsl | undefined = this; + while (n) { + if (n.symbol) return n.symbol; + n = n.parent; + } + return undefined; + } + + /** Unwraps nested DSL nodes into raw TypeScript AST nodes. */ protected unwrap(value: I): I extends TsDsl ? N : I { return ( value instanceof TsDsl ? value.$render() : value diff --git a/packages/openapi-ts/src/ts-dsl/decl/class.ts b/packages/openapi-ts/src/ts-dsl/decl/class.ts index 1659d422e..be9a67bf7 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/class.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/class.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -19,54 +20,63 @@ import { InitTsDsl } from './init'; import { MethodTsDsl } from './method'; export class ClassTsDsl extends TsDsl { - protected heritageClauses: Array = []; + protected baseClass?: Symbol | string; protected body: Array> = []; protected modifiers = createModifierAccessor(this); protected name: string; - constructor(name: string) { + constructor(name: Symbol | string) { super(); - this.name = name; + if (typeof name === 'string') { + this.name = name; + return; + } + this.name = name.finalName; + this.symbol = name; + this.symbol.setKind('class'); + this.symbol.setRootNode(this); } /** Adds one or more class members (fields, methods, etc.). */ do(...items: ReadonlyArray>): this { - // @ts-expect-error --- IGNORE --- - this.body.push(...items); + for (const item of items) { + if (item && typeof item === 'object' && 'setParent' in item) { + item.setParent(this); + } + // @ts-expect-error --- IGNORE --- + this.body.push(item); + } return this; } - /** Adds a base class to extend from. */ - extends(base?: string | ts.Expression | false | null): this { + /** Records a base class to extend from without rendering early. */ + extends(base?: Symbol | string): this { if (!base) return this; - this.heritageClauses.push( - ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [ - ts.factory.createExpressionWithTypeArguments( - this.$maybeId(base), - undefined, - ), - ]), - ); + this.baseClass = base; + if (typeof base !== 'string') { + const symbol = this.getRootSymbol(); + if (symbol) symbol.addDependency(base); + } return this; } /** Adds a class field. */ field(name: string, fn?: (f: FieldTsDsl) => void): this { - const f = new FieldTsDsl(name, fn); + const f = new FieldTsDsl(name, fn).setParent(this); this.body.push(f); return this; } /** Adds a class constructor. */ init(fn?: (i: InitTsDsl) => void): this { - const i = new InitTsDsl(fn); + const i = new InitTsDsl(fn).setParent(this); this.body.push(i); return this; } /** Adds a class method. */ method(name: string, fn?: (m: MethodTsDsl) => void): this { - const m = new MethodTsDsl(name, fn); + const m = new MethodTsDsl(name, fn).setParent(this); this.body.push(m); return this; } @@ -77,6 +87,11 @@ export class ClassTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Builds the `ClassDeclaration` node. */ $render(): ts.ClassDeclaration { const body = this.$node(this.body) as ReadonlyArray; @@ -84,10 +99,24 @@ export class ClassTsDsl extends TsDsl { [...this.$decorators(), ...this.modifiers.list()], this.name, this.$generics(), - this.heritageClauses, + this._renderHeritage(), body, ); } + + /** Builds heritage clauses (extends). */ + private _renderHeritage(): ReadonlyArray { + if (!this.baseClass) return []; + const id = + typeof this.baseClass === 'string' + ? this.$maybeId(this.baseClass) + : this.$maybeId(this.baseClass.finalName); + return [ + ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [ + ts.factory.createExpressionWithTypeArguments(id, undefined), + ]), + ]; + } } export interface ClassTsDsl diff --git a/packages/openapi-ts/src/ts-dsl/decl/decorator.ts b/packages/openapi-ts/src/ts-dsl/decl/decorator.ts index 4a77c30e8..6ebda0b43 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/decorator.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/decorator.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -7,27 +8,37 @@ import { mixin } from '../mixins/apply'; import { ArgsMixin } from '../mixins/args'; export class DecoratorTsDsl extends TsDsl { - protected name: string | ts.Expression; + protected name: Symbol | string | MaybeTsDsl; constructor( - name: string | ts.Expression, + name: Symbol | string | MaybeTsDsl, ...args: ReadonlyArray> ) { super(); this.name = name; + if (typeof name !== 'string' && 'id' in name) { + const symbol = this.getRootSymbol(); + if (symbol) symbol.addDependency(name); + } this.args(...args); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.Decorator { + const target = + typeof this.name !== 'string' && 'id' in this.name + ? this.$maybeId(this.name.finalName) + : this.$node(this.name); + const args = this.$args(); return ts.factory.createDecorator( args.length - ? ts.factory.createCallExpression( - this.$maybeId(this.name), - undefined, - args, - ) - : this.$maybeId(this.name), + ? ts.factory.createCallExpression(target, undefined, args) + : target, ); } } diff --git a/packages/openapi-ts/src/ts-dsl/decl/enum.ts b/packages/openapi-ts/src/ts-dsl/decl/enum.ts index f53300966..69b266336 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/enum.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/enum.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -20,9 +21,16 @@ export class EnumTsDsl extends TsDsl { private _name: string | ts.Identifier; protected modifiers = createModifierAccessor(this); - constructor(name: string | ts.Identifier, fn?: (e: EnumTsDsl) => void) { + constructor(name: Symbol | string, fn?: (e: EnumTsDsl) => void) { super(); - this._name = name; + if (typeof name === 'string') { + this._name = name; + } else { + this._name = name.finalName; + this.symbol = name; + this.symbol.setKind('enum'); + this.symbol.setRootNode(this); + } fn?.(this); } @@ -39,6 +47,11 @@ export class EnumTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Renders the enum declaration. */ $render(): ts.EnumDeclaration { return ts.factory.createEnumDeclaration( diff --git a/packages/openapi-ts/src/ts-dsl/decl/field.ts b/packages/openapi-ts/src/ts-dsl/decl/field.ts index 452d17df3..80ec0b6a8 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/field.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/field.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl, TypeTsDsl } from '../base'; @@ -33,6 +34,11 @@ export class FieldTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Builds the `PropertyDeclaration` node. */ $render(): ts.PropertyDeclaration { return ts.factory.createPropertyDeclaration( diff --git a/packages/openapi-ts/src/ts-dsl/decl/func.ts b/packages/openapi-ts/src/ts-dsl/decl/func.ts index 680b1d486..6d69338ac 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/func.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/func.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl, TypeTsDsl } from '../base'; @@ -29,27 +30,34 @@ class ImplFuncTsDsl extends TsDsl< ? ts.FunctionExpression : ts.ArrowFunction > { - protected mode: FuncMode; + protected mode?: FuncMode; protected modifiers = createModifierAccessor(this); protected name?: string; protected _returns?: TypeTsDsl; constructor(); constructor(fn: (f: ImplFuncTsDsl<'arrow'>) => void); - constructor(name: string); - constructor(name: string, fn: (f: ImplFuncTsDsl<'decl'>) => void); + constructor(name: Symbol | string); + constructor(name: Symbol | string, fn: (f: ImplFuncTsDsl<'decl'>) => void); constructor( - nameOrFn?: string | ((f: ImplFuncTsDsl<'arrow'>) => void), + nameOrFn?: Symbol | string | ((f: ImplFuncTsDsl<'arrow'>) => void), fn?: (f: ImplFuncTsDsl<'decl'>) => void, ) { super(); - if (typeof nameOrFn === 'string') { - this.name = nameOrFn; + if (typeof nameOrFn === 'function') { + this.mode = 'arrow'; + nameOrFn(this as unknown as FuncTsDsl<'arrow'>); + } else if (nameOrFn) { this.mode = 'decl'; + if (typeof nameOrFn === 'string') { + this.name = nameOrFn; + } else { + this.name = nameOrFn.finalName; + this.symbol = nameOrFn; + this.symbol.setKind('function'); + this.symbol.setRootNode(this); + } fn?.(this as unknown as FuncTsDsl<'decl'>); - } else { - this.mode = 'arrow'; - nameOrFn?.(this as unknown as FuncTsDsl<'arrow'>); } } @@ -77,6 +85,11 @@ class ImplFuncTsDsl extends TsDsl< return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): M extends 'decl' ? ts.FunctionDeclaration : M extends 'expr' diff --git a/packages/openapi-ts/src/ts-dsl/decl/getter.ts b/packages/openapi-ts/src/ts-dsl/decl/getter.ts index 2d1be95e3..2067d9cb6 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/getter.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/getter.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl } from '../base'; @@ -27,6 +28,11 @@ export class GetterTsDsl extends TsDsl { fn?.(this); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.GetAccessorDeclaration { return ts.factory.createGetAccessorDeclaration( [...this.$decorators(), ...this.modifiers.list()], diff --git a/packages/openapi-ts/src/ts-dsl/decl/init.ts b/packages/openapi-ts/src/ts-dsl/decl/init.ts index 7e9e59504..059e09502 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/init.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/init.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl } from '../base'; @@ -22,6 +23,11 @@ export class InitTsDsl extends TsDsl { fn?.(this); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Builds the `ConstructorDeclaration` node. */ $render(): ts.ConstructorDeclaration { return ts.factory.createConstructorDeclaration( diff --git a/packages/openapi-ts/src/ts-dsl/decl/member.ts b/packages/openapi-ts/src/ts-dsl/decl/member.ts index b0cfe68bf..c9165483d 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/member.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/member.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -24,6 +25,11 @@ export class EnumMemberTsDsl extends TsDsl { } } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Sets the enum member value. */ value(value?: Value): this { this._value = value; diff --git a/packages/openapi-ts/src/ts-dsl/decl/method.ts b/packages/openapi-ts/src/ts-dsl/decl/method.ts index 4c4e3b2d4..b73e5be55 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/method.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/method.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl, TypeTsDsl } from '../base'; @@ -38,6 +39,11 @@ export class MethodTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Builds the `MethodDeclaration` node. */ $render(): ts.MethodDeclaration { return ts.factory.createMethodDeclaration( diff --git a/packages/openapi-ts/src/ts-dsl/decl/param.ts b/packages/openapi-ts/src/ts-dsl/decl/param.ts index 61229f043..530bc17db 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/param.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/param.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl, TypeTsDsl } from '../base'; @@ -27,6 +28,11 @@ export class ParamTsDsl extends TsDsl { } } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Sets the parameter type. */ type(type: string | TypeTsDsl): this { this._type = type instanceof TypeTsDsl ? type : new TypeExprTsDsl(type); diff --git a/packages/openapi-ts/src/ts-dsl/decl/pattern.ts b/packages/openapi-ts/src/ts-dsl/decl/pattern.ts index 83a7b37ec..f32c68534 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/pattern.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/pattern.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeArray } from '../base'; @@ -44,6 +45,11 @@ export class PatternTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Builds and returns a BindingName (ObjectBindingPattern, ArrayBindingPattern, or Identifier). */ $render(): ts.BindingName { if (!this.pattern) { diff --git a/packages/openapi-ts/src/ts-dsl/decl/setter.ts b/packages/openapi-ts/src/ts-dsl/decl/setter.ts index 99c634192..30453fb57 100644 --- a/packages/openapi-ts/src/ts-dsl/decl/setter.ts +++ b/packages/openapi-ts/src/ts-dsl/decl/setter.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl } from '../base'; @@ -27,6 +28,11 @@ export class SetterTsDsl extends TsDsl { fn?.(this); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.SetAccessorDeclaration { return ts.factory.createSetAccessorDeclaration( [...this.$decorators(), ...this.modifiers.list()], diff --git a/packages/openapi-ts/src/ts-dsl/expr/array.ts b/packages/openapi-ts/src/ts-dsl/expr/array.ts index 6d0f095d9..b88c6b22a 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/array.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/array.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -49,6 +50,11 @@ export class ArrayTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.ArrayLiteralExpression { const elements = this._elements.map((item) => { const node = this.$node(item.expr); diff --git a/packages/openapi-ts/src/ts-dsl/expr/as.ts b/packages/openapi-ts/src/ts-dsl/expr/as.ts index fa1d37fab..95a860678 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/as.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/as.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl, TypeTsDsl } from '../base'; @@ -20,6 +21,11 @@ export class AsTsDsl extends TsDsl { this.type = type; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render() { return ts.factory.createAsExpression( this.$node(this.expr), diff --git a/packages/openapi-ts/src/ts-dsl/expr/attr.ts b/packages/openapi-ts/src/ts-dsl/expr/attr.ts index ad39e8817..516112fe7 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/attr.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/attr.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { validTypescriptIdentifierRegExp } from '~/utils/regexp'; @@ -28,6 +29,11 @@ export class AttrTsDsl extends TsDsl< this.right = right; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.PropertyAccessExpression | ts.ElementAccessExpression { const leftNode = this.$node(this.left); validTypescriptIdentifierRegExp.lastIndex = 0; diff --git a/packages/openapi-ts/src/ts-dsl/expr/await.ts b/packages/openapi-ts/src/ts-dsl/expr/await.ts index 6bca78495..6acdf5673 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/await.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/await.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -14,6 +15,11 @@ export class AwaitTsDsl extends TsDsl { this._awaitExpr = expr; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.AwaitExpression { return ts.factory.createAwaitExpression(this.$node(this._awaitExpr)); } diff --git a/packages/openapi-ts/src/ts-dsl/expr/binary.ts b/packages/openapi-ts/src/ts-dsl/expr/binary.ts index b87eb7f7b..3b450dd7a 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/binary.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/binary.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -119,6 +120,11 @@ export class BinaryTsDsl extends TsDsl { return this.opAndExpr('*', expr); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.BinaryExpression { if (!this._op) { throw new Error('BinaryTsDsl: missing operator'); diff --git a/packages/openapi-ts/src/ts-dsl/expr/call.ts b/packages/openapi-ts/src/ts-dsl/expr/call.ts index 77dfe4a6c..4874426b9 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/call.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/call.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -23,6 +24,11 @@ export class CallTsDsl extends TsDsl { ); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.CallExpression { return ts.factory.createCallExpression( this.$node(this._callee), diff --git a/packages/openapi-ts/src/ts-dsl/expr/expr.ts b/packages/openapi-ts/src/ts-dsl/expr/expr.ts index 768fbb649..0bcc06b2f 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/expr.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/expr.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import type ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -17,6 +18,11 @@ export class ExprTsDsl extends TsDsl { this._exprInput = id; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.Expression { return this.$node(this._exprInput); } diff --git a/packages/openapi-ts/src/ts-dsl/expr/id.ts b/packages/openapi-ts/src/ts-dsl/expr/id.ts index a4da00e5b..56d9b0946 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/id.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/id.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl } from '../base'; @@ -10,6 +11,11 @@ export class IdTsDsl extends TsDsl { this.name = name; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.Identifier { return ts.factory.createIdentifier(this.name); } diff --git a/packages/openapi-ts/src/ts-dsl/expr/literal.ts b/packages/openapi-ts/src/ts-dsl/expr/literal.ts index f239d9151..cb1352140 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/literal.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/literal.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging, @typescript-eslint/no-empty-object-type */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl } from '../base'; @@ -14,6 +15,11 @@ export class LiteralTsDsl extends TsDsl { this.value = value; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.LiteralTypeNode['literal'] { if (typeof this.value === 'boolean') { return this.value ? ts.factory.createTrue() : ts.factory.createFalse(); diff --git a/packages/openapi-ts/src/ts-dsl/expr/new.ts b/packages/openapi-ts/src/ts-dsl/expr/new.ts index e557a3f2a..b4d15a075 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/new.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/new.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -20,6 +21,11 @@ export class NewTsDsl extends TsDsl { this.args(...args); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Builds the `NewExpression` node. */ $render(): ts.NewExpression { return ts.factory.createNewExpression( diff --git a/packages/openapi-ts/src/ts-dsl/expr/object.ts b/packages/openapi-ts/src/ts-dsl/expr/object.ts index 7dc91e3c5..2f014ddbb 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/object.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/object.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -71,6 +72,11 @@ export class ObjectTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Builds and returns the object literal expression. */ $render(): ts.ObjectLiteralExpression { return ts.factory.createObjectLiteralExpression( diff --git a/packages/openapi-ts/src/ts-dsl/expr/prefix.ts b/packages/openapi-ts/src/ts-dsl/expr/prefix.ts index b13203d10..cb99d8e14 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/prefix.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/prefix.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -40,6 +41,11 @@ export class PrefixTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Renders the prefix unary expression node. */ $render(): ts.PrefixUnaryExpression { if (!this._expr) { diff --git a/packages/openapi-ts/src/ts-dsl/expr/prop.ts b/packages/openapi-ts/src/ts-dsl/expr/prop.ts index 16130fe38..1dca3ba01 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/prop.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/prop.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -35,6 +36,11 @@ export class ObjectPropTsDsl extends TsDsl { return this.missingRequiredCalls().length === 0; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + value(value: Expr | Stmt | ((p: ObjectPropTsDsl) => void)) { if (typeof value === 'function') { value(this); diff --git a/packages/openapi-ts/src/ts-dsl/expr/regexp.ts b/packages/openapi-ts/src/ts-dsl/expr/regexp.ts index d690e17e8..d7b043455 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/regexp.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/regexp.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl } from '../base'; @@ -20,6 +21,11 @@ export class RegExpTsDsl extends TsDsl { this.flags = flags; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Emits a RegularExpressionLiteral node. */ $render(): ts.RegularExpressionLiteral { const patternContent = diff --git a/packages/openapi-ts/src/ts-dsl/expr/template.ts b/packages/openapi-ts/src/ts-dsl/expr/template.ts index 90286cc5c..82eb392ba 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/template.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/template.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -18,6 +19,11 @@ export class TemplateTsDsl extends TsDsl< return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral { const parts = this.$node(this.parts); diff --git a/packages/openapi-ts/src/ts-dsl/expr/ternary.ts b/packages/openapi-ts/src/ts-dsl/expr/ternary.ts index 3f841ee41..301c3267b 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/ternary.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/ternary.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -28,6 +29,11 @@ export class TernaryTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.ConditionalExpression { if (!this._condition) throw new Error('Missing condition in ternary'); if (!this._then) throw new Error('Missing then expression in ternary'); diff --git a/packages/openapi-ts/src/ts-dsl/expr/typeof.ts b/packages/openapi-ts/src/ts-dsl/expr/typeof.ts index 4574610be..97e301ee6 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/typeof.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/typeof.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -15,6 +16,11 @@ export class TypeOfExprTsDsl extends TsDsl { this._expr = expr; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.TypeOfExpression { return ts.factory.createTypeOfExpression(this.$node(this._expr)); } diff --git a/packages/openapi-ts/src/ts-dsl/layout/doc.ts b/packages/openapi-ts/src/ts-dsl/layout/doc.ts index 9845dcf03..8e9dd81cb 100644 --- a/packages/openapi-ts/src/ts-dsl/layout/doc.ts +++ b/packages/openapi-ts/src/ts-dsl/layout/doc.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeArray } from '../base'; @@ -58,6 +59,11 @@ export class DocTsDsl extends TsDsl { return node; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.Node { // this class does not build a standalone node; // it modifies other nodes via `apply()`. diff --git a/packages/openapi-ts/src/ts-dsl/layout/hint.ts b/packages/openapi-ts/src/ts-dsl/layout/hint.ts index 1d7eadbc8..a3da41776 100644 --- a/packages/openapi-ts/src/ts-dsl/layout/hint.ts +++ b/packages/openapi-ts/src/ts-dsl/layout/hint.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeArray } from '../base'; @@ -40,6 +41,11 @@ export class HintTsDsl extends TsDsl { return node; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.Node { // this class does not build a standalone node; // it modifies other nodes via `apply()`. diff --git a/packages/openapi-ts/src/ts-dsl/layout/newline.ts b/packages/openapi-ts/src/ts-dsl/layout/newline.ts index 64df6f21c..cd2f0055e 100644 --- a/packages/openapi-ts/src/ts-dsl/layout/newline.ts +++ b/packages/openapi-ts/src/ts-dsl/layout/newline.ts @@ -1,9 +1,15 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import type ts from 'typescript'; import { TsDsl } from '../base'; import { IdTsDsl } from '../expr/id'; export class NewlineTsDsl extends TsDsl { + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.Identifier { return this.$node(new IdTsDsl('\n')); } diff --git a/packages/openapi-ts/src/ts-dsl/layout/note.ts b/packages/openapi-ts/src/ts-dsl/layout/note.ts index 5c264ef96..842af9089 100644 --- a/packages/openapi-ts/src/ts-dsl/layout/note.ts +++ b/packages/openapi-ts/src/ts-dsl/layout/note.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeArray } from '../base'; @@ -38,6 +39,11 @@ export class NoteTsDsl extends TsDsl { return node; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.Node { // this class does not build a standalone node; // it modifies other nodes via `apply()`. diff --git a/packages/openapi-ts/src/ts-dsl/mixins/apply.ts b/packages/openapi-ts/src/ts-dsl/mixins/apply.ts index 442c720bb..cf570bfdf 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/apply.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/apply.ts @@ -19,7 +19,6 @@ export function mixin(target: Function, ...sources: ReadonlyArray) { Object.getOwnPropertyDescriptors(sourceProto), )) { if (key === 'constructor') continue; - if (key === '$render' && !descriptor.value.mixin) continue; Object.defineProperty(targetProto, key, descriptor); } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/args.ts b/packages/openapi-ts/src/ts-dsl/mixins/args.ts index 4cd88f840..83bb2ea59 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/args.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/args.ts @@ -6,7 +6,7 @@ import { TsDsl } from '../base'; /** * Adds `.arg()` and `.args()` for managing expression arguments in call-like nodes. */ -export class ArgsMixin extends TsDsl { +export abstract class ArgsMixin extends TsDsl { protected _args?: Array>; /** Adds a single expression argument. */ @@ -26,8 +26,4 @@ export class ArgsMixin extends TsDsl { if (!this._args) return []; return this.$node(this._args).map((arg) => this.$maybeId(arg)); } - - $render(): ts.Node { - throw new Error('noop'); - } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/decorator.ts b/packages/openapi-ts/src/ts-dsl/mixins/decorator.ts index 9a414918a..099e1248a 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/decorator.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/decorator.ts @@ -1,18 +1,21 @@ +import type { Symbol } from '@hey-api/codegen-core'; import type ts from 'typescript'; import type { MaybeTsDsl } from '../base'; import { TsDsl } from '../base'; import { DecoratorTsDsl } from '../decl/decorator'; -export class DecoratorMixin extends TsDsl { +export abstract class DecoratorMixin extends TsDsl { protected decorators?: Array; /** Adds a decorator (e.g. `@sealed({ in: 'root' })`). */ decorator( - name: string | ts.Expression, + name: Symbol | string | MaybeTsDsl, ...args: ReadonlyArray> ): this { - (this.decorators ??= []).push(new DecoratorTsDsl(name, ...args)); + (this.decorators ??= []).push( + new DecoratorTsDsl(name, ...args).setParent(this), + ); return this; } @@ -21,8 +24,4 @@ export class DecoratorMixin extends TsDsl { if (!this.decorators) return []; return this.$node(this.decorators); } - - $render(): ts.Node { - throw new Error('noop'); - } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/do.ts b/packages/openapi-ts/src/ts-dsl/mixins/do.ts index e3873777a..77f4a737c 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/do.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/do.ts @@ -7,7 +7,7 @@ import { StmtTsDsl } from '../stmt/stmt'; /** * Adds `.do()` for appending statements or expressions to a body. */ -export class DoMixin extends TsDsl { +export abstract class DoMixin extends TsDsl { protected _do?: Array>; /** Adds one or more expressions/statements to the body. */ @@ -21,8 +21,4 @@ export class DoMixin extends TsDsl { if (!this._do) return []; return this.$node(this._do.map((item) => new StmtTsDsl(item))); } - - $render(): ts.Node { - throw new Error('noop'); - } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/doc.ts b/packages/openapi-ts/src/ts-dsl/mixins/doc.ts index 3e9159296..7b9cb846d 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/doc.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/doc.ts @@ -1,9 +1,7 @@ -import type { ITsDsl, MaybeArray } from '../base'; +import type { Constructor, ITsDsl, MaybeArray } from '../base'; import { DocTsDsl } from '../layout/doc'; -export function DocMixin< - TBase extends new (...args: ReadonlyArray) => ITsDsl, ->(Base: TBase) { +export function DocMixin(Base: TBase) { const $renderBase = Base.prototype.$render; class Mixin extends Base { @@ -20,9 +18,6 @@ export function DocMixin< } } - // @ts-expect-error - Mixin.prototype.$render.mixin = true; - return Mixin; } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/hint.ts b/packages/openapi-ts/src/ts-dsl/mixins/hint.ts index 62cb761f1..872819b71 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/hint.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/hint.ts @@ -1,9 +1,7 @@ -import type { ITsDsl, MaybeArray } from '../base'; +import type { Constructor, ITsDsl, MaybeArray } from '../base'; import { HintTsDsl } from '../layout/hint'; -export function HintMixin< - TBase extends new (...args: ReadonlyArray) => ITsDsl, ->(Base: TBase) { +export function HintMixin(Base: TBase) { const $renderBase = Base.prototype.$render; class Mixin extends Base { @@ -20,9 +18,6 @@ export function HintMixin< } } - // @ts-expect-error - Mixin.prototype.$render.mixin = true; - return Mixin; } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/modifiers.ts b/packages/openapi-ts/src/ts-dsl/mixins/modifiers.ts index 4fc8847b8..5ef584219 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/modifiers.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/modifiers.ts @@ -1,3 +1,4 @@ +import type { Symbol } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { TsDsl } from '../base'; @@ -15,13 +16,11 @@ export function createModifierAccessor(parent: Parent) { * Adds a modifier of the specified kind to the modifiers list if the condition is true. * * @param kind - The syntax kind of the modifier to add. - * @param condition - Whether to add the modifier (default: true). + * @param condition - Whether to add the modifier. * @returns The parent DSL node for chaining. */ - function _m(kind: ts.ModifierSyntaxKind, condition = true): Parent { - if (condition) { - modifiers.push(ts.factory.createModifier(kind)); - } + function _m(kind: ts.ModifierSyntaxKind, condition: boolean): Parent { + if (condition) modifiers.push(ts.factory.createModifier(kind)); return parent; } @@ -41,6 +40,7 @@ export function createModifierAccessor(parent: Parent) { type Target = object & { _m?(kind: ts.ModifierSyntaxKind, condition?: boolean): unknown; + symbol?: Symbol; }; /** @@ -53,8 +53,9 @@ export class AbstractMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - abstract(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.AbstractKeyword, condition) as T; + abstract(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.AbstractKeyword, cond) as T; } } @@ -68,8 +69,9 @@ export class AsyncMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - async(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.AsyncKeyword, condition) as T; + async(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.AsyncKeyword, cond) as T; } } @@ -83,8 +85,9 @@ export class ConstMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - const(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.ConstKeyword, condition) as T; + const(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.ConstKeyword, cond) as T; } } @@ -98,8 +101,9 @@ export class DeclareMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - declare(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.DeclareKeyword, condition) as T; + declare(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.DeclareKeyword, cond) as T; } } @@ -113,8 +117,9 @@ export class DefaultMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - default(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.DefaultKeyword, condition) as T; + default(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.DefaultKeyword, cond) as T; } } @@ -128,8 +133,10 @@ export class ExportMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - export(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.ExportKeyword, condition) as T; + export(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + if (this.symbol) this.symbol.setExported(cond); + return this._m!(ts.SyntaxKind.ExportKeyword, cond) as T; } } @@ -143,8 +150,9 @@ export class OverrideMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - override(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.OverrideKeyword, condition) as T; + override(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.OverrideKeyword, cond) as T; } } @@ -158,8 +166,9 @@ export class PrivateMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - private(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.PrivateKeyword, condition) as T; + private(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.PrivateKeyword, cond) as T; } } @@ -173,8 +182,9 @@ export class ProtectedMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - protected(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.ProtectedKeyword, condition) as T; + protected(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.ProtectedKeyword, cond) as T; } } @@ -188,8 +198,9 @@ export class PublicMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - public(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.PublicKeyword, condition) as T; + public(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.PublicKeyword, cond) as T; } } @@ -203,8 +214,9 @@ export class ReadonlyMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - readonly(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.ReadonlyKeyword, condition) as T; + readonly(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.ReadonlyKeyword, cond) as T; } } @@ -218,7 +230,8 @@ export class StaticMixin { * @param condition - Whether to add the modifier (default: true). * @returns The target object for chaining. */ - static(this: T, condition: boolean = true): T { - return this._m!(ts.SyntaxKind.StaticKeyword, condition) as T; + static(this: T, condition?: boolean): T { + const cond = arguments.length === 0 ? true : Boolean(condition); + return this._m!(ts.SyntaxKind.StaticKeyword, cond) as T; } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/note.ts b/packages/openapi-ts/src/ts-dsl/mixins/note.ts index 72f2901cb..d33f80228 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/note.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/note.ts @@ -1,9 +1,7 @@ -import type { ITsDsl, MaybeArray } from '../base'; +import type { Constructor, ITsDsl, MaybeArray } from '../base'; import { NoteTsDsl } from '../layout/note'; -export function NoteMixin< - TBase extends new (...args: ReadonlyArray) => ITsDsl, ->(Base: TBase) { +export function NoteMixin(Base: TBase) { const $renderBase = Base.prototype.$render; class Mixin extends Base { @@ -20,9 +18,6 @@ export function NoteMixin< } } - // @ts-expect-error - Mixin.prototype.$render.mixin = true; - return Mixin; } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/param.ts b/packages/openapi-ts/src/ts-dsl/mixins/param.ts index 3372d6368..f8e45e7f4 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/param.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/param.ts @@ -3,7 +3,7 @@ import type ts from 'typescript'; import { type MaybeTsDsl, TsDsl } from '../base'; import { ParamTsDsl } from '../decl/param'; -export class ParamMixin extends TsDsl { +export abstract class ParamMixin extends TsDsl { protected _params?: Array>; /** Adds a parameter. */ @@ -27,8 +27,4 @@ export class ParamMixin extends TsDsl { if (!this._params) return []; return this.$node(this._params); } - - $render(): ts.Node { - throw new Error('noop'); - } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/pattern.ts b/packages/openapi-ts/src/ts-dsl/mixins/pattern.ts index d47943752..a5bd11a04 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/pattern.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/pattern.ts @@ -7,7 +7,7 @@ import { PatternTsDsl } from '../decl/pattern'; /** * Mixin providing `.array()`, `.object()`, and `.spread()` methods for defining destructuring patterns. */ -export class PatternMixin extends TsDsl { +export abstract class PatternMixin extends TsDsl { protected pattern?: PatternTsDsl; /** Defines an array binding pattern. */ @@ -34,8 +34,4 @@ export class PatternMixin extends TsDsl { protected $pattern(): ts.BindingName | undefined { return this.$node(this.pattern); } - - $render(): ts.Node { - throw new Error('noop'); - } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/type-args.ts b/packages/openapi-ts/src/ts-dsl/mixins/type-args.ts index 146bb9ba0..b1ed253a8 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/type-args.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/type-args.ts @@ -3,7 +3,7 @@ import type ts from 'typescript'; import type { MaybeTsDsl, TypeTsDsl } from '../base'; import { TsDsl } from '../base'; -export class TypeArgsMixin extends TsDsl { +export abstract class TypeArgsMixin extends TsDsl { protected _generics?: Array>; /** Adds a single type argument (e.g. `string` in `Foo`). */ @@ -22,8 +22,4 @@ export class TypeArgsMixin extends TsDsl { protected $generics(): ReadonlyArray | undefined { return this.$type(this._generics); } - - $render(): ts.Node { - throw new Error('noop'); - } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/type-params.ts b/packages/openapi-ts/src/ts-dsl/mixins/type-params.ts index bd497ecf5..c3d917d42 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/type-params.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/type-params.ts @@ -4,7 +4,7 @@ import type { MaybeTsDsl } from '../base'; import { TsDsl } from '../base'; import { TypeParamTsDsl } from '../type/param'; -export class TypeParamsMixin extends TsDsl { +export abstract class TypeParamsMixin extends TsDsl { protected _generics?: Array>; /** Adds a single type parameter (e.g. `T` in `Array`). */ @@ -29,8 +29,4 @@ export class TypeParamsMixin extends TsDsl { return this.$node(node); }); } - - $render(): ts.Node { - throw new Error('noop'); - } } diff --git a/packages/openapi-ts/src/ts-dsl/mixins/value.ts b/packages/openapi-ts/src/ts-dsl/mixins/value.ts index 02baf9684..d008221b4 100644 --- a/packages/openapi-ts/src/ts-dsl/mixins/value.ts +++ b/packages/openapi-ts/src/ts-dsl/mixins/value.ts @@ -3,7 +3,7 @@ import type ts from 'typescript'; import type { MaybeTsDsl } from '../base'; import { TsDsl } from '../base'; -export class ValueMixin extends TsDsl { +export abstract class ValueMixin extends TsDsl { protected value?: string | MaybeTsDsl; /** Sets the initializer expression (e.g. `= expr`). */ @@ -15,8 +15,4 @@ export class ValueMixin extends TsDsl { protected $value(): ts.Expression | undefined { return this.$node(this.value); } - - $render(): ts.Node { - throw new Error('noop'); - } } diff --git a/packages/openapi-ts/src/ts-dsl/stmt/if.ts b/packages/openapi-ts/src/ts-dsl/stmt/if.ts index 7f8766088..417bb0c6b 100644 --- a/packages/openapi-ts/src/ts-dsl/stmt/if.ts +++ b/packages/openapi-ts/src/ts-dsl/stmt/if.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -25,6 +26,11 @@ export class IfTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.IfStatement { if (!this._condition) throw new Error('Missing condition in if'); diff --git a/packages/openapi-ts/src/ts-dsl/stmt/return.ts b/packages/openapi-ts/src/ts-dsl/stmt/return.ts index 483f96abd..a0f3acfe3 100644 --- a/packages/openapi-ts/src/ts-dsl/stmt/return.ts +++ b/packages/openapi-ts/src/ts-dsl/stmt/return.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -14,6 +15,11 @@ export class ReturnTsDsl extends TsDsl { this._returnExpr = expr; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.ReturnStatement { return ts.factory.createReturnStatement(this.$node(this._returnExpr)); } diff --git a/packages/openapi-ts/src/ts-dsl/stmt/stmt.ts b/packages/openapi-ts/src/ts-dsl/stmt/stmt.ts index 425b5eafa..9e8be4025 100644 --- a/packages/openapi-ts/src/ts-dsl/stmt/stmt.ts +++ b/packages/openapi-ts/src/ts-dsl/stmt/stmt.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl } from '../base'; @@ -10,6 +11,11 @@ export class StmtTsDsl extends TsDsl { this._inner = inner; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.Statement { const node = this.$node(this._inner); return ts.isStatement(node) diff --git a/packages/openapi-ts/src/ts-dsl/stmt/throw.ts b/packages/openapi-ts/src/ts-dsl/stmt/throw.ts index 16ef8cb65..9156899b7 100644 --- a/packages/openapi-ts/src/ts-dsl/stmt/throw.ts +++ b/packages/openapi-ts/src/ts-dsl/stmt/throw.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -20,6 +21,11 @@ export class ThrowTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.ThrowStatement { const errorNode = this.$node(this.error); const messageNode = this.$node(this.msg ? [this.msg] : []).map((expr) => diff --git a/packages/openapi-ts/src/ts-dsl/stmt/var.ts b/packages/openapi-ts/src/ts-dsl/stmt/var.ts index 14e33d14b..7ba8f1599 100644 --- a/packages/openapi-ts/src/ts-dsl/stmt/var.ts +++ b/packages/openapi-ts/src/ts-dsl/stmt/var.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl, TypeTsDsl } from '../base'; @@ -20,9 +21,18 @@ export class VarTsDsl extends TsDsl { protected name?: string; protected _type?: TypeTsDsl; - constructor(name?: string) { + constructor(name?: Symbol | string) { super(); - this.name = name; + if (name) { + if (typeof name === 'string') { + this.name = name; + } else { + this.name = name.finalName; + this.symbol = name; + this.symbol.setKind('var'); + this.symbol.setRootNode(this); + } + } } const(): this { @@ -35,6 +45,11 @@ export class VarTsDsl extends TsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Sets the variable type. */ type(type: string | TypeTsDsl): this { this._type = type instanceof TypeTsDsl ? type : new TypeExprTsDsl(type); diff --git a/packages/openapi-ts/src/ts-dsl/token.ts b/packages/openapi-ts/src/ts-dsl/token.ts index 996fab607..59bf21963 100644 --- a/packages/openapi-ts/src/ts-dsl/token.ts +++ b/packages/openapi-ts/src/ts-dsl/token.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TsDsl } from './base'; @@ -55,6 +56,11 @@ export class TokenTsDsl extends TsDsl< ); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Renders the final token */ $render(): ts.Token { if (!this._kind) { diff --git a/packages/openapi-ts/src/ts-dsl/type/alias.ts b/packages/openapi-ts/src/ts-dsl/type/alias.ts index 4fa0885ef..3e7151979 100644 --- a/packages/openapi-ts/src/ts-dsl/type/alias.ts +++ b/packages/openapi-ts/src/ts-dsl/type/alias.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -9,16 +10,28 @@ import { createModifierAccessor, ExportMixin } from '../mixins/modifiers'; import { TypeParamsMixin } from '../mixins/type-params'; export class TypeAliasTsDsl extends TsDsl { - protected value?: MaybeTsDsl; protected modifiers = createModifierAccessor(this); protected name: string; + protected value?: MaybeTsDsl; - constructor(name: string, fn?: (t: TypeAliasTsDsl) => void) { + constructor(name: Symbol | string, fn?: (t: TypeAliasTsDsl) => void) { super(); - this.name = name; + if (typeof name === 'string') { + this.name = name; + } else { + this.name = name.finalName; + this.symbol = name; + this.symbol.setKind('type'); + this.symbol.setRootNode(this); + } fn?.(this); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Sets the type expression on the right-hand side of `= ...`. */ type(node: MaybeTsDsl): this { this.value = node; diff --git a/packages/openapi-ts/src/ts-dsl/type/and.ts b/packages/openapi-ts/src/ts-dsl/type/and.ts index fbbb0085e..7c52a6ca6 100644 --- a/packages/openapi-ts/src/ts-dsl/type/and.ts +++ b/packages/openapi-ts/src/ts-dsl/type/and.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TypeTsDsl } from '../base'; @@ -10,6 +11,11 @@ export class TypeAndTsDsl extends TypeTsDsl { this.types(...nodes); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + types(...nodes: Array): this { this._types.push(...nodes); return this; diff --git a/packages/openapi-ts/src/ts-dsl/type/attr.ts b/packages/openapi-ts/src/ts-dsl/type/attr.ts index d04a64e0d..c89a10636 100644 --- a/packages/openapi-ts/src/ts-dsl/type/attr.ts +++ b/packages/openapi-ts/src/ts-dsl/type/attr.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -7,17 +8,17 @@ import { mixin } from '../mixins/apply'; import { TypeExprMixin } from '../mixins/type-expr'; export class TypeAttrTsDsl extends TypeTsDsl { - protected _base?: string | MaybeTsDsl; - protected right: string | ts.Identifier; + protected _base?: Symbol | string | MaybeTsDsl; + protected right: Symbol | string | ts.Identifier; constructor( - base: string | MaybeTsDsl, + base: Symbol | string | MaybeTsDsl, right: string | ts.Identifier, ); - constructor(right: string | ts.Identifier); + constructor(right: Symbol | string | ts.Identifier); constructor( - baseOrRight: string | MaybeTsDsl, - maybeRight?: string | ts.Identifier, + baseOrRight: Symbol | string | MaybeTsDsl, + maybeRight?: Symbol | string | ts.Identifier, ) { super(); if (maybeRight) { @@ -29,20 +30,31 @@ export class TypeAttrTsDsl extends TypeTsDsl { } } - base(base?: string | MaybeTsDsl): this { + base(base?: Symbol | string | MaybeTsDsl): this { this._base = base; return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.QualifiedName { if (!this._base) { throw new Error('TypeAttrTsDsl: missing base for qualified name'); } - const left = this.$node(this._base); + const left = + typeof this._base !== 'string' && this._base && 'id' in this._base + ? this.$node(this._base.finalName) + : this.$node(this._base); if (!ts.isEntityName(left)) { throw new Error('TypeAttrTsDsl: base must be an EntityName'); } - const right = this.$maybeId(this.right); + const right = + typeof this.right !== 'string' && this.right && 'id' in this.right + ? this.$maybeId(this.right.finalName) + : this.$maybeId(this.right); return ts.factory.createQualifiedName(left, right); } } diff --git a/packages/openapi-ts/src/ts-dsl/type/expr.ts b/packages/openapi-ts/src/ts-dsl/type/expr.ts index 6b6204266..502e4f40c 100644 --- a/packages/openapi-ts/src/ts-dsl/type/expr.ts +++ b/packages/openapi-ts/src/ts-dsl/type/expr.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { Symbol, SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TypeTsDsl } from '../base'; @@ -11,22 +12,28 @@ import { import { TypeAttrTsDsl } from './attr'; export class TypeExprTsDsl extends TypeTsDsl { - protected _exprInput?: string | ts.Identifier | TypeAttrTsDsl; + protected _exprInput?: Symbol | string | TypeAttrTsDsl; constructor(); constructor(fn: (t: TypeExprTsDsl) => void); - constructor(name: string); - constructor(name: string, fn?: (t: TypeExprTsDsl) => void); + constructor(name: Symbol | string); + constructor(name: Symbol | string, fn?: (t: TypeExprTsDsl) => void); constructor( - nameOrFn?: string | ((t: TypeExprTsDsl) => void), + name?: Symbol | string | ((t: TypeExprTsDsl) => void), fn?: (t: TypeExprTsDsl) => void, ) { super(); - if (typeof nameOrFn === 'string') { - this._exprInput = nameOrFn; - fn?.(this); - } else { - nameOrFn?.(this); + if (name) { + if (typeof name === 'function') { + name(this); + } else { + this._exprInput = name; + if (typeof name !== 'string') { + const symbol = this.getRootSymbol(); + if (symbol) symbol.addDependency(name); + } + fn?.(this); + } } } @@ -36,15 +43,25 @@ export class TypeExprTsDsl extends TypeTsDsl { right instanceof TypeAttrTsDsl ? right.base(this._exprInput) : new TypeAttrTsDsl(this._exprInput!, right); + this._exprInput = this._exprInput.setParent(this); return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.TypeReferenceNode { - if (!this._exprInput) - throw new Error('TypeExpr must have either an expression or an object'); + if (!this._exprInput) throw new Error('TypeExpr must have an expression'); + const typeName = + typeof this._exprInput === 'string' || + this._exprInput instanceof TypeAttrTsDsl + ? this.$type(this._exprInput) + : this._exprInput.finalName; return ts.factory.createTypeReferenceNode( // @ts-expect-error --- need to fix types - this.$type(this._exprInput), + typeName, this.$generics(), ); } diff --git a/packages/openapi-ts/src/ts-dsl/type/func.ts b/packages/openapi-ts/src/ts-dsl/type/func.ts index 958f64e37..e7fbc1a25 100644 --- a/packages/openapi-ts/src/ts-dsl/type/func.ts +++ b/packages/openapi-ts/src/ts-dsl/type/func.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TypeTsDsl } from '../base'; @@ -17,6 +18,11 @@ export class TypeFuncTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.FunctionTypeNode { if (this._returns === undefined) { throw new Error('Missing return type in function type DSL'); diff --git a/packages/openapi-ts/src/ts-dsl/type/idx-sig.ts b/packages/openapi-ts/src/ts-dsl/type/idx-sig.ts index 0ba632ab5..ea16327df 100644 --- a/packages/openapi-ts/src/ts-dsl/type/idx-sig.ts +++ b/packages/openapi-ts/src/ts-dsl/type/idx-sig.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -32,6 +33,11 @@ export class TypeIdxSigTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Sets the property type. */ type(type: Type): this { this._type = type; diff --git a/packages/openapi-ts/src/ts-dsl/type/idx.ts b/packages/openapi-ts/src/ts-dsl/type/idx.ts index a43300bdb..be2b33041 100644 --- a/packages/openapi-ts/src/ts-dsl/type/idx.ts +++ b/packages/openapi-ts/src/ts-dsl/type/idx.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -32,6 +33,11 @@ export class TypeIdxTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.IndexedAccessTypeNode { return ts.factory.createIndexedAccessTypeNode( this.$type(this._base), diff --git a/packages/openapi-ts/src/ts-dsl/type/literal.ts b/packages/openapi-ts/src/ts-dsl/type/literal.ts index 7e1f3caf5..4fd5578bf 100644 --- a/packages/openapi-ts/src/ts-dsl/type/literal.ts +++ b/packages/openapi-ts/src/ts-dsl/type/literal.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TypeTsDsl } from '../base'; @@ -11,6 +12,11 @@ export class TypeLiteralTsDsl extends TypeTsDsl { this.value = value; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.LiteralTypeNode { return ts.factory.createLiteralTypeNode( this.$node(new LiteralTsDsl(this.value)), diff --git a/packages/openapi-ts/src/ts-dsl/type/mapped.ts b/packages/openapi-ts/src/ts-dsl/type/mapped.ts index 946235799..208a6e518 100644 --- a/packages/openapi-ts/src/ts-dsl/type/mapped.ts +++ b/packages/openapi-ts/src/ts-dsl/type/mapped.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -65,6 +66,11 @@ export class TypeMappedTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Sets the mapped value type: `[K in X]: ValueType` */ type(type: string | MaybeTsDsl): this { this._type = type; diff --git a/packages/openapi-ts/src/ts-dsl/type/object.ts b/packages/openapi-ts/src/ts-dsl/type/object.ts index 26fbf0ee6..36b526dde 100644 --- a/packages/openapi-ts/src/ts-dsl/type/object.ts +++ b/packages/openapi-ts/src/ts-dsl/type/object.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TypeTsDsl } from '../base'; @@ -31,6 +32,11 @@ export class TypeObjectTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.TypeNode { return ts.factory.createTypeLiteralNode(this.$node(this.props)); } diff --git a/packages/openapi-ts/src/ts-dsl/type/operator.ts b/packages/openapi-ts/src/ts-dsl/type/operator.ts index 674b5bc20..5f94206ac 100644 --- a/packages/openapi-ts/src/ts-dsl/type/operator.ts +++ b/packages/openapi-ts/src/ts-dsl/type/operator.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -46,6 +47,11 @@ export class TypeOperatorTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Sets the target type of the operator. */ type(type: Type): this { this._type = type; diff --git a/packages/openapi-ts/src/ts-dsl/type/or.ts b/packages/openapi-ts/src/ts-dsl/type/or.ts index 874a82fab..6b2d4f973 100644 --- a/packages/openapi-ts/src/ts-dsl/type/or.ts +++ b/packages/openapi-ts/src/ts-dsl/type/or.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TypeTsDsl } from '../base'; @@ -10,6 +11,11 @@ export class TypeOrTsDsl extends TypeTsDsl { this.types(...nodes); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + types(...nodes: Array): this { this._types.push(...nodes); return this; diff --git a/packages/openapi-ts/src/ts-dsl/type/param.ts b/packages/openapi-ts/src/ts-dsl/type/param.ts index 50b43a28e..94a82c04a 100644 --- a/packages/openapi-ts/src/ts-dsl/type/param.ts +++ b/packages/openapi-ts/src/ts-dsl/type/param.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -27,6 +28,11 @@ export class TypeParamTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.TypeParameterDeclaration { if (!this.name) throw new Error('Missing type name'); return ts.factory.createTypeParameterDeclaration( diff --git a/packages/openapi-ts/src/ts-dsl/type/prop.ts b/packages/openapi-ts/src/ts-dsl/type/prop.ts index 393232508..c7f27cc29 100644 --- a/packages/openapi-ts/src/ts-dsl/type/prop.ts +++ b/packages/openapi-ts/src/ts-dsl/type/prop.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -21,6 +22,11 @@ export class TypePropTsDsl extends TypeTsDsl { fn(this); } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Sets the property type. */ type(type: string | MaybeTsDsl): this { this._type = type; diff --git a/packages/openapi-ts/src/ts-dsl/type/query.ts b/packages/openapi-ts/src/ts-dsl/type/query.ts index 987bd31de..059054964 100644 --- a/packages/openapi-ts/src/ts-dsl/type/query.ts +++ b/packages/openapi-ts/src/ts-dsl/type/query.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -17,6 +18,11 @@ export class TypeQueryTsDsl extends TypeTsDsl { this._expr = expr; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.TypeQueryNode { const expr = this.$node(this._expr); return ts.factory.createTypeQueryNode(expr as unknown as ts.EntityName); diff --git a/packages/openapi-ts/src/ts-dsl/type/template.ts b/packages/openapi-ts/src/ts-dsl/type/template.ts index 5617286ca..6cbb940de 100644 --- a/packages/openapi-ts/src/ts-dsl/type/template.ts +++ b/packages/openapi-ts/src/ts-dsl/type/template.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import type { MaybeTsDsl } from '../base'; @@ -17,6 +18,11 @@ export class TypeTemplateTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + /** Renders a TemplateLiteralTypeNode. */ $render(): ts.TemplateLiteralTypeNode { const parts = this.$node(this.parts); diff --git a/packages/openapi-ts/src/ts-dsl/type/tuple.ts b/packages/openapi-ts/src/ts-dsl/type/tuple.ts index 260c437fa..e0ab0cc65 100644 --- a/packages/openapi-ts/src/ts-dsl/type/tuple.ts +++ b/packages/openapi-ts/src/ts-dsl/type/tuple.ts @@ -1,3 +1,4 @@ +import type { SyntaxNode } from '@hey-api/codegen-core'; import ts from 'typescript'; import { TypeTsDsl } from '../base'; @@ -15,6 +16,11 @@ export class TypeTupleTsDsl extends TypeTsDsl { return this; } + /** Walk this node and its children with a visitor. */ + traverse(visitor: (node: SyntaxNode) => void): void { + console.log(visitor); + } + $render(): ts.TupleTypeNode { return ts.factory.createTupleTypeNode( this._elements.map((t) => this.$type(t)), -- 2.51.2