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

chore: update example codegen

+144 -21
+14 -3
examples/openapi-ts-pinia-colada/src/client/@pinia/colada.gen.ts
··· 3 3 import { type _JSONValue, defineQueryOptions, type UseMutationOptions } from '@pinia/colada' 4 4 5 5 import { client } from '../client.gen' 6 + import { serializeQueryKeyValue } from '../core/queryKeySerializer.gen' 6 7 import { 7 8 addPet, 8 9 createUser, ··· 89 90 }) 90 91 91 92 export type QueryKey<TOptions extends Options> = [ 92 - Pick<TOptions, 'path'> & { 93 + Pick<TOptions, 'baseUrl' | 'body' | 'path' | 'query'> & { 93 94 _id: string 94 95 baseUrl?: _JSONValue 96 + body?: _JSONValue 95 97 query?: _JSONValue 96 98 tags?: _JSONValue 97 99 } ··· 109 111 if (tags) { 110 112 params.tags = tags as unknown as _JSONValue 111 113 } 114 + if (options?.body !== undefined) { 115 + const normalizedBody = serializeQueryKeyValue(options.body) 116 + if (normalizedBody !== undefined) { 117 + params.body = normalizedBody 118 + } 119 + } 112 120 if (options?.path) { 113 121 params.path = options.path 114 122 } 115 - if (options?.query) { 116 - params.query = options.query as unknown as _JSONValue 123 + if (options?.query !== undefined) { 124 + const normalizedQuery = serializeQueryKeyValue(options.query) 125 + if (normalizedQuery !== undefined) { 126 + params.query = normalizedQuery 127 + } 117 128 } 118 129 return [params] 119 130 }
+6 -11
examples/openapi-ts-pinia-colada/src/client/client.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import { 4 - type ClientOptions as DefaultClientOptions, 5 - type Config, 6 - createClient, 7 - createConfig 8 - } from './client' 9 - import type { ClientOptions } from './types.gen' 3 + import { type ClientOptions, type Config, createClient, createConfig } from './client' 4 + import type { ClientOptions as ClientOptions2 } from './types.gen' 10 5 11 6 /** 12 7 * The `createClientConfig()` function will be called on client initialization ··· 16 11 * `setConfig()`. This is useful for example if you're using Next.js 17 12 * to ensure your client always has the correct values. 18 13 */ 19 - export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = ( 20 - override?: Config<DefaultClientOptions & T> 21 - ) => Config<Required<DefaultClientOptions> & T> 14 + export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = ( 15 + override?: Config<ClientOptions & T> 16 + ) => Config<Required<ClientOptions> & T> 22 17 23 18 export const client = createClient( 24 - createConfig<ClientOptions>({ 19 + createConfig<ClientOptions2>({ 25 20 baseUrl: 'https://petstore3.swagger.io/api/v3' 26 21 }) 27 22 )
+117
examples/openapi-ts-pinia-colada/src/client/core/queryKeySerializer.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + /** 4 + * JSON-friendly union that mirrors what Pinia Colada can hash. 5 + */ 6 + export type JsonValue = 7 + | null 8 + | string 9 + | number 10 + | boolean 11 + | JsonValue[] 12 + | { [key: string]: JsonValue } 13 + 14 + /** 15 + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. 16 + */ 17 + export const queryKeyJsonReplacer = (_key: string, value: unknown) => { 18 + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { 19 + return undefined 20 + } 21 + if (typeof value === 'bigint') { 22 + return value.toString() 23 + } 24 + if (value instanceof Date) { 25 + return value.toISOString() 26 + } 27 + return value 28 + } 29 + 30 + /** 31 + * Safely stringifies a value and parses it back into a JsonValue. 32 + */ 33 + export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { 34 + try { 35 + const json = JSON.stringify(input, queryKeyJsonReplacer) 36 + if (json === undefined) { 37 + return undefined 38 + } 39 + return JSON.parse(json) as JsonValue 40 + } catch { 41 + return undefined 42 + } 43 + } 44 + 45 + /** 46 + * Detects plain objects (including objects with a null prototype). 47 + */ 48 + const isPlainObject = (value: unknown): value is Record<string, unknown> => { 49 + if (value === null || typeof value !== 'object') { 50 + return false 51 + } 52 + const prototype = Object.getPrototypeOf(value as object) 53 + return prototype === Object.prototype || prototype === null 54 + } 55 + 56 + /** 57 + * Turns URLSearchParams into a sorted JSON object for deterministic keys. 58 + */ 59 + const serializeSearchParams = (params: URLSearchParams): JsonValue => { 60 + const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b)) 61 + const result: Record<string, JsonValue> = {} 62 + 63 + for (const [key, value] of entries) { 64 + const existing = result[key] 65 + if (existing === undefined) { 66 + result[key] = value 67 + continue 68 + } 69 + 70 + if (Array.isArray(existing)) { 71 + ;(existing as string[]).push(value) 72 + } else { 73 + result[key] = [existing, value] 74 + } 75 + } 76 + 77 + return result 78 + } 79 + 80 + /** 81 + * Normalizes any accepted value into a JSON-friendly shape for query keys. 82 + */ 83 + export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined => { 84 + if (value === null) { 85 + return null 86 + } 87 + 88 + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { 89 + return value 90 + } 91 + 92 + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { 93 + return undefined 94 + } 95 + 96 + if (typeof value === 'bigint') { 97 + return value.toString() 98 + } 99 + 100 + if (value instanceof Date) { 101 + return value.toISOString() 102 + } 103 + 104 + if (Array.isArray(value)) { 105 + return stringifyToJsonValue(value) 106 + } 107 + 108 + if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) { 109 + return serializeSearchParams(value) 110 + } 111 + 112 + if (isPlainObject(value)) { 113 + return stringifyToJsonValue(value) 114 + } 115 + 116 + return undefined 117 + }
+1 -1
examples/openapi-ts-pinia-colada/src/client/index.ts
··· 2 2 3 3 export * from './@pinia/colada.gen' 4 4 export * from './sdk.gen' 5 - export * from './types.gen' 5 + export type * from './types.gen'
+2 -2
examples/openapi-ts-pinia-colada/src/client/sdk.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import type { Client, Options as ClientOptions, TDataShape } from './client' 3 + import type { Client, Options as Options2, TDataShape } from './client' 4 4 import { client } from './client.gen' 5 5 import type { 6 6 AddPetData, ··· 65 65 export type Options< 66 66 TData extends TDataShape = TDataShape, 67 67 ThrowOnError extends boolean = boolean 68 - > = ClientOptions<TData, ThrowOnError> & { 68 + > = Options2<TData, ThrowOnError> & { 69 69 /** 70 70 * You can provide a client instance returned by `createClient()` instead of 71 71 * individual options. This might be also useful if you want to implement a
+4 -4
examples/openapi-ts-pinia-colada/src/client/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 + export type ClientOptions = { 4 + baseUrl: 'https://petstore3.swagger.io/api/v3' | (string & {}) 5 + } 6 + 3 7 export type Order = { 4 8 complete?: boolean 5 9 id?: number ··· 687 691 */ 688 692 200: unknown 689 693 } 690 - 691 - export type ClientOptions = { 692 - baseUrl: 'https://petstore3.swagger.io/api/v3' | (string & {}) 693 - }