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

chore: remove deprecated APIs

Lubos 19194051 ac638b78

+356 -269
+2 -1
dev/openapi-ts.config.ts
··· 44 44 // 'full.yaml', 45 45 // 'object-property-names.yaml', 46 46 // 'openai.yaml', 47 - 'opencode.yaml', 47 + // 'opencode.yaml', 48 48 // 'pagination-ref.yaml', 49 49 // 'sdk-instance.yaml', 50 + 'sdk-nested-classes.yaml', 50 51 // 'string-with-format.yaml', 51 52 // 'transformers.json', 52 53 // 'transformers-recursive.json',
-18
packages/codegen-core/src/symbols/registry.ts
··· 11 11 private _id: SymbolId = 0; 12 12 private _indices: Map<IndexEntry[0], Map<IndexEntry[1], Set<SymbolId>>> = 13 13 new Map(); 14 - /** 15 - * @deprecated 16 - */ 17 - private _nodes: Map<SymbolId, unknown> = new Map(); 18 14 private _queryCache: Map<QueryCacheKey, ReadonlyArray<SymbolId>> = new Map(); 19 15 private _queryCacheDependencies: Map<QueryCacheKey, Set<QueryCacheKey>> = 20 16 new Map(); ··· 27 23 return typeof identifier === 'number' 28 24 ? this._values.get(identifier) 29 25 : this.query(identifier)[0]; 30 - } 31 - 32 - /** 33 - * @deprecated 34 - */ 35 - getValue(symbolId: SymbolId): unknown { 36 - return this._nodes.get(symbolId); 37 26 } 38 27 39 28 isRegistered(identifier: ISymbolIdentifier): boolean { ··· 120 109 for (const id of this._registered.values()) { 121 110 yield this._values.get(id)!; 122 111 } 123 - } 124 - 125 - /** 126 - * @deprecated 127 - */ 128 - setValue(symbolId: SymbolId, value: unknown): Map<SymbolId, unknown> { 129 - return this._nodes.set(symbolId, value); 130 112 } 131 113 132 114 private buildCacheKey(filter: ISymbolMeta): QueryCacheKey {
-15
packages/codegen-core/src/symbols/types.d.ts
··· 75 75 */ 76 76 get(identifier: ISymbolIdentifier): Symbol | undefined; 77 77 /** 78 - * Returns the value associated with a symbol ID. 79 - * 80 - * @param symbolId Symbol ID. 81 - * @return The value associated with the symbol ID, or undefined if not found. 82 - */ 83 - getValue(symbolId: number): unknown; 84 - /** 85 78 * Returns whether a symbol is registered in the registry. 86 79 * 87 80 * @param identifier Symbol identifier to check. ··· 123 116 * @returns Array of all registered symbols, in insert order. 124 117 */ 125 118 registered(): IterableIterator<Symbol>; 126 - /** 127 - * Sets a value for a symbol by its ID. 128 - * 129 - * @param symbolId Symbol ID. 130 - * @param value The value to set. 131 - * @returns void 132 - */ 133 - setValue(symbolId: number, value: unknown): Map<number, unknown>; 134 119 }
+18 -18
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/sdk.gen.ts
··· 28 28 } 29 29 } 30 30 31 + class HeyApiRegistry<T> { 32 + private readonly defaultKey = 'default'; 33 + 34 + private readonly instances: Map<string, T> = new Map(); 35 + 36 + get(key?: string): T { 37 + const instance = this.instances.get(key ?? this.defaultKey); 38 + if (!instance) { 39 + throw new Error(`No SDK client found. Create one with "new NestedSdkWithInstance()" to fix this error.`); 40 + } 41 + return instance; 42 + } 43 + 44 + set(value: T, key?: string): void { 45 + this.instances.set(key ?? this.defaultKey, value); 46 + } 47 + } 48 + 31 49 export class Domains extends HeyApiClient { 32 50 public get<ThrowOnError extends boolean = false>(options?: Options<BusinessProvidersDomainsGetData, ThrowOnError>) { 33 51 return (options?.client ?? this.client).get<BusinessProvidersDomainsGetResponses, unknown, ThrowOnError>({ url: '/business/providers/domains', ...options }); ··· 48 66 } 49 67 50 68 providers = new Providers({ client: this.client }); 51 - } 52 - 53 - class HeyApiRegistry<T> { 54 - private readonly defaultKey = 'default'; 55 - 56 - private readonly instances: Map<string, T> = new Map(); 57 - 58 - get(key?: string): T { 59 - const instance = this.instances.get(key ?? this.defaultKey); 60 - if (!instance) { 61 - throw new Error(`No SDK client found. Create one with "new NestedSdkWithInstance()" to fix this error.`); 62 - } 63 - return instance; 64 - } 65 - 66 - set(value: T, key?: string): void { 67 - this.instances.set(key ?? this.defaultKey, value); 68 - } 69 69 } 70 70 71 71 export class NestedSdkWithInstance extends HeyApiClient {
+18 -18
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/sdk.gen.ts
··· 28 28 } 29 29 } 30 30 31 + class HeyApiRegistry<T> { 32 + private readonly defaultKey = 'default'; 33 + 34 + private readonly instances: Map<string, T> = new Map(); 35 + 36 + get(key?: string): T { 37 + const instance = this.instances.get(key ?? this.defaultKey); 38 + if (!instance) { 39 + throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`); 40 + } 41 + return instance; 42 + } 43 + 44 + set(value: T, key?: string): void { 45 + this.instances.set(key ?? this.defaultKey, value); 46 + } 47 + } 48 + 31 49 export class Bar extends HeyApiClient { 32 50 public post<ThrowOnError extends boolean = false>(options?: Options<FooBarPostData, ThrowOnError>) { 33 51 return (options?.client ?? this.client).post<FooBarPostResponses, unknown, ThrowOnError>({ url: '/foo/bar', ...options }); ··· 48 66 } 49 67 50 68 bar = new Bar({ client: this.client }); 51 - } 52 - 53 - class HeyApiRegistry<T> { 54 - private readonly defaultKey = 'default'; 55 - 56 - private readonly instances: Map<string, T> = new Map(); 57 - 58 - get(key?: string): T { 59 - const instance = this.instances.get(key ?? this.defaultKey); 60 - if (!instance) { 61 - throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`); 62 - } 63 - return instance; 64 - } 65 - 66 - set(value: T, key?: string): void { 67 - this.instances.set(key ?? this.defaultKey, value); 68 - } 69 69 } 70 70 71 71 export class Sdk extends HeyApiClient {
+2
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/sdk.gen.ts
··· 4 4 5 5 import type { Client, Options as Options2, TDataShape } from './client'; 6 6 import { client } from './client.gen'; 7 + import { postFooResponseTransformer } from './transformers.gen'; 7 8 import type { PostFooData, PostFooResponses } from './types.gen'; 8 9 import { vPostFooData, vPostFooResponse } from './valibot.gen'; 9 10 ··· 23 24 24 25 export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => (options?.client ?? client).post<PostFooResponses, unknown, ThrowOnError>({ 25 26 requestValidator: async (data) => await v.parseAsync(vPostFooData, data), 27 + responseTransformer: postFooResponseTransformer, 26 28 responseValidator: async (data) => await v.parseAsync(vPostFooResponse, data), 27 29 url: '/foo', 28 30 ...options
+7
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { PostFooResponse } from './types.gen'; 4 + 3 5 const fooSchemaResponseTransformer = (data: any) => { 4 6 data.foo = BigInt(data.foo.toString()); 5 7 return data; 6 8 }; 9 + 10 + export const postFooResponseTransformer = async (data: any): Promise<PostFooResponse> => { 11 + data = fooSchemaResponseTransformer(data); 12 + return data; 13 + };
+2
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/sdk.gen.ts
··· 2 2 3 3 import type { Client, Options as Options2, TDataShape } from './client'; 4 4 import { client } from './client.gen'; 5 + import { postFooResponseTransformer } from './transformers.gen'; 5 6 import type { PostFooData, PostFooResponses } from './types.gen'; 6 7 import { zPostFooData, zPostFooResponse } from './zod.gen'; 7 8 ··· 21 22 22 23 export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => (options?.client ?? client).post<PostFooResponses, unknown, ThrowOnError>({ 23 24 requestValidator: async (data) => await zPostFooData.parseAsync(data), 25 + responseTransformer: postFooResponseTransformer, 24 26 responseValidator: async (data) => await zPostFooResponse.parseAsync(data), 25 27 url: '/foo', 26 28 ...options
+7
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { PostFooResponse } from './types.gen'; 4 + 3 5 const fooSchemaResponseTransformer = (data: any) => { 4 6 data.foo = BigInt(data.foo.toString()); 5 7 return data; 6 8 }; 9 + 10 + export const postFooResponseTransformer = async (data: any): Promise<PostFooResponse> => { 11 + data = fooSchemaResponseTransformer(data); 12 + return data; 13 + };
+18 -18
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/sdk.gen.ts
··· 28 28 } 29 29 } 30 30 31 + class HeyApiRegistry<T> { 32 + private readonly defaultKey = 'default'; 33 + 34 + private readonly instances: Map<string, T> = new Map(); 35 + 36 + get(key?: string): T { 37 + const instance = this.instances.get(key ?? this.defaultKey); 38 + if (!instance) { 39 + throw new Error(`No SDK client found. Create one with "new NestedSdkWithInstance()" to fix this error.`); 40 + } 41 + return instance; 42 + } 43 + 44 + set(value: T, key?: string): void { 45 + this.instances.set(key ?? this.defaultKey, value); 46 + } 47 + } 48 + 31 49 export class Domains extends HeyApiClient { 32 50 public get<ThrowOnError extends boolean = false>(options?: Options<BusinessProvidersDomainsGetData, ThrowOnError>) { 33 51 return (options?.client ?? this.client).get<BusinessProvidersDomainsGetResponses, unknown, ThrowOnError>({ url: '/business/providers/domains', ...options }); ··· 48 66 } 49 67 50 68 providers = new Providers({ client: this.client }); 51 - } 52 - 53 - class HeyApiRegistry<T> { 54 - private readonly defaultKey = 'default'; 55 - 56 - private readonly instances: Map<string, T> = new Map(); 57 - 58 - get(key?: string): T { 59 - const instance = this.instances.get(key ?? this.defaultKey); 60 - if (!instance) { 61 - throw new Error(`No SDK client found. Create one with "new NestedSdkWithInstance()" to fix this error.`); 62 - } 63 - return instance; 64 - } 65 - 66 - set(value: T, key?: string): void { 67 - this.instances.set(key ?? this.defaultKey, value); 68 - } 69 69 } 70 70 71 71 export class NestedSdkWithInstance extends HeyApiClient {
+18 -18
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/sdk.gen.ts
··· 28 28 } 29 29 } 30 30 31 + class HeyApiRegistry<T> { 32 + private readonly defaultKey = 'default'; 33 + 34 + private readonly instances: Map<string, T> = new Map(); 35 + 36 + get(key?: string): T { 37 + const instance = this.instances.get(key ?? this.defaultKey); 38 + if (!instance) { 39 + throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`); 40 + } 41 + return instance; 42 + } 43 + 44 + set(value: T, key?: string): void { 45 + this.instances.set(key ?? this.defaultKey, value); 46 + } 47 + } 48 + 31 49 export class Bar extends HeyApiClient { 32 50 public post<ThrowOnError extends boolean = false>(options?: Options<FooBarPostData, ThrowOnError>) { 33 51 return (options?.client ?? this.client).post<FooBarPostResponses, unknown, ThrowOnError>({ url: '/foo/bar', ...options }); ··· 48 66 } 49 67 50 68 bar = new Bar({ client: this.client }); 51 - } 52 - 53 - class HeyApiRegistry<T> { 54 - private readonly defaultKey = 'default'; 55 - 56 - private readonly instances: Map<string, T> = new Map(); 57 - 58 - get(key?: string): T { 59 - const instance = this.instances.get(key ?? this.defaultKey); 60 - if (!instance) { 61 - throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`); 62 - } 63 - return instance; 64 - } 65 - 66 - set(value: T, key?: string): void { 67 - this.instances.set(key ?? this.defaultKey, value); 68 - } 69 69 } 70 70 71 71 export class Sdk extends HeyApiClient {
+2
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/sdk.gen.ts
··· 4 4 5 5 import type { Client, Options as Options2, TDataShape } from './client'; 6 6 import { client } from './client.gen'; 7 + import { postFooResponseTransformer } from './transformers.gen'; 7 8 import type { PostFooData, PostFooResponses } from './types.gen'; 8 9 import { vPostFooData, vPostFooResponse } from './valibot.gen'; 9 10 ··· 23 24 24 25 export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => (options?.client ?? client).post<PostFooResponses, unknown, ThrowOnError>({ 25 26 requestValidator: async (data) => await v.parseAsync(vPostFooData, data), 27 + responseTransformer: postFooResponseTransformer, 26 28 responseValidator: async (data) => await v.parseAsync(vPostFooResponse, data), 27 29 url: '/foo', 28 30 ...options
+7
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { PostFooResponse } from './types.gen'; 4 + 3 5 const fooSchemaResponseTransformer = (data: any) => { 4 6 data.foo = BigInt(data.foo.toString()); 5 7 return data; 6 8 }; 9 + 10 + export const postFooResponseTransformer = async (data: any): Promise<PostFooResponse> => { 11 + data = fooSchemaResponseTransformer(data); 12 + return data; 13 + };
+2
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/sdk.gen.ts
··· 2 2 3 3 import type { Client, Options as Options2, TDataShape } from './client'; 4 4 import { client } from './client.gen'; 5 + import { postFooResponseTransformer } from './transformers.gen'; 5 6 import type { PostFooData, PostFooResponses } from './types.gen'; 6 7 import { zPostFooData, zPostFooResponse } from './zod.gen'; 7 8 ··· 21 22 22 23 export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => (options?.client ?? client).post<PostFooResponses, unknown, ThrowOnError>({ 23 24 requestValidator: async (data) => await zPostFooData.parseAsync(data), 25 + responseTransformer: postFooResponseTransformer, 24 26 responseValidator: async (data) => await zPostFooResponse.parseAsync(data), 25 27 url: '/foo', 26 28 ...options
+7
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { PostFooResponse } from './types.gen'; 4 + 3 5 const fooSchemaResponseTransformer = (data: any) => { 4 6 data.foo = BigInt(data.foo.toString()); 5 7 return data; 6 8 }; 9 + 10 + export const postFooResponseTransformer = async (data: any): Promise<PostFooResponse> => { 11 + data = fooSchemaResponseTransformer(data); 12 + return data; 13 + };
+18
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { GetFooResponse } from './types.gen'; 4 + 3 5 const quxSchemaResponseTransformer = (data: any) => { 4 6 if (data.baz) { 5 7 data.baz = new Date(data.baz); ··· 8 10 }; 9 11 10 12 const bazSchemaResponseTransformer = (data: any) => { 13 + data = quxSchemaResponseTransformer(data); 11 14 data.bar = new Date(data.bar); 12 15 return data; 13 16 }; 17 + 18 + const barSchemaResponseTransformer = (data: any) => { 19 + data.foo = data.foo.map((item: any) => bazSchemaResponseTransformer(item)); 20 + return data; 21 + }; 22 + 23 + const fooSchemaResponseTransformer = (data: any) => { 24 + data.foo = data.foo.map((item: any) => barSchemaResponseTransformer(item)); 25 + return data; 26 + }; 27 + 28 + export const getFooResponseTransformer = async (data: any): Promise<GetFooResponse> => { 29 + data = fooSchemaResponseTransformer(data); 30 + return data; 31 + };
+7
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { GetFooResponse } from './types.gen'; 4 + 3 5 const fooSchemaResponseTransformer = (data: any) => { 4 6 if (data.foo) { 5 7 data.foo = new Date(data.foo); ··· 12 14 } 13 15 return data; 14 16 }; 17 + 18 + export const getFooResponseTransformer = async (data: any): Promise<GetFooResponse> => { 19 + data = data.map((item: any) => fooSchemaResponseTransformer(item)); 20 + return data; 21 + };
+7
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { GetTreeResponse } from './types.gen'; 4 + 3 5 const treeNodeSchemaResponseTransformer = (data: any) => { 4 6 if (data.createdAt) { 5 7 data.createdAt = new Date(data.createdAt); ··· 9 11 } 10 12 return data; 11 13 }; 14 + 15 + export const getTreeResponseTransformer = async (data: any): Promise<GetTreeResponse> => { 16 + data = data.map((item: any) => treeNodeSchemaResponseTransformer(item)); 17 + return data; 18 + };
+18 -18
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/sdk.gen.ts
··· 28 28 } 29 29 } 30 30 31 + class HeyApiRegistry<T> { 32 + private readonly defaultKey = 'default'; 33 + 34 + private readonly instances: Map<string, T> = new Map(); 35 + 36 + get(key?: string): T { 37 + const instance = this.instances.get(key ?? this.defaultKey); 38 + if (!instance) { 39 + throw new Error(`No SDK client found. Create one with "new NestedSdkWithInstance()" to fix this error.`); 40 + } 41 + return instance; 42 + } 43 + 44 + set(value: T, key?: string): void { 45 + this.instances.set(key ?? this.defaultKey, value); 46 + } 47 + } 48 + 31 49 export class Domains extends HeyApiClient { 32 50 public get<ThrowOnError extends boolean = false>(options?: Options<BusinessProvidersDomainsGetData, ThrowOnError>) { 33 51 return (options?.client ?? this.client).get<BusinessProvidersDomainsGetResponses, unknown, ThrowOnError>({ url: '/business/providers/domains', ...options }); ··· 48 66 } 49 67 50 68 providers = new Providers({ client: this.client }); 51 - } 52 - 53 - class HeyApiRegistry<T> { 54 - private readonly defaultKey = 'default'; 55 - 56 - private readonly instances: Map<string, T> = new Map(); 57 - 58 - get(key?: string): T { 59 - const instance = this.instances.get(key ?? this.defaultKey); 60 - if (!instance) { 61 - throw new Error(`No SDK client found. Create one with "new NestedSdkWithInstance()" to fix this error.`); 62 - } 63 - return instance; 64 - } 65 - 66 - set(value: T, key?: string): void { 67 - this.instances.set(key ?? this.defaultKey, value); 68 - } 69 69 } 70 70 71 71 export class NestedSdkWithInstance extends HeyApiClient {
+18 -18
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/sdk.gen.ts
··· 28 28 } 29 29 } 30 30 31 + class HeyApiRegistry<T> { 32 + private readonly defaultKey = 'default'; 33 + 34 + private readonly instances: Map<string, T> = new Map(); 35 + 36 + get(key?: string): T { 37 + const instance = this.instances.get(key ?? this.defaultKey); 38 + if (!instance) { 39 + throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`); 40 + } 41 + return instance; 42 + } 43 + 44 + set(value: T, key?: string): void { 45 + this.instances.set(key ?? this.defaultKey, value); 46 + } 47 + } 48 + 31 49 export class Bar extends HeyApiClient { 32 50 public post<ThrowOnError extends boolean = false>(options?: Options<FooBarPostData, ThrowOnError>) { 33 51 return (options?.client ?? this.client).post<FooBarPostResponses, unknown, ThrowOnError>({ url: '/foo/bar', ...options }); ··· 48 66 } 49 67 50 68 bar = new Bar({ client: this.client }); 51 - } 52 - 53 - class HeyApiRegistry<T> { 54 - private readonly defaultKey = 'default'; 55 - 56 - private readonly instances: Map<string, T> = new Map(); 57 - 58 - get(key?: string): T { 59 - const instance = this.instances.get(key ?? this.defaultKey); 60 - if (!instance) { 61 - throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`); 62 - } 63 - return instance; 64 - } 65 - 66 - set(value: T, key?: string): void { 67 - this.instances.set(key ?? this.defaultKey, value); 68 - } 69 69 } 70 70 71 71 export class Sdk extends HeyApiClient {
+2
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/sdk.gen.ts
··· 4 4 5 5 import type { Client, Options as Options2, TDataShape } from './client'; 6 6 import { client } from './client.gen'; 7 + import { postFooResponseTransformer } from './transformers.gen'; 7 8 import type { PostFooData, PostFooResponses } from './types.gen'; 8 9 import { vPostFooData, vPostFooResponse } from './valibot.gen'; 9 10 ··· 23 24 24 25 export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => (options?.client ?? client).post<PostFooResponses, unknown, ThrowOnError>({ 25 26 requestValidator: async (data) => await v.parseAsync(vPostFooData, data), 27 + responseTransformer: postFooResponseTransformer, 26 28 responseValidator: async (data) => await v.parseAsync(vPostFooResponse, data), 27 29 url: '/foo', 28 30 ...options
+7
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { PostFooResponse } from './types.gen'; 4 + 3 5 const fooSchemaResponseTransformer = (data: any) => { 4 6 data.foo = BigInt(data.foo.toString()); 5 7 return data; 6 8 }; 9 + 10 + export const postFooResponseTransformer = async (data: any): Promise<PostFooResponse> => { 11 + data = fooSchemaResponseTransformer(data); 12 + return data; 13 + };
+2
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/sdk.gen.ts
··· 2 2 3 3 import type { Client, Options as Options2, TDataShape } from './client'; 4 4 import { client } from './client.gen'; 5 + import { postFooResponseTransformer } from './transformers.gen'; 5 6 import type { PostFooData, PostFooResponses } from './types.gen'; 6 7 import { zPostFooData, zPostFooResponse } from './zod.gen'; 7 8 ··· 21 22 22 23 export const postFoo = <ThrowOnError extends boolean = false>(options?: Options<PostFooData, ThrowOnError>) => (options?.client ?? client).post<PostFooResponses, unknown, ThrowOnError>({ 23 24 requestValidator: async (data) => await zPostFooData.parseAsync(data), 25 + responseTransformer: postFooResponseTransformer, 24 26 responseValidator: async (data) => await zPostFooResponse.parseAsync(data), 25 27 url: '/foo', 26 28 ...options
+7
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { PostFooResponse } from './types.gen'; 4 + 3 5 const fooSchemaResponseTransformer = (data: any) => { 4 6 data.foo = BigInt(data.foo.toString()); 5 7 return data; 6 8 }; 9 + 10 + export const postFooResponseTransformer = async (data: any): Promise<PostFooResponse> => { 11 + data = fooSchemaResponseTransformer(data); 12 + return data; 13 + };
+18
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { GetFooResponse } from './types.gen'; 4 + 3 5 const quxSchemaResponseTransformer = (data: any) => { 4 6 if (data.baz) { 5 7 data.baz = new Date(data.baz); ··· 8 10 }; 9 11 10 12 const bazSchemaResponseTransformer = (data: any) => { 13 + data = quxSchemaResponseTransformer(data); 11 14 data.bar = new Date(data.bar); 12 15 return data; 13 16 }; 17 + 18 + const barSchemaResponseTransformer = (data: any) => { 19 + data.foo = data.foo.map((item: any) => bazSchemaResponseTransformer(item)); 20 + return data; 21 + }; 22 + 23 + const fooSchemaResponseTransformer = (data: any) => { 24 + data.foo = data.foo.map((item: any) => barSchemaResponseTransformer(item)); 25 + return data; 26 + }; 27 + 28 + export const getFooResponseTransformer = async (data: any): Promise<GetFooResponse> => { 29 + data = fooSchemaResponseTransformer(data); 30 + return data; 31 + };
+12
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { GetFooResponse, NestedDateObjectResponse } from './types.gen'; 4 + 3 5 const fooSchemaResponseTransformer = (data: any) => { 4 6 if (data.foo) { 5 7 data.foo = new Date(data.foo); ··· 16 18 return data; 17 19 }; 18 20 21 + export const getFooResponseTransformer = async (data: any): Promise<GetFooResponse> => { 22 + data = data.map((item: any) => fooSchemaResponseTransformer(item)); 23 + return data; 24 + }; 25 + 19 26 const nestedDateObjectSchemaResponseTransformer = (data: any) => { 20 27 if (data.foo) { 21 28 if (data.foo.bar) { ··· 24 31 } 25 32 return data; 26 33 }; 34 + 35 + export const nestedDateObjectResponseTransformer = async (data: any): Promise<NestedDateObjectResponse> => { 36 + data = nestedDateObjectSchemaResponseTransformer(data); 37 + return data; 38 + };
+7
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/transformers.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + import type { GetTreeResponse } from './types.gen'; 4 + 3 5 const treeNodeSchemaResponseTransformer = (data: any) => { 4 6 if (data.createdAt) { 5 7 data.createdAt = new Date(data.createdAt); ··· 9 11 } 10 12 return data; 11 13 }; 14 + 15 + export const getTreeResponseTransformer = async (data: any): Promise<GetTreeResponse> => { 16 + data = data.map((item: any) => treeNodeSchemaResponseTransformer(item)); 17 + return data; 18 + };
+18 -18
packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/instance/sdk.gen.ts
··· 28 28 } 29 29 } 30 30 31 + class HeyApiRegistry<T> { 32 + private readonly defaultKey = 'default'; 33 + 34 + private readonly instances: Map<string, T> = new Map(); 35 + 36 + get(key?: string): T { 37 + const instance = this.instances.get(key ?? this.defaultKey); 38 + if (!instance) { 39 + throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`); 40 + } 41 + return instance; 42 + } 43 + 44 + set(value: T, key?: string): void { 45 + this.instances.set(key ?? this.defaultKey, value); 46 + } 47 + } 48 + 31 49 export class AccountingCompanies extends HeyApiClient { 32 50 public count<ThrowOnError extends boolean = false>(options?: Options<ApiVVersionApiVersionOdataAccountingCompaniesCountData, ThrowOnError>) { 33 51 return (options?.client ?? this.client).get<ApiVVersionApiVersionOdataAccountingCompaniesCountResponses, unknown, ThrowOnError>({ url: '/api/v1/odata/AccountingCompanies/$count', ...options }); ··· 298 316 299 317 export class MapIdentityApi extends HeyApiClient { 300 318 api = new Api({ client: this.client }); 301 - } 302 - 303 - class HeyApiRegistry<T> { 304 - private readonly defaultKey = 'default'; 305 - 306 - private readonly instances: Map<string, T> = new Map(); 307 - 308 - get(key?: string): T { 309 - const instance = this.instances.get(key ?? this.defaultKey); 310 - if (!instance) { 311 - throw new Error(`No SDK client found. Create one with "new Sdk()" to fix this error.`); 312 - } 313 - return instance; 314 - } 315 - 316 - set(value: T, key?: string): void { 317 - this.instances.set(key ?? this.defaultKey, value); 318 - } 319 319 } 320 320 321 321 export class Sdk extends HeyApiClient {
+34 -28
packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts
··· 305 305 }, 306 306 ); 307 307 308 - const symbolHeyApiClient = plugin.config.instance 309 - ? plugin.registerSymbol({ 310 - meta: { 311 - category: 'utility', 312 - resource: 'class', 313 - resourceId: 'HeyApiClient', 314 - tool: 'sdk', 315 - }, 316 - name: 'HeyApiClient', 317 - }) 308 + const heyApiClientIndex = plugin.config.instance 309 + ? plugin.addNode(null) 318 310 : undefined; 319 - const symbolHeyApiRegistry = plugin.config.instance 320 - ? plugin.registerSymbol({ 321 - meta: { 322 - category: 'utility', 323 - resource: 'class', 324 - resourceId: 'HeyApiRegistry', 325 - tool: 'sdk', 326 - }, 327 - name: 'HeyApiRegistry', 328 - }) 311 + const symbolHeyApiClient = 312 + heyApiClientIndex !== undefined 313 + ? plugin.symbol('HeyApiClient', { 314 + meta: { 315 + category: 'utility', 316 + resource: 'class', 317 + resourceId: 'HeyApiClient', 318 + tool: 'sdk', 319 + }, 320 + }) 321 + : undefined; 322 + const heyApiRegistryIndex = plugin.config.instance 323 + ? plugin.addNode(null) 329 324 : undefined; 330 325 331 326 const generateClass = (currentClass: SdkClassEntry) => { ··· 400 395 } 401 396 } 402 397 403 - if (symbolHeyApiClient && !symbolHeyApiClient.node) { 398 + if ( 399 + heyApiClientIndex !== undefined && 400 + symbolHeyApiClient && 401 + !symbolHeyApiClient.node 402 + ) { 404 403 const node = createClientClass({ 405 404 plugin, 406 405 symbol: symbolHeyApiClient, 407 406 }); 408 - plugin.addNode(node); 407 + plugin.updateNode(heyApiClientIndex, node); 409 408 } 410 409 411 - const symbol = plugin.registerSymbol({ 410 + const symbol = plugin.symbol(resourceId, { 412 411 meta: { 413 412 category: 'utility', 414 413 resource: 'class', 415 414 resourceId, 416 415 tool: 'sdk', 417 416 }, 418 - name: resourceId, 419 417 }); 420 418 421 - if (currentClass.root && symbolHeyApiRegistry) { 419 + if (currentClass.root && heyApiRegistryIndex !== undefined) { 422 420 const symClient = plugin.getSymbol({ 423 421 category: 'client', 424 422 }); ··· 454 452 currentClass.nodes.unshift(ctor, $.newline()); 455 453 } 456 454 455 + const symbolRegistry = plugin.symbol('HeyApiRegistry', { 456 + meta: { 457 + category: 'utility', 458 + resource: 'class', 459 + resourceId: 'HeyApiRegistry', 460 + tool: 'sdk', 461 + }, 462 + }); 457 463 const node = createRegistryClass({ 458 464 plugin, 459 465 sdkSymbol: symbol, 460 - symbol: symbolHeyApiRegistry, 466 + symbol: symbolRegistry, 461 467 }); 462 - plugin.addNode(node); 468 + plugin.updateNode(heyApiRegistryIndex, node); 463 469 const registryNode = $.field(registryName, (f) => 464 470 f 465 471 .public() 466 472 .static() 467 473 .readonly() 468 - .assign($.new(symbolHeyApiRegistry).generic(symbol)), 474 + .assign($.new(symbolRegistry).generic(symbol)), 469 475 ); 470 476 currentClass.nodes.unshift(registryNode, $.newline()); 471 477 }
+10 -18
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts
··· 59 59 resource: 'definition', 60 60 resourceId: schema.$ref, 61 61 }; 62 - 63 - let symbol = plugin.getSymbol(query); 64 - 65 - if (!symbol) { 66 - // Register a placeholder symbol immediately and set its value to null 67 - // as a stop token to prevent infinite recursion for self-referential 68 - // schemas. We also mark this symbol as "building" so that nested 69 - // references to it can emit calls that will be implemented later. 70 - symbol = plugin.registerSymbol({ 71 - meta: query, 72 - name: buildName({ 62 + const symbol = 63 + plugin.getSymbol(query) ?? 64 + plugin.symbol( 65 + buildName({ 73 66 config: { 74 67 case: 'camelCase', 75 68 name: '{{name}}SchemaResponseTransformer', 76 69 }, 77 70 name: refToName(schema.$ref), 78 71 }), 79 - }); 80 - plugin.setSymbolValue(symbol, null); 81 - } 72 + { 73 + meta: query, 74 + }, 75 + ); 82 76 83 77 // Only compute the implementation if the symbol isn't already being built. 84 78 // This prevents infinite recursion on self-referential schemas. We still 85 79 // allow emitting a call when the symbol is currently being built so 86 80 // parent nodes can reference the transformer that will be emitted later. 87 - const existingValue = plugin.gen.symbols.getValue(symbol.id); 88 - if (!existingValue && !buildingSymbols.has(symbol.id)) { 81 + if (!symbol.node && !buildingSymbols.has(symbol.id)) { 89 82 buildingSymbols.add(symbol.id); 90 83 try { 91 84 const refSchema = plugin.context.resolveIrRef<IR.SchemaObject>( ··· 113 106 // Only emit a call if the symbol has a value (implementation) OR the 114 107 // symbol is currently being built (recursive reference) — in the 115 108 // latter case we allow emitting a call that will be implemented later. 116 - const currentValue = plugin.gen.symbols.getValue(symbol.id); 117 - if (currentValue || buildingSymbols.has(symbol.id)) { 109 + if (symbol.node || buildingSymbols.has(symbol.id)) { 118 110 const ref = plugin.referenceSymbol(query); 119 111 const callExpression = $(ref).call(dataExpression); 120 112
+3 -13
packages/openapi-ts/src/plugins/shared/utils/instance.ts
··· 317 317 return this.gen.symbols.reference(meta); 318 318 } 319 319 320 + /** 321 + * @deprecated use `plugin.symbol()` instead 322 + */ 320 323 registerSymbol(symbol: SymbolIn): Symbol { 321 324 return this.symbol(symbol.name, symbol); 322 325 } ··· 359 362 hook({ plugin: this, symbol: symbolOut }); 360 363 } 361 364 return symbolOut; 362 - } 363 - 364 - /** 365 - * @deprecated use addNode 366 - */ 367 - setSymbolValue(symbol: Symbol, value: unknown): void { 368 - for (const hook of this.eventHooks['symbol:setValue:before']) { 369 - hook({ plugin: this, symbol, value }); 370 - } 371 - this.gen.symbols.setValue(symbol.id, value); 372 - for (const hook of this.eventHooks['symbol:setValue:after']) { 373 - hook({ plugin: this, symbol, value }); 374 - } 375 365 } 376 366 377 367 private buildEventHooks(): EventHooks {
+58 -50
packages/openapi-ts/src/plugins/zod/shared/operation.ts
··· 118 118 schemaData.required = [...requiredProperties]; 119 119 120 120 const ast = getAst(schemaData, fromRef(state.path)); 121 - const symbol = plugin.registerSymbol({ 122 - meta: { 123 - category: 'schema', 124 - path: fromRef(state.path), 125 - resource: 'operation', 126 - resourceId: operation.id, 127 - role: 'data', 128 - tags: fromRef(state.tags), 129 - tool: 'zod', 130 - }, 131 - name: buildName({ 121 + const symbol = plugin.symbol( 122 + buildName({ 132 123 config: plugin.config.requests, 133 124 name: operation.id, 134 125 }), 135 - }); 126 + { 127 + meta: { 128 + category: 'schema', 129 + path: fromRef(state.path), 130 + resource: 'operation', 131 + resourceId: operation.id, 132 + role: 'data', 133 + tags: fromRef(state.tags), 134 + tool: 'zod', 135 + }, 136 + }, 137 + ); 136 138 const typeInferSymbol = plugin.config.requests.types.infer.enabled 137 - ? plugin.registerSymbol({ 138 - meta: { 139 - category: 'type', 140 - path: fromRef(state.path), 141 - resource: 'operation', 142 - resourceId: operation.id, 143 - role: 'data', 144 - tags: fromRef(state.tags), 145 - tool: 'zod', 146 - variant: 'infer', 147 - }, 148 - name: buildName({ 139 + ? plugin.symbol( 140 + buildName({ 149 141 config: plugin.config.requests.types.infer, 150 142 name: operation.id, 151 143 }), 152 - }) 144 + { 145 + meta: { 146 + category: 'type', 147 + path: fromRef(state.path), 148 + resource: 'operation', 149 + resourceId: operation.id, 150 + role: 'data', 151 + tags: fromRef(state.tags), 152 + tool: 'zod', 153 + variant: 'infer', 154 + }, 155 + }, 156 + ) 153 157 : undefined; 154 158 exportAst({ 155 159 ast, ··· 167 171 if (response) { 168 172 const path = [...fromRef(state.path), 'responses']; 169 173 const ast = getAst(response, path); 170 - const symbol = plugin.registerSymbol({ 171 - meta: { 172 - category: 'schema', 173 - path, 174 - resource: 'operation', 175 - resourceId: operation.id, 176 - role: 'responses', 177 - tags: fromRef(state.tags), 178 - tool: 'zod', 179 - }, 180 - name: buildName({ 174 + const symbol = plugin.symbol( 175 + buildName({ 181 176 config: plugin.config.responses, 182 177 name: operation.id, 183 178 }), 184 - }); 179 + { 180 + meta: { 181 + category: 'schema', 182 + path, 183 + resource: 'operation', 184 + resourceId: operation.id, 185 + role: 'responses', 186 + tags: fromRef(state.tags), 187 + tool: 'zod', 188 + }, 189 + }, 190 + ); 185 191 const typeInferSymbol = plugin.config.responses.types.infer.enabled 186 - ? plugin.registerSymbol({ 187 - meta: { 188 - category: 'type', 189 - path, 190 - resource: 'operation', 191 - resourceId: operation.id, 192 - role: 'responses', 193 - tags: fromRef(state.tags), 194 - tool: 'zod', 195 - variant: 'infer', 196 - }, 197 - name: buildName({ 192 + ? plugin.symbol( 193 + buildName({ 198 194 config: plugin.config.responses.types.infer, 199 195 name: operation.id, 200 196 }), 201 - }) 197 + { 198 + meta: { 199 + category: 'type', 200 + path, 201 + resource: 'operation', 202 + resourceId: operation.id, 203 + role: 'responses', 204 + tags: fromRef(state.tags), 205 + tool: 'zod', 206 + variant: 'infer', 207 + }, 208 + }, 209 + ) 202 210 : undefined; 203 211 exportAst({ 204 212 ast,