fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2878 from hey-api/refactor/selector-typescript

refactor: remove selectors from typescript plugin

authored by

Lubos and committed by
GitHub
dfd1a2eb 830a26a3

+384 -209
+6 -6
dev/openapi-ts.config.ts
··· 346 346 // definitions: 'z{{name}}Definition', 347 347 exportFromIndex: true, 348 348 // metadata: true, 349 - name: 'valibot', 349 + // name: 'valibot', 350 350 // requests: { 351 351 // case: 'PascalCase', 352 352 // name: '{{name}}Data', ··· 385 385 // comments: false, 386 386 compatibilityVersion: 4, 387 387 dates: { 388 - local: true, 388 + // local: true, 389 389 // offset: true, 390 390 }, 391 391 definitions: { ··· 394 394 // infer: 'D{{name}}ZodType', 395 395 // }, 396 396 }, 397 - exportFromIndex: true, 397 + // exportFromIndex: true, 398 398 // metadata: true, 399 399 // name: 'zod', 400 400 // requests: { ··· 417 417 // }, 418 418 }, 419 419 types: { 420 - // infer: { 421 - // case: 'snake_case', 422 - // }, 420 + infer: { 421 + case: 'snake_case', 422 + }, 423 423 }, 424 424 '~hooks': { 425 425 symbols: {
-1
packages/openapi-ts/src/generate/__tests__/class.test.ts
··· 109 109 '@hey-api/typescript': { 110 110 api: { 111 111 schemaToType: () => ({}) as ts.TypeNode, 112 - selector: () => [], 113 112 }, 114 113 config: { 115 114 enums: 'javascript',
-3
packages/openapi-ts/src/generate/__tests__/core.test.ts
··· 124 124 '@hey-api/typescript': { 125 125 api: { 126 126 schemaToType: () => ({}) as ts.TypeNode, 127 - selector: () => [], 128 127 }, 129 128 config: { 130 129 enums: 'javascript', ··· 281 280 '@hey-api/typescript': { 282 281 api: { 283 282 schemaToType: () => ({}) as ts.TypeNode, 284 - selector: () => [], 285 283 }, 286 284 config: { 287 285 enums: 'javascript', ··· 421 419 '@hey-api/typescript': { 422 420 api: { 423 421 schemaToType: () => ({}) as ts.TypeNode, 424 - selector: () => [], 425 422 }, 426 423 config: { 427 424 enums: 'javascript',
-1
packages/openapi-ts/src/generate/legacy/__tests__/index.test.ts
··· 108 108 '@hey-api/typescript': { 109 109 api: { 110 110 schemaToType: () => ({}) as ts.TypeNode, 111 - selector: () => [], 112 111 }, 113 112 config: { 114 113 enums: 'javascript',
-1
packages/openapi-ts/src/generate/legacy/__tests__/output.test.ts
··· 121 121 '@hey-api/typescript': { 122 122 api: { 123 123 schemaToType: () => ({}) as ts.TypeNode, 124 - selector: () => [], 125 124 }, 126 125 config: { 127 126 enums: 'javascript',
+1 -1
packages/openapi-ts/src/index.ts
··· 43 43 * Tags associated with this symbol. 44 44 */ 45 45 tags?: Set<string>; 46 - tool?: 'valibot' | (string & {}); 46 + tool?: 'arktype' | 'typescript' | 'valibot' | 'zod' | (string & {}); 47 47 variant?: 'container' | (string & {}); 48 48 } 49 49 }
-1
packages/openapi-ts/src/openApi/common/parser/__tests__/type.test.ts
··· 10 10 '@hey-api/typescript': { 11 11 api: { 12 12 schemaToType: () => ({}) as ts.TypeNode, 13 - selector: () => [], 14 13 }, 15 14 config: { 16 15 name: '@hey-api/typescript',
-1
packages/openapi-ts/src/openApi/v3/parser/__tests__/getModel.test.ts
··· 13 13 '@hey-api/typescript': { 14 14 api: { 15 15 schemaToType: () => ({}) as ts.TypeNode, 16 - selector: () => [], 17 16 }, 18 17 config: { 19 18 name: '@hey-api/typescript',
+2
packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts
··· 292 292 resource: 'operation', 293 293 resourceId: operation.id, 294 294 role: 'data', 295 + tool: 'typescript', 295 296 }); 296 297 const dataType = symbolDataType?.placeholder || 'unknown'; 297 298 ··· 350 351 resource: 'operation', 351 352 resourceId: operation.id, 352 353 role: 'data', 354 + tool: 'typescript', 353 355 }); 354 356 const dataType = symbolDataType?.placeholder || 'unknown'; 355 357
+2
packages/openapi-ts/src/plugins/@angular/common/httpResources.ts
··· 375 375 resource: 'operation', 376 376 resourceId: operation.id, 377 377 role: 'data', 378 + tool: 'typescript', 378 379 }); 379 380 const dataType = symbolDataType?.placeholder || 'unknown'; 380 381 ··· 429 430 resource: 'operation', 430 431 resourceId: operation.id, 431 432 role: 'data', 433 + tool: 'typescript', 432 434 }); 433 435 const dataType = symbolDataType?.placeholder || 'unknown'; 434 436
-2
packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts
··· 112 112 '@hey-api/typescript': { 113 113 api: { 114 114 schemaToType: () => ({}) as ts.TypeNode, 115 - selector: () => [], 116 115 }, 117 116 config: { 118 117 enums: 'javascript', ··· 282 281 '@hey-api/typescript': { 283 282 api: { 284 283 schemaToType: () => ({}) as ts.TypeNode, 285 - selector: () => [], 286 284 }, 287 285 config: { 288 286 enums: 'javascript',
-4
packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts
··· 115 115 '@hey-api/typescript': { 116 116 api: { 117 117 schemaToType: () => ({}) as ts.TypeNode, 118 - selector: () => [], 119 118 }, 120 119 config: { 121 120 name: '@hey-api/typescript', ··· 357 356 '@hey-api/typescript': { 358 357 api: { 359 358 schemaToType: () => ({}) as ts.TypeNode, 360 - selector: () => [], 361 359 }, 362 360 config: { 363 361 name: '@hey-api/typescript', ··· 522 520 '@hey-api/typescript': { 523 521 api: { 524 522 schemaToType: () => ({}) as ts.TypeNode, 525 - selector: () => [], 526 523 }, 527 524 config: { 528 525 name: '@hey-api/typescript', ··· 689 686 '@hey-api/typescript': { 690 687 api: { 691 688 schemaToType: () => ({}) as ts.TypeNode, 692 - selector: () => [], 693 689 }, 694 690 config: { 695 691 name: '@hey-api/typescript',
+1
packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts
··· 163 163 resource: 'operation', 164 164 resourceId: operation.id, 165 165 role: 'data', 166 + tool: 'typescript', 166 167 }); 167 168 const dataType = symbolDataType?.placeholder || 'unknown'; 168 169
-1
packages/openapi-ts/src/plugins/@hey-api/typescript/__tests__/plugin.test.ts
··· 112 112 '@hey-api/typescript': { 113 113 api: { 114 114 schemaToType: () => ({}) as ts.TypeNode, 115 - selector: () => [], 116 115 }, 117 116 config: { 118 117 enums: 'javascript',
-26
packages/openapi-ts/src/plugins/@hey-api/typescript/api.ts
··· 1 - import type { Selector } from '@hey-api/codegen-core'; 2 1 import type ts from 'typescript'; 3 2 4 - import type { Plugin } from '~/plugins'; 5 - 6 3 import { irSchemaToAstV1 } from './v1/api'; 7 4 8 - type SelectorType = 9 - | 'TypeID' 10 - | 'webhook-payload' 11 - | 'webhook-request' 12 - | 'Webhooks'; 13 - 14 5 export type IApi = { 15 6 schemaToType: (args: Parameters<typeof irSchemaToAstV1>[0]) => ts.TypeNode; 16 - /** 17 - * @param type Selector type. 18 - * @param value Depends on `type`: 19 - * - `TypeID`: `type` name string 20 - * - `webhook-payload`: `operation.id` string 21 - * - `webhook-request`: `operation.id` string 22 - * - `Webhooks`: never 23 - * @returns Selector array 24 - * @deprecated 25 - */ 26 - selector: (type: SelectorType, value?: string) => Selector; 27 7 }; 28 8 29 9 export class Api implements IApi { 30 - constructor(public meta: Plugin.Name<'@hey-api/typescript'>) {} 31 - 32 - selector(...args: ReadonlyArray<string | undefined>): Selector { 33 - return [this.meta.name, ...(args as Selector)]; 34 - } 35 - 36 10 schemaToType(args: Parameters<typeof irSchemaToAstV1>[0]): ts.TypeNode { 37 11 return irSchemaToAstV1(args); 38 12 }
+1 -3
packages/openapi-ts/src/plugins/@hey-api/typescript/config.ts
··· 6 6 import type { HeyApiTypeScriptPlugin } from './types'; 7 7 8 8 export const defaultConfig: HeyApiTypeScriptPlugin['Config'] = { 9 - api: new Api({ 10 - name: '@hey-api/typescript', 11 - }), 9 + api: new Api(), 12 10 config: { 13 11 case: 'PascalCase', 14 12 exportFromIndex: true,
+5
packages/openapi-ts/src/plugins/@hey-api/typescript/shared/operation.ts
··· 130 130 resourceId: operation.id, 131 131 role: 'data', 132 132 tags: state.tags?.value, 133 + tool: 'typescript', 133 134 }, 134 135 name: buildName({ 135 136 config: plugin.config.requests, ··· 172 173 resourceId: operation.id, 173 174 role: 'errors', 174 175 tags: state.tags?.value, 176 + tool: 'typescript', 175 177 }, 176 178 name: buildName({ 177 179 config: plugin.config.errors, ··· 201 203 resourceId: operation.id, 202 204 role: 'error', 203 205 tags: state.tags?.value, 206 + tool: 'typescript', 204 207 }, 205 208 name: buildName({ 206 209 config: { ··· 239 242 resourceId: operation.id, 240 243 role: 'responses', 241 244 tags: state.tags?.value, 245 + tool: 'typescript', 242 246 }, 243 247 name: buildName({ 244 248 config: plugin.config.responses, ··· 268 272 resourceId: operation.id, 269 273 role: 'response', 270 274 tags: state.tags?.value, 275 + tool: 'typescript', 271 276 }, 272 277 name: buildName({ 273 278 config: {
+11 -2
packages/openapi-ts/src/plugins/@hey-api/typescript/shared/webhook.ts
··· 27 27 exported: true, 28 28 kind: 'type', 29 29 meta: { 30 + category: 'type', 30 31 path: state.path.value, 32 + resource: 'webhook', 33 + resourceId: operation.id, 34 + role: 'data', 31 35 tags: state.tags?.value, 36 + tool: 'typescript', 32 37 }, 33 38 name: buildName({ 34 39 config: { ··· 37 42 }, 38 43 name: operation.id, 39 44 }), 40 - selector: plugin.api.selector('webhook-payload', operation.id), 41 45 }); 42 46 const type = irSchemaToAst({ 43 47 plugin, ··· 61 65 resource: 'definition', 62 66 resourceId: symbolWebhookPayload.placeholder, 63 67 tags: state.tags?.value, 68 + tool: 'typescript', 64 69 }, 65 70 name: symbolWebhookPayload.name, 66 71 placeholder: symbolWebhookPayload.placeholder, ··· 86 91 exported: true, 87 92 kind: 'type', 88 93 meta: { 94 + category: 'type', 89 95 path: state.path.value, 96 + resource: 'webhook', 97 + resourceId: operation.id, 98 + role: 'data', 90 99 tags: state.tags?.value, 100 + tool: 'typescript', 91 101 }, 92 102 name: buildName({ 93 103 config: plugin.config.webhooks, 94 104 name: operation.id, 95 105 }), 96 - selector: plugin.api.selector('webhook-request', operation.id), 97 106 }); 98 107 const type = irSchemaToAst({ 99 108 plugin,
+8 -1
packages/openapi-ts/src/plugins/@hey-api/typescript/v1/plugin.ts
··· 91 91 resource: 'definition', 92 92 resourceId: $ref, 93 93 tags: state.tags?.value, 94 + tool: 'typescript', 94 95 }, 95 96 name: buildName({ 96 97 config: plugin.config.definitions, ··· 114 115 category: 'type', 115 116 resource: 'client', 116 117 role: 'options', 118 + tool: 'typescript', 117 119 }, 118 120 name: buildName({ 119 121 config: { ··· 126 128 const symbolWebhooks = plugin.registerSymbol({ 127 129 exported: true, 128 130 kind: 'type', 131 + meta: { 132 + category: 'type', 133 + resource: 'webhook', 134 + tool: 'typescript', 135 + variant: 'container', 136 + }, 129 137 name: buildName({ 130 138 config: { 131 139 case: plugin.config.case, 132 140 }, 133 141 name: 'Webhooks', 134 142 }), 135 - selector: plugin.api.selector('Webhooks'), 136 143 }); 137 144 138 145 const servers: Array<IR.ServerObject> = [];
+19 -8
packages/openapi-ts/src/plugins/@hey-api/typescript/v1/toAst/string.ts
··· 1 + import type { SymbolMeta } from '@hey-api/codegen-core'; 1 2 import type ts from 'typescript'; 2 3 3 4 import type { SchemaWithType } from '~/plugins'; ··· 44 45 parts.pop(); // remove the ID part 45 46 const type = parts.join('_'); 46 47 47 - const selector = plugin.api.selector('TypeID', type); 48 - if (!plugin.getSymbol(selector)) { 49 - const selectorTypeId = plugin.api.selector('TypeID'); 48 + const query: SymbolMeta = { 49 + category: 'type', 50 + resource: 'type-id', 51 + resourceId: type, 52 + tool: 'typescript', 53 + }; 54 + if (!plugin.getSymbol(query)) { 55 + const queryTypeId: SymbolMeta = { 56 + category: 'type', 57 + resource: 'type-id', 58 + tool: 'typescript', 59 + variant: 'container', 60 + }; 50 61 51 - if (!plugin.getSymbol(selectorTypeId)) { 62 + if (!plugin.getSymbol(queryTypeId)) { 52 63 const symbolTypeId = plugin.registerSymbol({ 53 64 exported: true, 54 65 kind: 'type', 66 + meta: queryTypeId, 55 67 name: 'TypeID', 56 - selector: selectorTypeId, 57 68 }); 58 69 const nodeTypeId = tsc.typeAliasDeclaration({ 59 70 exportType: symbolTypeId.exported, ··· 77 88 plugin.setSymbolValue(symbolTypeId, nodeTypeId); 78 89 } 79 90 80 - const symbolTypeId = plugin.referenceSymbol(selectorTypeId); 91 + const symbolTypeId = plugin.referenceSymbol(queryTypeId); 81 92 const symbolTypeName = plugin.registerSymbol({ 82 93 exported: true, 83 94 kind: 'type', 95 + meta: query, 84 96 name: stringCase({ 85 97 case: plugin.config.case, 86 98 value: `${type}_id`, 87 99 }), 88 - selector, 89 100 }); 90 101 const node = tsc.typeAliasDeclaration({ 91 102 exportType: symbolTypeName.exported, ··· 101 112 }); 102 113 plugin.setSymbolValue(symbolTypeName, node); 103 114 } 104 - const symbol = plugin.referenceSymbol(selector); 115 + const symbol = plugin.referenceSymbol(query); 105 116 return tsc.typeReferenceNode({ typeName: symbol.placeholder }); 106 117 } 107 118 }
+1 -15
packages/openapi-ts/src/plugins/arktype/api.ts
··· 6 6 import type { ValidatorArgs } from './shared/types'; 7 7 import { createRequestValidatorV2, createResponseValidatorV2 } from './v2/api'; 8 8 9 - type SelectorType = 10 - | 'data' 11 - | 'external' 12 - | 'ref' 13 - | 'responses' 14 - | 'type-infer-data' 15 - | 'type-infer-ref' 16 - | 'type-infer-responses' 17 - | 'type-infer-webhook-request' 18 - | 'webhook-request'; 9 + type SelectorType = 'data' | 'ref' | 'responses' | 'webhook-request'; 19 10 20 11 export type IApi = { 21 12 createRequestValidator: (args: ValidatorArgs) => ts.ArrowFunction | undefined; ··· 26 17 * @param type Selector type. 27 18 * @param value Depends on `type`: 28 19 * - `data`: `operation.id` string 29 - * - `external`: external modules 30 20 * - `ref`: `$ref` JSON pointer 31 21 * - `responses`: `operation.id` string 32 - * - `type-infer-data`: `operation.id` string 33 - * - `type-infer-ref`: `$ref` JSON pointer 34 - * - `type-infer-responses`: `operation.id` string 35 - * - `type-infer-webhook-request`: `operation.id` string 36 22 * - `webhook-request`: `operation.id` string 37 23 * @returns Selector array 38 24 * @deprecated
+4 -3
packages/openapi-ts/src/plugins/arktype/shared/export.ts
··· 22 22 symbol: Symbol; 23 23 typeInferSymbol: Symbol | undefined; 24 24 }): void => { 25 - const type = plugin.referenceSymbol( 26 - plugin.api.selector('external', 'arktype.type'), 27 - ); 25 + const type = plugin.referenceSymbol({ 26 + category: 'external', 27 + resource: 'arktype.type', 28 + }); 28 29 29 30 const statement = tsc.constVariable({ 30 31 comment: plugin.config.comments
+13 -3
packages/openapi-ts/src/plugins/arktype/v2/plugin.ts
··· 27 27 }): Ast => { 28 28 let ast: Partial<Ast> = {}; 29 29 30 - // const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 30 + // const z = plugin.referenceSymbol({ 31 + // category: 'external', 32 + // resource: 'arktype.type', 33 + // }); 31 34 32 35 if (schema.$ref) { 33 36 const selector = plugin.api.selector('ref', schema.$ref); ··· 261 264 exported: true, 262 265 kind: 'type', 263 266 meta: { 267 + category: 'type', 264 268 path: state.path.value, 269 + resource: 'definition', 270 + resourceId: $ref, 271 + tool: 'arktype', 272 + variant: 'infer', 265 273 }, 266 274 name: buildName({ 267 275 config: plugin.config.definitions.types.infer, 268 276 name: baseName, 269 277 }), 270 - selector: plugin.api.selector('type-infer-ref', $ref), 271 278 }) 272 279 : undefined; 273 280 exportAst({ ··· 282 289 export const handlerV2: ArktypePlugin['Handler'] = ({ plugin }) => { 283 290 plugin.registerSymbol({ 284 291 external: 'arktype', 292 + meta: { 293 + category: 'external', 294 + resource: 'arktype.type', 295 + }, 285 296 name: 'type', 286 - selector: plugin.api.selector('external', 'arktype.type'), 287 297 }); 288 298 289 299 plugin.forEach(
+4 -3
packages/openapi-ts/src/plugins/arktype/v2/toAst/index.ts
··· 86 86 // }); 87 87 } 88 88 89 - const type = args.plugin.referenceSymbol( 90 - args.plugin.api.selector('external', 'arktype.type'), 91 - ); 89 + const type = args.plugin.referenceSymbol({ 90 + category: 'external', 91 + resource: 'arktype.type', 92 + }); 92 93 93 94 const expression = ts.factory.createCallExpression( 94 95 ts.factory.createIdentifier(type.placeholder),
+1
packages/openapi-ts/src/plugins/fastify/plugin.ts
··· 21 21 resource: 'operation', 22 22 resourceId: operation.id, 23 23 role: 'data', 24 + tool: 'typescript', 24 25 }); 25 26 if (symbolDataType) { 26 27 if (operation.body) {
-36
packages/openapi-ts/src/plugins/zod/api.ts
··· 1 - import type { Selector } from '@hey-api/codegen-core'; 2 1 import type ts from 'typescript'; 3 - 4 - import type { Plugin } from '~/plugins'; 5 2 6 3 import { 7 4 createRequestValidatorMini, ··· 11 8 import { createRequestValidatorV3, createResponseValidatorV3 } from './v3/api'; 12 9 import { createRequestValidatorV4, createResponseValidatorV4 } from './v4/api'; 13 10 14 - type SelectorType = 15 - | 'data' 16 - | 'external' 17 - | 'ref' 18 - | 'responses' 19 - | 'type-infer-data' 20 - | 'type-infer-ref' 21 - | 'type-infer-responses' 22 - | 'type-infer-webhook-request' 23 - | 'webhook-request'; 24 - 25 11 export type IApi = { 26 12 createRequestValidator: (args: ValidatorArgs) => ts.ArrowFunction | undefined; 27 13 createResponseValidator: ( 28 14 args: ValidatorArgs, 29 15 ) => ts.ArrowFunction | undefined; 30 - /** 31 - * @param type Selector type. 32 - * @param value Depends on `type`: 33 - * - `data`: `operation.id` string 34 - * - `external`: external modules 35 - * - `ref`: `$ref` JSON pointer 36 - * - `responses`: `operation.id` string 37 - * - `type-infer-data`: `operation.id` string 38 - * - `type-infer-ref`: `$ref` JSON pointer 39 - * - `type-infer-responses`: `operation.id` string 40 - * - `type-infer-webhook-request`: `operation.id` string 41 - * - `webhook-request`: `operation.id` string 42 - * @returns Selector array 43 - * @deprecated 44 - */ 45 - selector: (type: SelectorType, value?: string) => Selector; 46 16 }; 47 17 48 18 export class Api implements IApi { 49 - constructor(public meta: Plugin.Name<'zod'>) {} 50 - 51 19 createRequestValidator(args: ValidatorArgs): ts.ArrowFunction | undefined { 52 20 const { plugin } = args; 53 21 switch (plugin.config.compatibilityVersion) { ··· 72 40 default: 73 41 return createResponseValidatorV4(args); 74 42 } 75 - } 76 - 77 - selector(...args: ReadonlyArray<string | undefined>): Selector { 78 - return [this.meta.name, ...(args as Selector)]; 79 43 } 80 44 }
+1 -3
packages/openapi-ts/src/plugins/zod/config.ts
··· 11 11 >; 12 12 13 13 export const defaultConfig: ZodPlugin['Config'] = { 14 - api: new Api({ 15 - name: 'zod', 16 - }), 14 + api: new Api(), 17 15 config: { 18 16 case: 'camelCase', 19 17 comments: true,
+14 -4
packages/openapi-ts/src/plugins/zod/mini/api.ts
··· 9 9 operation, 10 10 plugin, 11 11 }: ValidatorArgs): ts.ArrowFunction | undefined => { 12 - const symbol = plugin.getSymbol(plugin.api.selector('data', operation.id)); 12 + const symbol = plugin.getSymbol({ 13 + category: 'schema', 14 + resource: 'operation', 15 + resourceId: operation.id, 16 + role: 'data', 17 + tool: 'zod', 18 + }); 13 19 if (!symbol) return; 14 20 15 21 const dataParameterName = 'data'; ··· 41 47 operation, 42 48 plugin, 43 49 }: ValidatorArgs): ts.ArrowFunction | undefined => { 44 - const symbol = plugin.getSymbol( 45 - plugin.api.selector('responses', operation.id), 46 - ); 50 + const symbol = plugin.getSymbol({ 51 + category: 'schema', 52 + resource: 'operation', 53 + resourceId: operation.id, 54 + role: 'responses', 55 + tool: 'zod', 56 + }); 47 57 if (!symbol) return; 48 58 49 59 const dataParameterName = 'data';
+27 -7
packages/openapi-ts/src/plugins/zod/mini/plugin.ts
··· 1 + import type { SymbolMeta } from '@hey-api/codegen-core'; 2 + 1 3 import { deduplicateSchema } from '~/ir/schema'; 2 4 import type { IR } from '~/ir/types'; 3 5 import { buildName } from '~/openApi/shared/utils/name'; ··· 32 34 }): Ast => { 33 35 let ast: Partial<Ast> = {}; 34 36 35 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 37 + const z = plugin.referenceSymbol({ 38 + category: 'external', 39 + resource: 'zod.z', 40 + }); 36 41 37 42 if (schema.$ref) { 38 - const selector = plugin.api.selector('ref', schema.$ref); 39 - const refSymbol = plugin.referenceSymbol(selector); 40 - if (plugin.isSymbolRegistered(selector)) { 43 + const query: SymbolMeta = { 44 + category: 'schema', 45 + resource: 'definition', 46 + resourceId: schema.$ref, 47 + tool: 'zod', 48 + }; 49 + const refSymbol = plugin.referenceSymbol(query); 50 + if (plugin.isSymbolRegistered(query)) { 41 51 const ref = tsc.identifier({ text: refSymbol.placeholder }); 42 52 ast.expression = ref; 43 53 } else { ··· 238 248 const symbol = plugin.registerSymbol({ 239 249 exported: true, 240 250 meta: { 251 + category: 'schema', 241 252 path: state.path.value, 253 + resource: 'definition', 254 + resourceId: $ref, 242 255 tags: state.tags?.value, 256 + tool: 'zod', 243 257 }, 244 258 name: buildName({ 245 259 config: plugin.config.definitions, 246 260 name: baseName, 247 261 }), 248 - selector: plugin.api.selector('ref', $ref), 249 262 }); 250 263 const typeInferSymbol = plugin.config.definitions.types.infer.enabled 251 264 ? plugin.registerSymbol({ 252 265 exported: true, 253 266 kind: 'type', 254 267 meta: { 268 + category: 'type', 255 269 path: state.path.value, 270 + resource: 'definition', 271 + resourceId: $ref, 256 272 tags: state.tags?.value, 273 + tool: 'zod', 274 + variant: 'infer', 257 275 }, 258 276 name: buildName({ 259 277 config: plugin.config.definitions.types.infer, 260 278 name: baseName, 261 279 }), 262 - selector: plugin.api.selector('type-infer-ref', $ref), 263 280 }) 264 281 : undefined; 265 282 exportAst({ ··· 275 292 plugin.registerSymbol({ 276 293 external: getZodModule({ plugin }), 277 294 importKind: 'namespace', 295 + meta: { 296 + category: 'external', 297 + resource: 'zod.z', 298 + }, 278 299 name: 'z', 279 - selector: plugin.api.selector('external', 'zod.z'), 280 300 }); 281 301 282 302 plugin.forEach(
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/array.ts
··· 17 17 }: IrSchemaToAstOptions & { 18 18 schema: SchemaWithType<'array'>; 19 19 }): Omit<Ast, 'typeName'> => { 20 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 20 + const z = plugin.referenceSymbol({ 21 + category: 'external', 22 + resource: 'zod.z', 23 + }); 21 24 22 25 const result: Partial<Omit<Ast, 'typeName'>> = {}; 23 26
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/boolean.ts
··· 10 10 }: IrSchemaToAstOptions & { 11 11 schema: SchemaWithType<'boolean'>; 12 12 }): Omit<Ast, 'typeName'> => { 13 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 13 + const z = plugin.referenceSymbol({ 14 + category: 'external', 15 + resource: 'zod.z', 16 + }); 14 17 15 18 const result: Partial<Omit<Ast, 'typeName'>> = {}; 16 19
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/enum.ts
··· 14 14 }: IrSchemaToAstOptions & { 15 15 schema: SchemaWithType<'enum'>; 16 16 }): Omit<Ast, 'typeName'> => { 17 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 17 + const z = plugin.referenceSymbol({ 18 + category: 'external', 19 + resource: 'zod.z', 20 + }); 18 21 19 22 const result: Partial<Omit<Ast, 'typeName'>> = {}; 20 23
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/never.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'never'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/null.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'null'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/number.ts
··· 13 13 }: IrSchemaToAstOptions & { 14 14 schema: SchemaWithType<'integer' | 'number'>; 15 15 }): Omit<Ast, 'typeName'> => { 16 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 16 + const z = plugin.referenceSymbol({ 17 + category: 'external', 18 + resource: 'zod.z', 19 + }); 17 20 18 21 const result: Partial<Omit<Ast, 'typeName'>> = {}; 19 22
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/object.ts
··· 16 16 }: IrSchemaToAstOptions & { 17 17 schema: SchemaWithType<'object'>; 18 18 }): Omit<Ast, 'typeName'> => { 19 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 19 + const z = plugin.referenceSymbol({ 20 + category: 'external', 21 + resource: 'zod.z', 22 + }); 20 23 21 24 const result: Partial<Omit<Ast, 'typeName'>> = {}; 22 25
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/string.ts
··· 12 12 }: IrSchemaToAstOptions & { 13 13 schema: SchemaWithType<'string'>; 14 14 }): Omit<Ast, 'typeName'> => { 15 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 15 + const z = plugin.referenceSymbol({ 16 + category: 'external', 17 + resource: 'zod.z', 18 + }); 16 19 17 20 const result: Partial<Omit<Ast, 'typeName'>> = {}; 18 21
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/tuple.ts
··· 15 15 }: IrSchemaToAstOptions & { 16 16 schema: SchemaWithType<'tuple'>; 17 17 }): Omit<Ast, 'typeName'> => { 18 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 18 + const z = plugin.referenceSymbol({ 19 + category: 'external', 20 + resource: 'zod.z', 21 + }); 19 22 20 23 const result: Partial<Omit<Ast, 'typeName'>> = {}; 21 24
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/undefined.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'undefined'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/unknown.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'unknown'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/mini/toAst/void.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'void'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/shared/export.ts
··· 22 22 symbol: Symbol; 23 23 typeInferSymbol: Symbol | undefined; 24 24 }): void => { 25 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 25 + const z = plugin.referenceSymbol({ 26 + category: 'external', 27 + resource: 'zod.z', 28 + }); 26 29 27 30 const statement = tsc.constVariable({ 28 31 comment: plugin.config.comments
+22 -7
packages/openapi-ts/src/plugins/zod/shared/operation.ts
··· 119 119 const symbol = plugin.registerSymbol({ 120 120 exported: true, 121 121 meta: { 122 + category: 'schema', 122 123 path: state.path.value, 124 + resource: 'operation', 125 + resourceId: operation.id, 126 + role: 'data', 123 127 tags: state.tags?.value, 128 + tool: 'zod', 124 129 }, 125 130 name: buildName({ 126 131 config: plugin.config.requests, 127 132 name: operation.id, 128 133 }), 129 - selector: plugin.api.selector('data', operation.id), 130 134 }); 131 135 const typeInferSymbol = plugin.config.requests.types.infer.enabled 132 136 ? plugin.registerSymbol({ 133 137 exported: true, 134 138 kind: 'type', 135 139 meta: { 140 + category: 'type', 136 141 path: state.path.value, 142 + resource: 'operation', 143 + resourceId: operation.id, 144 + role: 'data', 137 145 tags: state.tags?.value, 146 + tool: 'zod', 147 + variant: 'infer', 138 148 }, 139 149 name: buildName({ 140 150 config: plugin.config.requests.types.infer, 141 151 name: operation.id, 142 152 }), 143 - selector: plugin.api.selector('type-infer-data', operation.id), 144 153 }) 145 154 : undefined; 146 155 exportAst({ ··· 162 171 const symbol = plugin.registerSymbol({ 163 172 exported: true, 164 173 meta: { 174 + category: 'schema', 165 175 path, 176 + resource: 'operation', 177 + resourceId: operation.id, 178 + role: 'responses', 166 179 tags: state.tags?.value, 180 + tool: 'zod', 167 181 }, 168 182 name: buildName({ 169 183 config: plugin.config.responses, 170 184 name: operation.id, 171 185 }), 172 - selector: plugin.api.selector('responses', operation.id), 173 186 }); 174 187 const typeInferSymbol = plugin.config.responses.types.infer.enabled 175 188 ? plugin.registerSymbol({ 176 189 exported: true, 177 190 kind: 'type', 178 191 meta: { 192 + category: 'type', 179 193 path, 194 + resource: 'operation', 195 + resourceId: operation.id, 196 + role: 'responses', 180 197 tags: state.tags?.value, 198 + tool: 'zod', 199 + variant: 'infer', 181 200 }, 182 201 name: buildName({ 183 202 config: plugin.config.responses.types.infer, 184 203 name: operation.id, 185 204 }), 186 - selector: plugin.api.selector( 187 - 'type-infer-responses', 188 - operation.id, 189 - ), 190 205 }) 191 206 : undefined; 192 207 exportAst({
+11 -5
packages/openapi-ts/src/plugins/zod/shared/webhook.ts
··· 118 118 const symbol = plugin.registerSymbol({ 119 119 exported: true, 120 120 meta: { 121 + category: 'schema', 121 122 path: state.path.value, 123 + resource: 'webhook', 124 + resourceId: operation.id, 125 + role: 'data', 122 126 tags: state.tags?.value, 127 + tool: 'zod', 123 128 }, 124 129 name: buildName({ 125 130 config: plugin.config.webhooks, 126 131 name: operation.id, 127 132 }), 128 - selector: plugin.api.selector('webhook-request', operation.id), 129 133 }); 130 134 const typeInferSymbol = plugin.config.webhooks.types.infer.enabled 131 135 ? plugin.registerSymbol({ 132 136 exported: true, 133 137 kind: 'type', 134 138 meta: { 139 + category: 'type', 135 140 path: state.path.value, 141 + resource: 'webhook', 142 + resourceId: operation.id, 143 + role: 'data', 136 144 tags: state.tags?.value, 145 + tool: 'zod', 146 + variant: 'infer', 137 147 }, 138 148 name: buildName({ 139 149 config: plugin.config.webhooks.types.infer, 140 150 name: operation.id, 141 151 }), 142 - selector: plugin.api.selector( 143 - 'type-infer-webhook-request', 144 - operation.id, 145 - ), 146 152 }) 147 153 : undefined; 148 154 exportAst({
+14 -4
packages/openapi-ts/src/plugins/zod/v3/api.ts
··· 9 9 operation, 10 10 plugin, 11 11 }: ValidatorArgs): ts.ArrowFunction | undefined => { 12 - const symbol = plugin.getSymbol(plugin.api.selector('data', operation.id)); 12 + const symbol = plugin.getSymbol({ 13 + category: 'schema', 14 + resource: 'operation', 15 + resourceId: operation.id, 16 + role: 'data', 17 + tool: 'zod', 18 + }); 13 19 if (!symbol) return; 14 20 15 21 const dataParameterName = 'data'; ··· 41 47 operation, 42 48 plugin, 43 49 }: ValidatorArgs): ts.ArrowFunction | undefined => { 44 - const symbol = plugin.getSymbol( 45 - plugin.api.selector('responses', operation.id), 46 - ); 50 + const symbol = plugin.getSymbol({ 51 + category: 'schema', 52 + resource: 'operation', 53 + resourceId: operation.id, 54 + role: 'responses', 55 + tool: 'zod', 56 + }); 47 57 if (!symbol) return; 48 58 49 59 const dataParameterName = 'data';
+27 -7
packages/openapi-ts/src/plugins/zod/v3/plugin.ts
··· 1 + import type { SymbolMeta } from '@hey-api/codegen-core'; 2 + 1 3 import { deduplicateSchema } from '~/ir/schema'; 2 4 import type { IR } from '~/ir/types'; 3 5 import { buildName } from '~/openApi/shared/utils/name'; ··· 32 34 }): Ast => { 33 35 let ast: Partial<Ast> = {}; 34 36 35 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 37 + const z = plugin.referenceSymbol({ 38 + category: 'external', 39 + resource: 'zod.z', 40 + }); 36 41 37 42 if (schema.$ref) { 38 - const selector = plugin.api.selector('ref', schema.$ref); 39 - const refSymbol = plugin.referenceSymbol(selector); 40 - if (plugin.isSymbolRegistered(selector)) { 43 + const query: SymbolMeta = { 44 + category: 'schema', 45 + resource: 'definition', 46 + resourceId: schema.$ref, 47 + tool: 'zod', 48 + }; 49 + const refSymbol = plugin.referenceSymbol(query); 50 + if (plugin.isSymbolRegistered(query)) { 41 51 const ref = tsc.identifier({ text: refSymbol.placeholder }); 42 52 ast.expression = ref; 43 53 } else { ··· 212 222 const symbol = plugin.registerSymbol({ 213 223 exported: true, 214 224 meta: { 225 + category: 'schema', 215 226 path: state.path.value, 227 + resource: 'definition', 228 + resourceId: $ref, 216 229 tags: state.tags?.value, 230 + tool: 'zod', 217 231 }, 218 232 name: buildName({ 219 233 config: plugin.config.definitions, 220 234 name: baseName, 221 235 }), 222 - selector: plugin.api.selector('ref', $ref), 223 236 }); 224 237 const typeInferSymbol = plugin.config.definitions.types.infer.enabled 225 238 ? plugin.registerSymbol({ 226 239 exported: true, 227 240 kind: 'type', 228 241 meta: { 242 + category: 'type', 229 243 path: state.path.value, 244 + resource: 'definition', 245 + resourceId: $ref, 230 246 tags: state.tags?.value, 247 + tool: 'zod', 248 + variant: 'infer', 231 249 }, 232 250 name: buildName({ 233 251 config: plugin.config.definitions.types.infer, 234 252 name: baseName, 235 253 }), 236 - selector: plugin.api.selector('type-infer-ref', $ref), 237 254 }) 238 255 : undefined; 239 256 exportAst({ ··· 248 265 export const handlerV3: ZodPlugin['Handler'] = ({ plugin }) => { 249 266 plugin.registerSymbol({ 250 267 external: getZodModule({ plugin }), 268 + meta: { 269 + category: 'external', 270 + resource: 'zod.z', 271 + }, 251 272 name: 'z', 252 - selector: plugin.api.selector('external', 'zod.z'), 253 273 }); 254 274 255 275 plugin.forEach(
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/array.ts
··· 19 19 }): Omit<Ast, 'typeName'> & { 20 20 anyType?: string; 21 21 } => { 22 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 22 + const z = plugin.referenceSymbol({ 23 + category: 'external', 24 + resource: 'zod.z', 25 + }); 23 26 24 27 const functionName = tsc.propertyAccessExpression({ 25 28 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/boolean.ts
··· 10 10 }: IrSchemaToAstOptions & { 11 11 schema: SchemaWithType<'boolean'>; 12 12 }) => { 13 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 13 + const z = plugin.referenceSymbol({ 14 + category: 'external', 15 + resource: 'zod.z', 16 + }); 14 17 15 18 if (typeof schema.const === 'boolean') { 16 19 const expression = tsc.callExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/enum.ts
··· 14 14 }: IrSchemaToAstOptions & { 15 15 schema: SchemaWithType<'enum'>; 16 16 }): ts.CallExpression => { 17 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 17 + const z = plugin.referenceSymbol({ 18 + category: 'external', 19 + resource: 'zod.z', 20 + }); 18 21 19 22 const enumMembers: Array<ts.LiteralExpression> = []; 20 23 const literalMembers: Array<ts.CallExpression> = [];
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/never.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'never'>; 11 11 }) => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const expression = tsc.callExpression({ 14 17 functionName: tsc.propertyAccessExpression({ 15 18 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/null.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'null'>; 11 11 }) => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const expression = tsc.callExpression({ 14 17 functionName: tsc.propertyAccessExpression({ 15 18 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/number.ts
··· 11 11 }: IrSchemaToAstOptions & { 12 12 schema: SchemaWithType<'integer' | 'number'>; 13 13 }) => { 14 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 14 + const z = plugin.referenceSymbol({ 15 + category: 'external', 16 + resource: 'zod.z', 17 + }); 15 18 16 19 const isBigInt = schema.type === 'integer' && schema.format === 'int64'; 17 20
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/object.ts
··· 18 18 }): Omit<Ast, 'typeName'> & { 19 19 anyType?: string; 20 20 } => { 21 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 21 + const z = plugin.referenceSymbol({ 22 + category: 'external', 23 + resource: 'zod.z', 24 + }); 22 25 23 26 let hasLazyExpression = false; 24 27
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/string.ts
··· 10 10 }: IrSchemaToAstOptions & { 11 11 schema: SchemaWithType<'string'>; 12 12 }) => { 13 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 13 + const z = plugin.referenceSymbol({ 14 + category: 'external', 15 + resource: 'zod.z', 16 + }); 14 17 15 18 if (typeof schema.const === 'string') { 16 19 const expression = tsc.callExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/tuple.ts
··· 17 17 }): Omit<Ast, 'typeName'> & { 18 18 anyType?: string; 19 19 } => { 20 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 20 + const z = plugin.referenceSymbol({ 21 + category: 'external', 22 + resource: 'zod.z', 23 + }); 21 24 22 25 let hasLazyExpression = false; 23 26
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/undefined.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'undefined'>; 11 11 }) => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const expression = tsc.callExpression({ 14 17 functionName: tsc.propertyAccessExpression({ 15 18 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/unknown.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'unknown'>; 11 11 }) => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const expression = tsc.callExpression({ 14 17 functionName: tsc.propertyAccessExpression({ 15 18 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v3/toAst/void.ts
··· 9 9 }: IrSchemaToAstOptions & { 10 10 schema: SchemaWithType<'void'>; 11 11 }) => { 12 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 12 + const z = plugin.referenceSymbol({ 13 + category: 'external', 14 + resource: 'zod.z', 15 + }); 13 16 const expression = tsc.callExpression({ 14 17 functionName: tsc.propertyAccessExpression({ 15 18 expression: z.placeholder,
+14 -4
packages/openapi-ts/src/plugins/zod/v4/api.ts
··· 9 9 operation, 10 10 plugin, 11 11 }: ValidatorArgs): ts.ArrowFunction | undefined => { 12 - const symbol = plugin.getSymbol(plugin.api.selector('data', operation.id)); 12 + const symbol = plugin.getSymbol({ 13 + category: 'schema', 14 + resource: 'operation', 15 + resourceId: operation.id, 16 + role: 'data', 17 + tool: 'zod', 18 + }); 13 19 if (!symbol) return; 14 20 15 21 const dataParameterName = 'data'; ··· 41 47 operation, 42 48 plugin, 43 49 }: ValidatorArgs): ts.ArrowFunction | undefined => { 44 - const symbol = plugin.getSymbol( 45 - plugin.api.selector('responses', operation.id), 46 - ); 50 + const symbol = plugin.getSymbol({ 51 + category: 'schema', 52 + resource: 'operation', 53 + resourceId: operation.id, 54 + role: 'responses', 55 + tool: 'zod', 56 + }); 47 57 if (!symbol) return; 48 58 49 59 const dataParameterName = 'data';
+27 -7
packages/openapi-ts/src/plugins/zod/v4/plugin.ts
··· 1 + import type { SymbolMeta } from '@hey-api/codegen-core'; 2 + 1 3 import { deduplicateSchema } from '~/ir/schema'; 2 4 import type { IR } from '~/ir/types'; 3 5 import { buildName } from '~/openApi/shared/utils/name'; ··· 32 34 }): Ast => { 33 35 let ast: Partial<Ast> = {}; 34 36 35 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 37 + const z = plugin.referenceSymbol({ 38 + category: 'external', 39 + resource: 'zod.z', 40 + }); 36 41 37 42 if (schema.$ref) { 38 - const selector = plugin.api.selector('ref', schema.$ref); 39 - const refSymbol = plugin.referenceSymbol(selector); 40 - if (plugin.isSymbolRegistered(selector)) { 43 + const query: SymbolMeta = { 44 + category: 'schema', 45 + resource: 'definition', 46 + resourceId: schema.$ref, 47 + tool: 'zod', 48 + }; 49 + const refSymbol = plugin.referenceSymbol(query); 50 + if (plugin.isSymbolRegistered(query)) { 41 51 const ref = tsc.identifier({ text: refSymbol.placeholder }); 42 52 ast.expression = ref; 43 53 } else { ··· 240 250 const symbol = plugin.registerSymbol({ 241 251 exported: true, 242 252 meta: { 253 + category: 'schema', 243 254 path: state.path.value, 255 + resource: 'definition', 256 + resourceId: $ref, 244 257 tags: state.tags?.value, 258 + tool: 'zod', 245 259 }, 246 260 name: buildName({ 247 261 config: plugin.config.definitions, 248 262 name: baseName, 249 263 }), 250 - selector: plugin.api.selector('ref', $ref), 251 264 }); 252 265 const typeInferSymbol = plugin.config.definitions.types.infer.enabled 253 266 ? plugin.registerSymbol({ 254 267 exported: true, 255 268 kind: 'type', 256 269 meta: { 270 + category: 'type', 257 271 path: state.path.value, 272 + resource: 'definition', 273 + resourceId: $ref, 258 274 tags: state.tags?.value, 275 + tool: 'zod', 276 + variant: 'infer', 259 277 }, 260 278 name: buildName({ 261 279 config: plugin.config.definitions.types.infer, 262 280 name: baseName, 263 281 }), 264 - selector: plugin.api.selector('type-infer-ref', $ref), 265 282 }) 266 283 : undefined; 267 284 exportAst({ ··· 276 293 export const handlerV4: ZodPlugin['Handler'] = ({ plugin }) => { 277 294 plugin.registerSymbol({ 278 295 external: getZodModule({ plugin }), 296 + meta: { 297 + category: 'external', 298 + resource: 'zod.z', 299 + }, 279 300 name: 'z', 280 - selector: plugin.api.selector('external', 'zod.z'), 281 301 }); 282 302 283 303 plugin.forEach(
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/array.ts
··· 19 19 }): Omit<Ast, 'typeName'> => { 20 20 const result: Partial<Omit<Ast, 'typeName'>> = {}; 21 21 22 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 22 + const z = plugin.referenceSymbol({ 23 + category: 'external', 24 + resource: 'zod.z', 25 + }); 23 26 24 27 const functionName = tsc.propertyAccessExpression({ 25 28 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/boolean.ts
··· 12 12 }): Omit<Ast, 'typeName'> => { 13 13 const result: Partial<Omit<Ast, 'typeName'>> = {}; 14 14 15 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 15 + const z = plugin.referenceSymbol({ 16 + category: 'external', 17 + resource: 'zod.z', 18 + }); 16 19 17 20 if (typeof schema.const === 'boolean') { 18 21 result.expression = tsc.callExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/enum.ts
··· 16 16 }): Omit<Ast, 'typeName'> => { 17 17 const result: Partial<Omit<Ast, 'typeName'>> = {}; 18 18 19 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 19 + const z = plugin.referenceSymbol({ 20 + category: 'external', 21 + resource: 'zod.z', 22 + }); 20 23 21 24 const enumMembers: Array<ts.LiteralExpression> = []; 22 25 const literalMembers: Array<ts.CallExpression> = [];
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/never.ts
··· 10 10 schema: SchemaWithType<'never'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 12 const result: Partial<Omit<Ast, 'typeName'>> = {}; 13 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 13 + const z = plugin.referenceSymbol({ 14 + category: 'external', 15 + resource: 'zod.z', 16 + }); 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({ 16 19 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/null.ts
··· 10 10 schema: SchemaWithType<'null'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 12 const result: Partial<Omit<Ast, 'typeName'>> = {}; 13 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 13 + const z = plugin.referenceSymbol({ 14 + category: 'external', 15 + resource: 'zod.z', 16 + }); 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({ 16 19 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/number.ts
··· 15 15 16 16 const isBigInt = schema.type === 'integer' && schema.format === 'int64'; 17 17 18 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 18 + const z = plugin.referenceSymbol({ 19 + category: 'external', 20 + resource: 'zod.z', 21 + }); 19 22 20 23 if (typeof schema.const === 'number') { 21 24 // TODO: parser - handle bigint constants
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/object.ts
··· 24 24 25 25 const required = schema.required ?? []; 26 26 27 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 27 + const z = plugin.referenceSymbol({ 28 + category: 'external', 29 + resource: 'zod.z', 30 + }); 28 31 29 32 for (const name in schema.properties) { 30 33 const property = schema.properties[name]!;
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/string.ts
··· 12 12 }): Omit<Ast, 'typeName'> => { 13 13 const result: Partial<Omit<Ast, 'typeName'>> = {}; 14 14 15 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 15 + const z = plugin.referenceSymbol({ 16 + category: 'external', 17 + resource: 'zod.z', 18 + }); 16 19 17 20 if (typeof schema.const === 'string') { 18 21 result.expression = tsc.callExpression({
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/tuple.ts
··· 17 17 }): Omit<Ast, 'typeName'> => { 18 18 const result: Partial<Omit<Ast, 'typeName'>> = {}; 19 19 20 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 20 + const z = plugin.referenceSymbol({ 21 + category: 'external', 22 + resource: 'zod.z', 23 + }); 21 24 22 25 if (schema.const && Array.isArray(schema.const)) { 23 26 const tupleElements = schema.const.map((value) =>
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/undefined.ts
··· 10 10 schema: SchemaWithType<'undefined'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 12 const result: Partial<Omit<Ast, 'typeName'>> = {}; 13 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 13 + const z = plugin.referenceSymbol({ 14 + category: 'external', 15 + resource: 'zod.z', 16 + }); 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({ 16 19 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/unknown.ts
··· 10 10 schema: SchemaWithType<'unknown'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 12 const result: Partial<Omit<Ast, 'typeName'>> = {}; 13 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 13 + const z = plugin.referenceSymbol({ 14 + category: 'external', 15 + resource: 'zod.z', 16 + }); 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({ 16 19 expression: z.placeholder,
+4 -1
packages/openapi-ts/src/plugins/zod/v4/toAst/void.ts
··· 10 10 schema: SchemaWithType<'void'>; 11 11 }): Omit<Ast, 'typeName'> => { 12 12 const result: Partial<Omit<Ast, 'typeName'>> = {}; 13 - const z = plugin.referenceSymbol(plugin.api.selector('external', 'zod.z')); 13 + const z = plugin.referenceSymbol({ 14 + category: 'external', 15 + resource: 'zod.z', 16 + }); 14 17 result.expression = tsc.callExpression({ 15 18 functionName: tsc.propertyAccessExpression({ 16 19 expression: z.placeholder,
-2
packages/openapi-ts/src/utils/__tests__/handlebars.test.ts
··· 105 105 '@hey-api/typescript': { 106 106 api: { 107 107 schemaToType: () => ({}) as ts.TypeNode, 108 - selector: () => [], 109 108 }, 110 109 config: { 111 110 enums: 'javascript', ··· 235 234 '@hey-api/typescript': { 236 235 api: { 237 236 schemaToType: () => ({}) as ts.TypeNode, 238 - selector: () => [], 239 237 }, 240 238 config: { 241 239 enums: 'javascript',