From 208811923fc2f32bad1322158fda9d83468bc011 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 30 Oct 2025 06:19:48 +0800 Subject: [PATCH] refactor: remove selectors from sdk plugin --- .vscode/launch.json | 5 +- dev/openapi-ts.config.ts | 8 +-- .../src/__tests__/symbols.test.ts | 39 +++++++++++ packages/codegen-core/src/symbols/registry.ts | 7 ++ packages/openapi-ts/src/index.ts | 1 + .../plugins/@angular/common/httpRequests.ts | 18 ++--- .../plugins/@angular/common/httpResources.ts | 18 ++--- .../src/plugins/@hey-api/sdk/api.ts | 40 +---------- .../src/plugins/@hey-api/sdk/config.ts | 4 +- .../src/plugins/@hey-api/sdk/shared/class.ts | 66 ++++++++++++------- .../plugins/@hey-api/sdk/shared/functions.ts | 11 +++- .../plugins/@hey-api/sdk/shared/operation.ts | 27 +++++--- .../@hey-api/sdk/shared/typeOptions.ts | 19 ++++-- .../src/plugins/@hey-api/sdk/v1/plugin.ts | 33 +++++++--- .../src/plugins/@pinia/colada/plugin.ts | 17 +++-- .../src/plugins/@pinia/colada/queryKey.ts | 18 ++--- .../plugins/@tanstack/query-core/plugin.ts | 17 +++-- .../plugins/@tanstack/query-core/queryKey.ts | 18 ++--- 18 files changed, 226 insertions(+), 140 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8321ec401..edbd4ea4b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,7 +16,10 @@ "cwd": "${workspaceFolder}/dev", "runtimeExecutable": "node", "runtimeArgs": ["-r", "ts-node/register/transpile-only"], - "program": "${workspaceFolder}/packages/openapi-ts/src/run.ts" + "program": "${workspaceFolder}/packages/openapi-ts/src/run.ts", + "env": { + "DEBUG": "false" + } } ] } diff --git a/dev/openapi-ts.config.ts b/dev/openapi-ts.config.ts index 9f4b5a0b7..49cf75c92 100644 --- a/dev/openapi-ts.config.ts +++ b/dev/openapi-ts.config.ts @@ -40,9 +40,9 @@ export default defineConfig(() => { // 'dutchie.json', // 'invalid', // 'openai.yaml', - 'full.yaml', + // 'full.yaml', // 'opencode.yaml', - // 'sdk-instance.yaml', + 'sdk-instance.yaml', // 'string-with-format.yaml', // 'transformers.json', // 'type-format.yaml', @@ -214,7 +214,7 @@ export default defineConfig(() => { { // baseUrl: false, // exportFromIndex: true, - name: '@hey-api/client-fetch', + // name: '@hey-api/client-fetch', // name: 'legacy/angular', // runtimeConfigPath: path.resolve(__dirname, 'hey-api.ts'), // runtimeConfigPath: './src/hey-api.ts', @@ -259,7 +259,7 @@ export default defineConfig(() => { // fields.unwrap('path') // }, // include... - // instance: true, + instance: true, name: '@hey-api/sdk', // operationId: false, // params_EXPERIMENTAL: 'experiment', diff --git a/packages/codegen-core/src/__tests__/symbols.test.ts b/packages/codegen-core/src/__tests__/symbols.test.ts index 596be15b9..f8018bdd7 100644 --- a/packages/codegen-core/src/__tests__/symbols.test.ts +++ b/packages/codegen-core/src/__tests__/symbols.test.ts @@ -230,4 +230,43 @@ describe('SymbolRegistry', () => { expect(cacheKeys3.length).toBe(3); expect(registry['queryCache'].get(cacheKeys3[2]!)).toEqual([]); }); + + it('returns the same stub reference for identical unresolved meta', () => { + const registry = new SymbolRegistry(); + + const stubA1 = registry.reference({ a: 1 }); + const stubA2 = registry.reference({ a: 1 }); + + // Same reference, not new instance + expect(stubA1).toBe(stubA2); + + // Cache entry created by the internal query call + const cacheKey = registry['buildCacheKey']({ a: 1 }); + expect(registry['queryCache'].has(cacheKey)).toBe(true); + expect(registry['queryCache'].get(cacheKey)).toEqual([]); + }); + + it('demonstrates stub addition does not invalidate unrelated cache', () => { + const registry = new SymbolRegistry(); + + // Create one indexed symbol and one query to seed cache + const symA = registry.register({ meta: { foo: 'bar' }, name: 'A' }); + const resultFoo = registry.query({ foo: 'bar' }); + expect(resultFoo).toEqual([symA]); + const cacheKeysBefore = Array.from(registry['queryCache'].keys()); + expect(cacheKeysBefore.length).toBe(1); + + // Add unrelated stub (its meta triggers its own query) + const stub = registry.reference({ something: 'else' }); + expect(stub.meta).toEqual({ something: 'else' }); + + // Existing cache entry still present, plus one new entry for stub + const cacheKeysAfter = Array.from(registry['queryCache'].keys()); + expect(cacheKeysAfter.length).toBe(cacheKeysBefore.length + 1); + expect(cacheKeysAfter).toEqual(expect.arrayContaining(cacheKeysBefore)); + + // The new stub isn't indexed, so query returns nothing yet + const newQuery = registry.query({ something: 'else' }); + expect(newQuery).toEqual([]); + }); }); diff --git a/packages/codegen-core/src/symbols/registry.ts b/packages/codegen-core/src/symbols/registry.ts index 9790a3833..ad0626839 100644 --- a/packages/codegen-core/src/symbols/registry.ts +++ b/packages/codegen-core/src/symbols/registry.ts @@ -23,6 +23,7 @@ export class SymbolRegistry implements ISymbolRegistry { private registerOrder: Set = new Set(); // TODO: remove after removing selectors private selectorToId: Map = new Map(); + private stubCache: Map = new Map(); private stubs: Set = new Set(); private values: Map = new Map(); @@ -118,6 +119,9 @@ export class SymbolRegistry implements ISymbolRegistry { } const [registered] = this.query(symbol.meta); if (registered) return registered; + const cacheKey = this.buildCacheKey(symbol.meta); + const cachedId = this.stubCache.get(cacheKey); + if (cachedId !== undefined) return this.values.get(cachedId)!; const id = this.id; const stub: ISymbolOut = { exportFrom: [], @@ -127,6 +131,7 @@ export class SymbolRegistry implements ISymbolRegistry { }; this.values.set(stub.id, stub); this.stubs.add(stub.id); + this.stubCache.set(cacheKey, stub.id); return stub; } @@ -294,6 +299,8 @@ export class SymbolRegistry implements ISymbolRegistry { stub?.meta && this.isSubset(this.buildIndexKeySpace(stub.meta), indexKeySpace) ) { + const cacheKey = this.buildCacheKey(stub.meta); + this.stubCache.delete(cacheKey); this.values.set(stubId, Object.assign(stub, symbol)); this.stubs.delete(stubId); } diff --git a/packages/openapi-ts/src/index.ts b/packages/openapi-ts/src/index.ts index dce20a4e2..eb3deb813 100644 --- a/packages/openapi-ts/src/index.ts +++ b/packages/openapi-ts/src/index.ts @@ -57,6 +57,7 @@ declare module '@hey-api/codegen-core' { | 'arktype' | 'fastify' | 'json-schema' + | 'sdk' | 'typescript' | 'valibot' | 'zod' diff --git a/packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts b/packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts index 63fa4be6e..6390a68e1 100644 --- a/packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts +++ b/packages/openapi-ts/src/plugins/@angular/common/httpRequests.ts @@ -289,10 +289,11 @@ const generateAngularRequestMethod = ({ resource: '@angular/common/http.HttpRequest', }); - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - const symbolOptions = plugin.referenceSymbol( - sdkPlugin.api.selector('Options'), - ); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); const symbolDataType = plugin.querySymbol({ category: 'type', @@ -349,10 +350,11 @@ const generateAngularRequestFunction = ({ resource: '@angular/common/http.HttpRequest', }); - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - const symbolOptions = plugin.referenceSymbol( - sdkPlugin.api.selector('Options'), - ); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); const symbolDataType = plugin.querySymbol({ category: 'type', diff --git a/packages/openapi-ts/src/plugins/@angular/common/httpResources.ts b/packages/openapi-ts/src/plugins/@angular/common/httpResources.ts index a66d04b84..9e668a46a 100644 --- a/packages/openapi-ts/src/plugins/@angular/common/httpResources.ts +++ b/packages/openapi-ts/src/plugins/@angular/common/httpResources.ts @@ -375,10 +375,11 @@ const generateAngularResourceMethod = ({ operation: IR.OperationObject; plugin: AngularCommonPlugin['Instance']; }) => { - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - const symbolOptions = plugin.referenceSymbol( - sdkPlugin.api.selector('Options'), - ); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); const symbolDataType = plugin.querySymbol({ category: 'type', @@ -430,10 +431,11 @@ const generateAngularResourceFunction = ({ plugin: AngularCommonPlugin['Instance']; symbol: Symbol; }) => { - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - const symbolOptions = plugin.referenceSymbol( - sdkPlugin.api.selector('Options'), - ); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); const symbolDataType = plugin.querySymbol({ category: 'type', diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/api.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/api.ts index c24450163..1496308d2 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/api.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/api.ts @@ -1,39 +1,3 @@ -import type { Selector } from '@hey-api/codegen-core'; +export type IApi = any; -import type { Plugin } from '~/plugins'; - -type SelectorType = - | 'buildClientParams' - | 'class' - | 'Client' - | 'Composable' - | 'formDataBodySerializer' - | 'function' - | 'Options' - | 'urlSearchParamsBodySerializer'; - -export type IApi = { - /** - * @param type Selector type. - * @param value Depends on `type`: - * - `buildClientParams`: never - * - `class`: current class name - * - `Client`: never - * - `Composable`: never - * - `formDataBodySerializer`: never - * - `function`: `operation.id` string - * - `Options`: never - * - `urlSearchParamsBodySerializer`: never - * @returns Selector array - * @deprecated - */ - selector: (type: SelectorType, value?: string) => Selector; -}; - -export class Api implements IApi { - constructor(public meta: Plugin.Name<'@hey-api/sdk'>) {} - - selector(...args: ReadonlyArray): Selector { - return [this.meta.name, ...(args as Selector)]; - } -} +export class Api implements IApi {} diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts index 956f1e584..85e8d4ca6 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts @@ -6,9 +6,7 @@ import { handlerLegacy } from './plugin-legacy'; import type { HeyApiSdkPlugin } from './types'; export const defaultConfig: HeyApiSdkPlugin['Config'] = { - api: new Api({ - name: '@hey-api/sdk', - }), + api: new Api(), config: { asClass: false, auth: true, 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 7ae0685af..f93341a3d 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 @@ -22,9 +22,9 @@ type SdkClassEntry = { */ className: string; /** - * Symbol IDs for child classes located inside this class. + * Class names for child classes located inside this class. */ - classes: Set; + classes: Set; /** * Symbol ID for the class. */ @@ -62,7 +62,10 @@ const createClientClassNodes = ({ }), }); - const symbolClient = plugin.referenceSymbol(plugin.api.selector('Client')); + const symbolClient = plugin.referenceSymbol({ + category: 'external', + resource: 'client.Client', + }); const symClient = plugin.getSymbol({ category: 'client', }); @@ -122,11 +125,11 @@ export const generateClassSdk = ({ const client = getClientPlugin(plugin.context.config); const isAngularClient = client.name === '@hey-api/client-angular'; const isNuxtClient = client.name === '@hey-api/client-nuxt'; - const sdkClasses = new Map(); + const sdkClasses = new Map(); /** * Track unique added classes. */ - const generatedClasses = new Set(); + const generatedClasses = new Set(); const clientClassNodes = plugin.config.instance ? createClientClassNodes({ plugin }) @@ -156,11 +159,14 @@ export const generateClassSdk = ({ for (const entry of classes.values()) { entry.path.forEach((currentClassName, index) => { - const symbolCurrentClass = plugin.referenceSymbol( - plugin.api.selector('class', currentClassName), - ); - if (!sdkClasses.has(symbolCurrentClass.id)) { - sdkClasses.set(symbolCurrentClass.id, { + const symbolCurrentClass = plugin.referenceSymbol({ + category: 'utility', + resource: 'class', + resourceId: currentClassName, + tool: 'sdk', + }); + if (!sdkClasses.has(symbolCurrentClass.meta!.resourceId!)) { + sdkClasses.set(symbolCurrentClass.meta!.resourceId!, { className: currentClassName, classes: new Set(), id: symbolCurrentClass.id, @@ -172,15 +178,20 @@ export const generateClassSdk = ({ const parentClassName = entry.path[index - 1]; if (parentClassName) { - const symbolParentClass = plugin.referenceSymbol( - plugin.api.selector('class', parentClassName), - ); + const symbolParentClass = plugin.referenceSymbol({ + category: 'utility', + resource: 'class', + resourceId: parentClassName, + tool: 'sdk', + }); if ( symbolParentClass.placeholder !== symbolCurrentClass.placeholder ) { - const parentClass = sdkClasses.get(symbolParentClass.id)!; - parentClass.classes.add(symbolCurrentClass.id); - sdkClasses.set(symbolParentClass.id, parentClass); + const parentClass = sdkClasses.get( + symbolParentClass.meta!.resourceId!, + )!; + parentClass.classes.add(symbolCurrentClass.meta!.resourceId!); + sdkClasses.set(symbolParentClass.meta!.resourceId!, parentClass); } } @@ -190,7 +201,9 @@ export const generateClassSdk = ({ return; } - const currentClass = sdkClasses.get(symbolCurrentClass.id)!; + const currentClass = sdkClasses.get( + symbolCurrentClass.meta!.resourceId!, + )!; // avoid duplicate methods if (currentClass.methods.has(entry.methodName)) { @@ -221,8 +234,10 @@ export const generateClassSdk = ({ { default: tsc.ots.string('$fetch'), extends: tsc.typeNode( - plugin.referenceSymbol(plugin.api.selector('Composable')) - .placeholder, + plugin.referenceSymbol({ + category: 'external', + resource: 'client.Composable', + }).placeholder, ), name: nuxtTypeComposable, }, @@ -264,7 +279,7 @@ export const generateClassSdk = ({ currentClass.methods.add(entry.methodName); - sdkClasses.set(symbolCurrentClass.id, currentClass); + sdkClasses.set(symbolCurrentClass.meta!.resourceId!, currentClass); }); } }, @@ -279,7 +294,7 @@ export const generateClassSdk = ({ }); const generateClass = (currentClass: SdkClassEntry) => { - if (generatedClasses.has(currentClass.id)) { + if (generatedClasses.has(currentClass.className)) { return; } @@ -327,8 +342,13 @@ export const generateClassSdk = ({ const symbol = plugin.registerSymbol({ exported: true, + meta: { + category: 'utility', + resource: 'class', + resourceId: currentClass.className, + tool: 'sdk', + }, name: currentClass.className, - selector: plugin.api.selector('class', currentClass.className), }); const node = tsc.classDeclaration({ decorator: @@ -353,7 +373,7 @@ export const generateClassSdk = ({ nodes: currentClass.nodes, }); plugin.setSymbolValue(symbol, node); - generatedClasses.add(symbol.id); + generatedClasses.add(symbol.meta!.resourceId!); }; if (clientClassNodes.length) { 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 c210a4506..836b9bb2e 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 @@ -47,8 +47,12 @@ export const generateFlatSdk = ({ }); const symbol = plugin.registerSymbol({ meta: { + category: 'sdk', path: event._path, + resource: 'operation', + resourceId: operation.id, tags: event.tags, + tool: 'sdk', }, name: serviceFunctionIdentifier({ config: plugin.context.config, @@ -56,7 +60,6 @@ export const generateFlatSdk = ({ id: operation.id, operation, }), - selector: plugin.api.selector('function', operation.id), }); const node = tsc.constVariable({ comment: createOperationComment({ operation }), @@ -70,8 +73,10 @@ export const generateFlatSdk = ({ { default: tsc.ots.string('$fetch'), extends: tsc.typeNode( - plugin.referenceSymbol(plugin.api.selector('Composable')) - .placeholder, + plugin.referenceSymbol({ + category: 'external', + resource: 'client.Composable', + }).placeholder, ), name: nuxtTypeComposable, }, diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts index c873506a0..b34932a59 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts @@ -168,7 +168,11 @@ export const operationOptionsType = ({ }); const dataType = symbolDataType?.placeholder || 'unknown'; - const symbolOptions = plugin.referenceSymbol(plugin.api.selector('Options')); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); if (isNuxtClient) { const symbolResponseType = plugin.querySymbol({ @@ -412,9 +416,10 @@ export const operationStatements = ({ if (operation.body) { switch (operation.body.type) { case 'form-data': { - const symbol = plugin.referenceSymbol( - plugin.api.selector('formDataBodySerializer'), - ); + const symbol = plugin.referenceSymbol({ + category: 'external', + resource: 'client.formDataBodySerializer', + }); requestOptions.push({ spread: symbol.placeholder }); break; } @@ -430,9 +435,10 @@ export const operationStatements = ({ }); break; case 'url-search-params': { - const symbol = plugin.referenceSymbol( - plugin.api.selector('urlSearchParamsBodySerializer'), - ); + const symbol = plugin.referenceSymbol({ + category: 'external', + resource: 'client.urlSearchParamsBodySerializer', + }); requestOptions.push({ spread: symbol.placeholder }); break; } @@ -631,9 +637,10 @@ export const operationStatements = ({ } config.push(tsc.objectExpression({ obj })); } - const symbol = plugin.referenceSymbol( - plugin.api.selector('buildClientParams'), - ); + const symbol = plugin.referenceSymbol({ + category: 'external', + resource: 'client.buildClientParams', + }); statements.push( tsc.constVariable({ expression: tsc.callExpression({ 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 d3e10b662..bd31d3c3a 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 @@ -22,8 +22,12 @@ export const createTypeOptions = ({ const symbolClient = plugin.registerSymbol({ external: clientModule, kind: 'type', + meta: { + category: 'external', + resource: 'client.Client', + tool: client.name, + }, name: 'Client', - selector: plugin.api.selector('Client'), }); const symbolClientOptions = plugin.registerSymbol({ external: clientModule, @@ -33,8 +37,12 @@ export const createTypeOptions = ({ const symbolOptions = plugin.registerSymbol({ exported: true, kind: 'type', + meta: { + category: 'type', + resource: 'client-options', + tool: 'sdk', + }, name: 'Options', - selector: plugin.api.selector('Options'), }); const typeOptions = tsc.typeAliasDeclaration({ @@ -94,9 +102,10 @@ export const createTypeOptions = ({ ? [ tsc.typeParameterDeclaration({ constraint: tsc.typeReferenceNode({ - typeName: plugin.referenceSymbol( - plugin.api.selector('Composable'), - ).placeholder, + typeName: plugin.referenceSymbol({ + category: 'external', + resource: 'client.Composable', + }).placeholder, }), defaultType: tsc.typeNode("'$fetch'"), name: 'TComposable', diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/v1/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/v1/plugin.ts index b3d2b054a..631b9c927 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/v1/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/v1/plugin.ts @@ -8,34 +8,49 @@ import type { HeyApiSdkPlugin } from '../types'; export const handlerV1: HeyApiSdkPlugin['Handler'] = ({ plugin }) => { const clientModule = clientFolderAbsolutePath(plugin.context.config); + const client = getClientPlugin(plugin.context.config); + const isAngularClient = client.name === '@hey-api/client-angular'; + const isNuxtClient = client.name === '@hey-api/client-nuxt'; + plugin.registerSymbol({ external: clientModule, + meta: { + category: 'external', + resource: 'client.formDataBodySerializer', + tool: client.name, + }, name: 'formDataBodySerializer', - selector: plugin.api.selector('formDataBodySerializer'), }); plugin.registerSymbol({ external: clientModule, + meta: { + category: 'external', + resource: 'client.urlSearchParamsBodySerializer', + tool: client.name, + }, name: 'urlSearchParamsBodySerializer', - selector: plugin.api.selector('urlSearchParamsBodySerializer'), }); plugin.registerSymbol({ external: clientModule, + meta: { + category: 'external', + resource: 'client.buildClientParams', + tool: client.name, + }, name: 'buildClientParams', - selector: plugin.api.selector('buildClientParams'), }); - - const client = getClientPlugin(plugin.context.config); - const isAngularClient = client.name === '@hey-api/client-angular'; - const isNuxtClient = client.name === '@hey-api/client-nuxt'; if (isNuxtClient) { plugin.registerSymbol({ external: clientModule, kind: 'type', + meta: { + category: 'external', + resource: 'client.Composable', + tool: client.name, + }, name: 'Composable', - selector: plugin.api.selector('Composable'), }); } - if (isAngularClient && plugin.config.asClass) { plugin.registerSymbol({ external: '@angular/core', diff --git a/packages/openapi-ts/src/plugins/@pinia/colada/plugin.ts b/packages/openapi-ts/src/plugins/@pinia/colada/plugin.ts index 173c41dd4..e6d0574c2 100644 --- a/packages/openapi-ts/src/plugins/@pinia/colada/plugin.ts +++ b/packages/openapi-ts/src/plugins/@pinia/colada/plugin.ts @@ -69,9 +69,12 @@ export const handler: PiniaColadaPlugin['Handler'] = ({ plugin }) => { // as it's really easy to break once we change the class casing entry ? [ - plugin.referenceSymbol( - sdkPlugin.api.selector('class', entry.path[0]), - ).placeholder, + plugin.referenceSymbol({ + category: 'utility', + resource: 'class', + resourceId: entry.path[0], + tool: 'sdk', + }).placeholder, ...entry.path.slice(1).map((className: string) => stringCase({ case: 'camelCase', @@ -82,9 +85,11 @@ export const handler: PiniaColadaPlugin['Handler'] = ({ plugin }) => { ] .filter(Boolean) .join('.') - : plugin.referenceSymbol( - sdkPlugin.api.selector('function', operation.id), - ).placeholder; + : plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }).placeholder; if (plugin.hooks.operation.isQuery(operation)) { if (plugin.config.queryOptions.enabled) { diff --git a/packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts b/packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts index 64514de27..522ab8db4 100644 --- a/packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts +++ b/packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts @@ -56,10 +56,11 @@ export const createQueryKeyFunction = ({ const baseUrlKey = getClientBaseUrlKey(plugin.context.config); - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - const symbolOptions = plugin.referenceSymbol( - sdkPlugin.api.selector('Options'), - ); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); const symbolClient = plugin.getSymbol({ category: 'client', }); @@ -338,10 +339,11 @@ export const createQueryKeyType = ({ }, ]; - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - const symbolOptions = plugin.referenceSymbol( - sdkPlugin.api.selector('Options'), - ); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); const symbolQueryKeyType = plugin.registerSymbol({ exported: true, kind: 'type', diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts index 5e74836d9..78c752792 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts @@ -93,9 +93,12 @@ export const handler: PluginHandler = ({ plugin }) => { // as it's really easy to break once we change the class casing entry ? [ - plugin.referenceSymbol( - sdkPlugin.api.selector('class', entry.path[0]), - ).placeholder, + plugin.referenceSymbol({ + category: 'utility', + resource: 'class', + resourceId: entry.path[0], + tool: 'sdk', + }).placeholder, ...entry.path.slice(1).map((className) => stringCase({ case: 'camelCase', @@ -106,9 +109,11 @@ export const handler: PluginHandler = ({ plugin }) => { ] .filter(Boolean) .join('.') - : plugin.referenceSymbol( - sdkPlugin.api.selector('function', operation.id), - ).placeholder; + : plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }).placeholder; if (plugin.hooks.operation.isQuery(operation)) { if (plugin.config.queryOptions.enabled) { 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 f796da682..349cf96f8 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts @@ -55,10 +55,11 @@ export const createQueryKeyFunction = ({ category: 'client', }); - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - const symbolOptions = plugin.referenceSymbol( - sdkPlugin.api.selector('Options'), - ); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); const fn = tsc.constVariable({ expression: tsc.arrowFunction({ @@ -310,10 +311,11 @@ export const createQueryKeyType = ({ plugin }: { plugin: PluginInstance }) => { }, ]; - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - const symbolOptions = plugin.referenceSymbol( - sdkPlugin.api.selector('Options'), - ); + const symbolOptions = plugin.referenceSymbol({ + category: 'type', + resource: 'client-options', + tool: 'sdk', + }); const symbolQueryKeyType = plugin.registerSymbol({ exported: true, kind: 'type',