diff --git a/.changeset/fuzzy-taxes-cheer.md b/.changeset/fuzzy-taxes-cheer.md new file mode 100644 index 000000000..91d83d78e --- /dev/null +++ b/.changeset/fuzzy-taxes-cheer.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +**plugin(zod)**: expand support for bigint types diff --git a/dev/openapi-ts.config.ts b/dev/openapi-ts.config.ts index 89537db16..2fa9cb243 100644 --- a/dev/openapi-ts.config.ts +++ b/dev/openapi-ts.config.ts @@ -38,13 +38,13 @@ export default defineConfig(() => { // }, path: path.resolve( getSpecsPath(), - '3.0.x', - // '3.1.x', + // '3.0.x', + '3.1.x', // 'circular.yaml', // 'dutchie.json', // 'enum-names-values.yaml', // 'full.yaml', - // 'integer-formats.yaml', + 'integer-formats.yaml', // 'invalid', // 'object-property-names.yaml', // 'openai.yaml', @@ -52,7 +52,7 @@ export default defineConfig(() => { // 'pagination-ref.yaml', // 'schema-const.yaml', // 'sdk-instance.yaml', - 'sdk-method-class-conflict.yaml', + // 'sdk-method-class-conflict.yaml', // 'sdk-nested-classes.yaml', // 'sdk-nested-conflict.yaml', // 'string-with-format.yaml', @@ -397,7 +397,7 @@ export default defineConfig(() => { definitions: 'z{{name}}', exportFromIndex: true, // metadata: true, - // name: 'valibot', + name: 'valibot', // requests: { // case: 'PascalCase', // name: '{{name}}Data', @@ -467,7 +467,7 @@ export default defineConfig(() => { { // case: 'snake_case', // comments: false, - compatibilityVersion: 4, + compatibilityVersion: 3, dates: { // local: true, // offset: true, diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts new file mode 100644 index 000000000..a168141eb --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts @@ -0,0 +1,80 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, queryOptions } from '@tanstack/angular-query-experimental'; + +import { client } from '../client.gen'; +import { getBar, getFoo, type Options } from '../sdk.gen'; +import type { GetBarData, GetFooData } from '../types.gen'; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); + +export const getFooOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getFoo({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getFooQueryKey(options), + meta: { + id: 'getFoo', + method: 'get', + path: '/foo' + } +}); + +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); + +export const getBarOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getBar({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getBarQueryKey(options), + meta: { + id: 'getBar', + method: 'get', + path: '/bar' + } +}); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts new file mode 100644 index 000000000..5a6a25034 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts @@ -0,0 +1,80 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, queryOptions } from '@tanstack/react-query'; + +import { client } from '../client.gen'; +import { getBar, getFoo, type Options } from '../sdk.gen'; +import type { GetBarData, GetFooData } from '../types.gen'; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); + +export const getFooOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getFoo({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getFooQueryKey(options), + meta: { + id: 'getFoo', + method: 'get', + path: '/foo' + } +}); + +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); + +export const getBarOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getBar({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getBarQueryKey(options), + meta: { + id: 'getBar', + method: 'get', + path: '/bar' + } +}); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts new file mode 100644 index 000000000..8b6d32356 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts @@ -0,0 +1,80 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, queryOptions } from '@tanstack/solid-query'; + +import { client } from '../client.gen'; +import { getBar, getFoo, type Options } from '../sdk.gen'; +import type { GetBarData, GetFooData } from '../types.gen'; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); + +export const getFooOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getFoo({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getFooQueryKey(options), + meta: { + id: 'getFoo', + method: 'get', + path: '/foo' + } +}); + +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); + +export const getBarOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getBar({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getBarQueryKey(options), + meta: { + id: 'getBar', + method: 'get', + path: '/bar' + } +}); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts new file mode 100644 index 000000000..4c50bd620 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts @@ -0,0 +1,80 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, queryOptions } from '@tanstack/svelte-query'; + +import { client } from '../client.gen'; +import { getBar, getFoo, type Options } from '../sdk.gen'; +import type { GetBarData, GetFooData } from '../types.gen'; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); + +export const getFooOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getFoo({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getFooQueryKey(options), + meta: { + id: 'getFoo', + method: 'get', + path: '/foo' + } +}); + +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); + +export const getBarOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getBar({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getBarQueryKey(options), + meta: { + id: 'getBar', + method: 'get', + path: '/bar' + } +}); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts new file mode 100644 index 000000000..4793f41da --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts @@ -0,0 +1,80 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, queryOptions } from '@tanstack/vue-query'; + +import { client } from '../client.gen'; +import { getBar, getFoo, type Options } from '../sdk.gen'; +import type { GetBarData, GetFooData } from '../types.gen'; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); + +export const getFooOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getFoo({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getFooQueryKey(options), + meta: { + id: 'getFoo', + method: 'get', + path: '/foo' + } +}); + +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); + +export const getBarOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getBar({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getBarQueryKey(options), + meta: { + id: 'getBar', + method: 'get', + path: '/bar' + } +}); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client.gen.ts new file mode 100644 index 000000000..cab3c7019 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig()); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts new file mode 100644 index 000000000..c2a5190c2 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts @@ -0,0 +1,301 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { + Client, + Config, + RequestOptions, + ResolvedRequestOptions, +} from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors< + Request, + Response, + unknown, + ResolvedRequestOptions + >(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body); + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response: Response; + + try { + response = await _fetch(request); + } catch (error) { + // Handle fetch exceptions (AbortError, network errors, etc.) + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn( + error, + undefined as any, + request, + opts, + )) as unknown; + } + } + + finalError = finalError || ({} as unknown); + + if (opts.throwOnError) { + throw finalError; + } + + // Return error response + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + request, + response: undefined as any, + }; + } + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if ( + response.status === 204 || + response.headers.get('Content-Length') === '0' + ) { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'json': + case 'text': + data = await response[parseAs](); + break; + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = + (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = + (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/index.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/index.ts new file mode 100644 index 000000000..b295edeca --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/index.ts @@ -0,0 +1,25 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Auth } from '../core/auth.gen'; +export type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +export { + formDataBodySerializer, + jsonBodySerializer, + urlSearchParamsBodySerializer, +} from '../core/bodySerializer.gen'; +export { buildClientParams } from '../core/params.gen'; +export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'; +export { createClient } from './client.gen'; +export type { + Client, + ClientOptions, + Config, + CreateClientConfig, + Options, + RequestOptions, + RequestResult, + ResolvedRequestOptions, + ResponseStyle, + TDataShape, +} from './types.gen'; +export { createConfig, mergeHeaders } from './utils.gen'; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/types.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/types.gen.ts new file mode 100644 index 000000000..b4a499cc0 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/types.gen.ts @@ -0,0 +1,241 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { + Client as CoreClient, + Config as CoreConfig, +} from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: + | 'arrayBuffer' + | 'auto' + | 'blob' + | 'formData' + | 'json' + | 'stream' + | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record + ? TData[keyof TData] + : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? + | (TData extends Record + ? TData[keyof TData] + : TData) + | undefined + : ( + | { + data: TData extends Record + ? TData[keyof TData] + : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick< + Required>, + 'method' + >, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/utils.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/utils.gen.ts new file mode 100644 index 000000000..4c48a9ee1 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/utils.gen.ts @@ -0,0 +1,332 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = ( + contentType: string | null, +): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if ( + cleanContent.startsWith('application/json') || + cleanContent.endsWith('+json') + ) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => + cleanContent.startsWith(type), + ) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = + header instanceof Headers + ? headersEntries(header) + : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e. their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = ( + request: Req, + options: Options, +) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update( + id: number | Interceptor, + fn: Interceptor, + ): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/auth.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/auth.gen.ts new file mode 100644 index 000000000..f8a73266f --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/bodySerializer.gen.ts new file mode 100644 index 000000000..552b50f7c --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/params.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/params.gen.ts new file mode 100644 index 000000000..602715c46 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/pathSerializer.gen.ts new file mode 100644 index 000000000..8d9993104 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/queryKeySerializer.gen.ts new file mode 100644 index 000000000..d3bb68396 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/serverSentEvents.gen.ts new file mode 100644 index 000000000..343d25af8 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/serverSentEvents.gen.ts @@ -0,0 +1,266 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + // Normalize line endings: CRLF -> LF, then CR -> LF + buffer = buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); + + const chunks = buffer.split('\n\n'); + buffer = chunks.pop() ?? ''; + + for (const chunk of chunks) { + const lines = chunk.split('\n'); + const dataLines: Array = []; + let eventName: string | undefined; + + for (const line of lines) { + if (line.startsWith('data:')) { + dataLines.push(line.replace(/^data:\s*/, '')); + } else if (line.startsWith('event:')) { + eventName = line.replace(/^event:\s*/, ''); + } else if (line.startsWith('id:')) { + lastEventId = line.replace(/^id:\s*/, ''); + } else if (line.startsWith('retry:')) { + const parsed = Number.parseInt( + line.replace(/^retry:\s*/, ''), + 10, + ); + if (!Number.isNaN(parsed)) { + retryDelay = parsed; + } + } + } + + let data: unknown; + let parsedJson = false; + + if (dataLines.length) { + const rawData = dataLines.join('\n'); + try { + data = JSON.parse(rawData); + parsedJson = true; + } catch { + data = rawData; + } + } + + if (parsedJson) { + if (responseValidator) { + await responseValidator(data); + } + + if (responseTransformer) { + data = await responseTransformer(data); + } + } + + onSseEvent?.({ + data, + event: eventName, + id: lastEventId, + retry: retryDelay, + }); + + if (dataLines.length) { + yield data as any; + } + } + } + } finally { + signal.removeEventListener('abort', abortHandler); + reader.releaseLock(); + } + + break; // exit loop on normal completion + } catch (error) { + // connection failed or aborted; retry after delay + onSseError?.(error); + + if ( + sseMaxRetryAttempts !== undefined && + attempt >= sseMaxRetryAttempts + ) { + break; // stop after firing error + } + + // exponential backoff: double retry each attempt, cap at 30s + const backoff = Math.min( + retryDelay * 2 ** (attempt - 1), + sseMaxRetryDelay ?? 30000, + ); + await sleep(backoff); + } + } + }; + + const stream = createStream(); + + return { stream }; +}; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/types.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/types.gen.ts new file mode 100644 index 000000000..643c070c9 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/utils.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/utils.gen.ts new file mode 100644 index 000000000..0b5389d08 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/index.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/index.ts new file mode 100644 index 000000000..afbfb3822 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export { getBar, getFoo, type Options } from './sdk.gen'; +export type { ClientOptions, GetBarData, GetBarResponses, GetFooData, GetFooResponses } from './types.gen'; diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/sdk.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/sdk.gen.ts new file mode 100644 index 000000000..e2081efc5 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/sdk.gen.ts @@ -0,0 +1,39 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Client, Options as Options2, TDataShape } from './client'; +import { client } from './client.gen'; +import type { GetBarData, GetBarResponses, GetFooData, GetFooResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export const getFoo = (options?: Options) => (options?.client ?? client).get({ + security: [{ + in: 'query', + name: 'foo', + type: 'apiKey' + }], + url: '/foo', + ...options +}); + +export const getBar = (options?: Options) => (options?.client ?? client).get({ + security: [{ + in: 'cookie', + name: 'bar', + type: 'apiKey' + }], + url: '/bar', + ...options +}); diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/types.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/types.gen.ts new file mode 100644 index 000000000..41519aa51 --- /dev/null +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/types.gen.ts @@ -0,0 +1,33 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type GetFooData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type GetFooResponses = { + /** + * OK + */ + 200: unknown; +}; + +export type GetBarData = { + body?: never; + path?: never; + query?: never; + url: '/bar'; +}; + +export type GetBarResponses = { + /** + * OK + */ + 200: unknown; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts index c439f1fb2..c369f0aa5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts @@ -8,7 +8,7 @@ export const vFoo = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), BigInt(0)), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), BigInt(0)), id: v.string() }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts index 477553d5c..e0b29908f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts index 49b25b351..167326e71 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts @@ -689,7 +689,7 @@ export const vCollectionFormatData = v.object({ export const vTypesData = v.object({ body: v.optional(v.never()), path: v.optional(v.object({ - id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'))) + id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'))) })), query: v.object({ parameterNumber: v.optional(v.number(), 123), diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts index c439f1fb2..c369f0aa5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts @@ -8,7 +8,7 @@ export const vFoo = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), BigInt(0)), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), BigInt(0)), id: v.string() }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts index 477553d5c..e0b29908f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts index 7d0f29978..ba6d999dd 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts @@ -630,8 +630,8 @@ export const vDefault = v.object({ }); export const vPageable = v.object({ - page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'), v.minValue(0)), 0), - size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'), v.minValue(1))), + page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'), v.minValue(0)), 0), + size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'), v.minValue(1))), sort: v.optional(v.array(v.string())) }); @@ -962,13 +962,13 @@ export const vCompositionWithOneOfAndProperties = v.intersect([v.union([v.strict }), v.strictObject({ bar: vNonAsciiStringæøåÆøÅöôêÊ字符串 })]), v.object({ - baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'), v.minValue(0)), v.null()]), - qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'), v.minValue(0)) + baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'), v.minValue(0)), v.null()]), + qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'), v.minValue(0)) })]); export const vModelWithOneOfAndProperties = v.intersect([v.union([vSimpleParameter, vNonAsciiStringæøåÆøÅöôêÊ字符串]), v.object({ - baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'), v.minValue(0)), v.null()]), - qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'), v.minValue(0)) + baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'), v.minValue(0)), v.null()]), + qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'), v.minValue(0)) })]); /** @@ -1331,7 +1331,7 @@ export const vCollectionFormatData = v.object({ export const vTypesData = v.object({ body: v.optional(v.never()), path: v.optional(v.object({ - id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'))) + id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'))) })), query: v.object({ parameterNumber: v.optional(v.number(), 123), @@ -1444,12 +1444,12 @@ export const vComplexParamsData = v.object({ vModelWithDictionary ]), user: v.optional(v.pipe(v.object({ - id: v.optional(v.pipe(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')), v.readonly())), + id: v.optional(v.pipe(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647')), v.readonly())), name: v.optional(v.pipe(v.union([v.pipe(v.string(), v.readonly()), v.null()]), v.readonly())) }), v.readonly())) })), path: v.object({ - id: v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')), + id: v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647')), 'api-version': v.string() }), query: v.optional(v.never()) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/integer-formats/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/integer-formats/valibot.gen.ts index 00e476013..5cb356977 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/integer-formats/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/integer-formats/valibot.gen.ts @@ -4,47 +4,47 @@ import * as v from 'valibot'; export const vIntegerFormats = v.object({ numberNoFormat: v.optional(v.number()), - numberInt8: v.optional(v.pipe(v.number(), v.minValue(-128, 'Invalid value: Expected int8 to be >= -2^7'), v.maxValue(127, 'Invalid value: Expected int8 to be <= 2^7-1'))), - numberInt16: v.optional(v.pipe(v.number(), v.minValue(-32768, 'Invalid value: Expected int16 to be >= -2^15'), v.maxValue(32767, 'Invalid value: Expected int16 to be <= 2^15-1'))), - numberInt32: v.optional(v.pipe(v.number(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'))), + numberInt8: v.optional(v.pipe(v.number(), v.minValue(-128, 'Invalid value: Expected int8 to be >= -128'), v.maxValue(127, 'Invalid value: Expected int8 to be <= 127'))), + numberInt16: v.optional(v.pipe(v.number(), v.minValue(-32768, 'Invalid value: Expected int16 to be >= -32768'), v.maxValue(32767, 'Invalid value: Expected int16 to be <= 32767'))), + numberInt32: v.optional(v.pipe(v.number(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'))), numberInt64: v.optional(v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), - numberUint8: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'))), - numberUint16: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'))), - numberUint32: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint32 to be >= 0'), v.maxValue(4294967295, 'Invalid value: Expected uint32 to be <= 2^32-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), + numberUint8: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'))), + numberUint16: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'))), + numberUint32: v.optional(v.pipe(v.number(), v.minValue(0, 'Invalid value: Expected uint32 to be >= 0'), v.maxValue(4294967295, 'Invalid value: Expected uint32 to be <= 4294967295'))), numberUint64: v.optional(v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 2^64-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 18446744073709551615'))), integerNoFormat: v.optional(v.pipe(v.number(), v.integer())), - integerInt8: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-128, 'Invalid value: Expected int8 to be >= -2^7'), v.maxValue(127, 'Invalid value: Expected int8 to be <= 2^7-1'))), - integerInt16: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-32768, 'Invalid value: Expected int16 to be >= -2^15'), v.maxValue(32767, 'Invalid value: Expected int16 to be <= 2^15-1'))), - integerInt32: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'))), + integerInt8: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-128, 'Invalid value: Expected int8 to be >= -128'), v.maxValue(127, 'Invalid value: Expected int8 to be <= 127'))), + integerInt16: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-32768, 'Invalid value: Expected int16 to be >= -32768'), v.maxValue(32767, 'Invalid value: Expected int16 to be <= 32767'))), + integerInt32: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'))), integerInt64: v.optional(v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), - integerUint8: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'))), - integerUint16: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'))), - integerUint32: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint32 to be >= 0'), v.maxValue(4294967295, 'Invalid value: Expected uint32 to be <= 2^32-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), + integerUint8: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'))), + integerUint16: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'))), + integerUint32: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint32 to be >= 0'), v.maxValue(4294967295, 'Invalid value: Expected uint32 to be <= 4294967295'))), integerUint64: v.optional(v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 2^64-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 18446744073709551615'))), stringInt64: v.optional(v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), stringUint64: v.optional(v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 2^64-1'))) + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('0'), 'Invalid value: Expected uint64 to be >= 0'), v.maxValue(BigInt('18446744073709551615'), 'Invalid value: Expected uint64 to be <= 18446744073709551615'))) }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts index c439f1fb2..c369f0aa5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts @@ -8,7 +8,7 @@ export const vFoo = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), BigInt(0)), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), BigInt(0)), id: v.string() }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts index 477553d5c..e0b29908f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts index f2c944329..bda71b202 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts @@ -630,8 +630,8 @@ export const vDefault = v.object({ }); export const vPageable = v.object({ - page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'), v.minValue(0)), 0), - size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'), v.minValue(1))), + page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'), v.minValue(0)), 0), + size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'), v.minValue(1))), sort: v.optional(v.array(v.string())) }); @@ -972,13 +972,13 @@ export const vCompositionWithOneOfAndProperties = v.intersect([v.union([v.strict }), v.strictObject({ bar: vNonAsciiStringæøåÆøÅöôêÊ字符串 })]), v.object({ - baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'), v.minValue(0)), v.null()]), - qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'), v.minValue(0)) + baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'), v.minValue(0)), v.null()]), + qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'), v.minValue(0)) })]); export const vModelWithOneOfAndProperties = v.intersect([v.union([vSimpleParameter, vNonAsciiStringæøåÆøÅöôêÊ字符串]), v.object({ - baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 2^16-1'), v.minValue(0)), v.null()]), - qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 2^8-1'), v.minValue(0)) + baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'), v.minValue(0)), v.null()]), + qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'), v.minValue(0)) })]); /** @@ -1347,7 +1347,7 @@ export const vCollectionFormatData = v.object({ export const vTypesData = v.object({ body: v.optional(v.never()), path: v.optional(v.object({ - id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1'))) + id: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'))) })), query: v.object({ parameterNumber: v.optional(v.number(), 123), @@ -1461,12 +1461,12 @@ export const vComplexParamsData = v.object({ vModelWithDictionary ]), user: v.optional(v.pipe(v.object({ - id: v.optional(v.pipe(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')), v.readonly())), + id: v.optional(v.pipe(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647')), v.readonly())), name: v.optional(v.pipe(v.union([v.pipe(v.string(), v.readonly()), v.null()]), v.readonly())) }), v.readonly())) })), path: v.object({ - id: v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2^31'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2^31-1')), + id: v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647')), 'api-version': v.string() }), query: v.optional(v.never()) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-bigint-min-max/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-bigint-min-max/valibot.gen.ts index c3c08a3d9..cbeb18dc2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-bigint-min-max/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-bigint-min-max/valibot.gen.ts @@ -7,5 +7,5 @@ export const vFoo = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'), v.minValue(BigInt(0)), v.maxValue(BigInt(100)))) + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'), v.minValue(BigInt(0)), v.maxValue(BigInt(100)))) }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/valibot.gen.ts index 0faa468f8..c029506af 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/valibot.gen.ts @@ -9,7 +9,7 @@ export const vSessionUserPhoneCalloutRingingWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -17,7 +17,7 @@ export const vSessionUserPhoneCalloutRingingWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -30,12 +30,12 @@ export const vSessionUserPhoneCalloutRingingWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), from_number: v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')) + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')) }) }) }) @@ -51,7 +51,7 @@ export const vSessionUserRoomSystemCalloutRingingWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -59,7 +59,7 @@ export const vSessionUserRoomSystemCalloutRingingWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -84,7 +84,7 @@ export const vSessionRecordingStartedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -111,7 +111,7 @@ export const vSessionRecordingResumedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -138,7 +138,7 @@ export const vSessionLiveStreamingStoppedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -176,7 +176,7 @@ export const vSessionStreamIngestionStoppedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -205,7 +205,7 @@ export const vSessionUserRoomSystemCalloutRejectedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -213,7 +213,7 @@ export const vSessionUserRoomSystemCalloutRejectedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -238,7 +238,7 @@ export const vSessionAlertWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -267,7 +267,7 @@ export const vSessionSharingEndedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -303,7 +303,7 @@ export const vSessionRecordingPausedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -330,7 +330,7 @@ export const vSessionEndedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -354,7 +354,7 @@ export const vSessionStartedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -377,7 +377,7 @@ export const vSessionStreamIngestionUnbindWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -406,7 +406,7 @@ export const vSessionLiveStreamingStartedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -444,7 +444,7 @@ export const vSessionUserRoomSystemCalloutMissedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -452,7 +452,7 @@ export const vSessionUserRoomSystemCalloutMissedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -477,7 +477,7 @@ export const vSessionUserPhoneCalloutAcceptedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -485,7 +485,7 @@ export const vSessionUserPhoneCalloutAcceptedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -498,12 +498,12 @@ export const vSessionUserPhoneCalloutAcceptedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), from_number: v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')) + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')) }) }) }) @@ -519,7 +519,7 @@ export const vSessionUserLeftWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -550,7 +550,7 @@ export const vSessionSharingStartedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -586,7 +586,7 @@ export const vSessionUserPhoneCalloutCanceledWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -600,12 +600,12 @@ export const vSessionUserPhoneCalloutCanceledWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), from_number: v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')) + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')) }) }) }) @@ -621,7 +621,7 @@ export const vSessionRecordingTranscriptCompletedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), download_token: v.string(), payload: v.strictObject({ account_id: v.string(), @@ -694,7 +694,7 @@ export const vSessionRecordingDeletedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), operator: v.pipe(v.string(), v.email()), @@ -719,7 +719,7 @@ export const vSessionUserRoomSystemCalloutFailedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -727,7 +727,7 @@ export const vSessionUserRoomSystemCalloutFailedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -753,7 +753,7 @@ export const vSessionRecordingCompletedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), download_token: v.string(), payload: v.strictObject({ account_id: v.string(), @@ -890,7 +890,7 @@ export const vSessionRecordingTranscriptFailedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -913,7 +913,7 @@ export const vSessionRecordingTrashedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), operator: v.pipe(v.string(), v.email()), @@ -938,7 +938,7 @@ export const vSessionUserJoinedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -968,7 +968,7 @@ export const vSessionStreamIngestionStartedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -997,7 +997,7 @@ export const vSessionStreamIngestionConnectedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -1026,7 +1026,7 @@ export const vSessionStreamIngestionDisconnectedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -1055,7 +1055,7 @@ export const vSessionRecordingRecoveredWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), operator: v.pipe(v.string(), v.email()), @@ -1080,7 +1080,7 @@ export const vSessionUserPhoneCalloutMissedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -1088,7 +1088,7 @@ export const vSessionUserPhoneCalloutMissedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -1101,12 +1101,12 @@ export const vSessionUserPhoneCalloutMissedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), from_number: v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')) + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')) }) }) }) @@ -1122,7 +1122,7 @@ export const vSessionUserPhoneCalloutRejectedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -1130,7 +1130,7 @@ export const vSessionUserPhoneCalloutRejectedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -1143,12 +1143,12 @@ export const vSessionUserPhoneCalloutRejectedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), from_number: v.pipe(v.union([ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')) + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')) }) }) }) @@ -1164,7 +1164,7 @@ export const vSessionUserRoomSystemCalloutAcceptedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ @@ -1172,7 +1172,7 @@ export const vSessionUserRoomSystemCalloutAcceptedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1'))), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'))), uuid: v.optional(v.string()), session_id: v.string(), session_name: v.string(), @@ -1197,7 +1197,7 @@ export const vSessionRecordingStoppedWebhookRequest = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -2^63'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 2^63-1')), + ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807')), payload: v.strictObject({ account_id: v.string(), object: v.strictObject({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/zod.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/zod.gen.ts index 633c15a60..d3d62087d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/zod.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/zod.gen.ts @@ -5,11 +5,11 @@ import { z } from 'zod'; export const zSessionUserPhoneCalloutRingingWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -18,8 +18,8 @@ export const zSessionUserPhoneCalloutRingingWebhookRequest = z.object({ host_id: z.string(), participant: z.object({ invitee_name: z.string(), - phone_number: z.coerce.bigint(), - from_number: z.coerce.bigint() + phone_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + from_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) }) }) }) @@ -31,11 +31,11 @@ export const zSessionUserPhoneCalloutRingingWebhookRequest = z.object({ export const zSessionUserRoomSystemCalloutRingingWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -56,7 +56,7 @@ export const zSessionUserRoomSystemCalloutRingingWebhookRequest = z.object({ export const zSessionRecordingStartedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_started']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -79,7 +79,7 @@ export const zSessionRecordingStartedWebhookRequest = z.object({ export const zSessionRecordingResumedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_resumed']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -102,7 +102,7 @@ export const zSessionRecordingResumedWebhookRequest = z.object({ export const zSessionLiveStreamingStoppedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.live_streaming_stopped']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -136,7 +136,7 @@ export const zSessionLiveStreamingStoppedWebhookRequest = z.object({ export const zSessionStreamIngestionStoppedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.stream_ingestion_stopped']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -161,11 +161,11 @@ export const zSessionStreamIngestionStoppedWebhookRequest = z.object({ export const zSessionUserRoomSystemCalloutRejectedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -186,7 +186,7 @@ export const zSessionUserRoomSystemCalloutRejectedWebhookRequest = z.object({ export const zSessionAlertWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.alert']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -211,7 +211,7 @@ export const zSessionAlertWebhookRequest = z.object({ export const zSessionSharingEndedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.sharing_ended']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -243,7 +243,7 @@ export const zSessionSharingEndedWebhookRequest = z.object({ export const zSessionRecordingPausedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_paused']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -266,7 +266,7 @@ export const zSessionRecordingPausedWebhookRequest = z.object({ export const zSessionEndedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.ended']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -286,7 +286,7 @@ export const zSessionEndedWebhookRequest = z.object({ export const zSessionStartedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.started']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -305,7 +305,7 @@ export const zSessionStartedWebhookRequest = z.object({ export const zSessionStreamIngestionUnbindWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.stream_ingestion_unbind']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -330,7 +330,7 @@ export const zSessionStreamIngestionUnbindWebhookRequest = z.object({ export const zSessionLiveStreamingStartedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.live_streaming_started']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -364,11 +364,11 @@ export const zSessionLiveStreamingStartedWebhookRequest = z.object({ export const zSessionUserRoomSystemCalloutMissedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -389,11 +389,11 @@ export const zSessionUserRoomSystemCalloutMissedWebhookRequest = z.object({ export const zSessionUserPhoneCalloutAcceptedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -402,8 +402,8 @@ export const zSessionUserPhoneCalloutAcceptedWebhookRequest = z.object({ host_id: z.string(), participant: z.object({ invitee_name: z.string(), - phone_number: z.coerce.bigint(), - from_number: z.coerce.bigint() + phone_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + from_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) }) }) }) @@ -415,7 +415,7 @@ export const zSessionUserPhoneCalloutAcceptedWebhookRequest = z.object({ export const zSessionUserLeftWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.user_left']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -442,7 +442,7 @@ export const zSessionUserLeftWebhookRequest = z.object({ export const zSessionSharingStartedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.sharing_started']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -474,7 +474,7 @@ export const zSessionSharingStartedWebhookRequest = z.object({ export const zSessionUserPhoneCalloutCanceledWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -484,8 +484,8 @@ export const zSessionUserPhoneCalloutCanceledWebhookRequest = z.object({ user_key: z.string(), participant: z.object({ invitee_name: z.string(), - phone_number: z.coerce.bigint(), - from_number: z.coerce.bigint() + phone_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + from_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) }) }) }) @@ -497,7 +497,7 @@ export const zSessionUserPhoneCalloutCanceledWebhookRequest = z.object({ export const zSessionRecordingTranscriptCompletedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_transcript_completed']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), download_token: z.string(), payload: z.object({ account_id: z.string(), @@ -566,7 +566,7 @@ export const zSessionRecordingTranscriptCompletedWebhookRequest = z.object({ export const zSessionRecordingDeletedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_deleted']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), operator: z.email(), @@ -587,11 +587,11 @@ export const zSessionRecordingDeletedWebhookRequest = z.object({ export const zSessionUserRoomSystemCalloutFailedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -627,7 +627,7 @@ export const zSessionUserRoomSystemCalloutFailedWebhookRequest = z.object({ export const zSessionRecordingCompletedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_completed']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), download_token: z.string(), payload: z.object({ account_id: z.string(), @@ -760,7 +760,7 @@ export const zSessionRecordingCompletedWebhookRequest = z.object({ export const zSessionRecordingTranscriptFailedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_transcript_failed']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -779,7 +779,7 @@ export const zSessionRecordingTranscriptFailedWebhookRequest = z.object({ export const zSessionRecordingTrashedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_trashed']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), operator: z.email(), @@ -800,7 +800,7 @@ export const zSessionRecordingTrashedWebhookRequest = z.object({ export const zSessionUserJoinedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.user_joined']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -826,7 +826,7 @@ export const zSessionUserJoinedWebhookRequest = z.object({ export const zSessionStreamIngestionStartedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.stream_ingestion_started']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -851,7 +851,7 @@ export const zSessionStreamIngestionStartedWebhookRequest = z.object({ export const zSessionStreamIngestionConnectedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.stream_ingestion_connected']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -876,7 +876,7 @@ export const zSessionStreamIngestionConnectedWebhookRequest = z.object({ export const zSessionStreamIngestionDisconnectedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.stream_ingestion_disconnected']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ @@ -901,7 +901,7 @@ export const zSessionStreamIngestionDisconnectedWebhookRequest = z.object({ export const zSessionRecordingRecoveredWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_recovered']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), operator: z.email(), @@ -922,11 +922,11 @@ export const zSessionRecordingRecoveredWebhookRequest = z.object({ export const zSessionUserPhoneCalloutMissedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -935,8 +935,8 @@ export const zSessionUserPhoneCalloutMissedWebhookRequest = z.object({ host_id: z.string(), participant: z.object({ invitee_name: z.string(), - phone_number: z.coerce.bigint(), - from_number: z.coerce.bigint() + phone_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + from_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) }) }) }) @@ -948,11 +948,11 @@ export const zSessionUserPhoneCalloutMissedWebhookRequest = z.object({ export const zSessionUserPhoneCalloutRejectedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -961,8 +961,8 @@ export const zSessionUserPhoneCalloutRejectedWebhookRequest = z.object({ host_id: z.string(), participant: z.object({ invitee_name: z.string(), - phone_number: z.coerce.bigint(), - from_number: z.coerce.bigint() + phone_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + from_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) }) }) }) @@ -974,11 +974,11 @@ export const zSessionUserPhoneCalloutRejectedWebhookRequest = z.object({ export const zSessionUserRoomSystemCalloutAcceptedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.string(), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ - id: z.optional(z.coerce.bigint()), + id: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), uuid: z.optional(z.string()), session_id: z.string(), session_name: z.string(), @@ -999,7 +999,7 @@ export const zSessionUserRoomSystemCalloutAcceptedWebhookRequest = z.object({ export const zSessionRecordingStoppedWebhookRequest = z.object({ body: z.optional(z.object({ event: z.enum(['session.recording_stopped']), - event_ts: z.coerce.bigint(), + event_ts: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), payload: z.object({ account_id: z.string(), object: z.object({ diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/test/objectAdditionalProperties/additional-properties.test.ts b/packages/openapi-ts-tests/main/test/additional-properties.test.ts similarity index 97% rename from packages/openapi-ts-tests/main/test/plugins/valibot/test/objectAdditionalProperties/additional-properties.test.ts rename to packages/openapi-ts-tests/main/test/additional-properties.test.ts index a4b0826db..1ebec9881 100644 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/test/objectAdditionalProperties/additional-properties.test.ts +++ b/packages/openapi-ts-tests/main/test/additional-properties.test.ts @@ -1,13 +1,17 @@ import * as v from 'valibot'; import { beforeAll, describe, expect, it } from 'vitest'; -import { setupValibotTest } from '../../test-helper'; +import { setupValibotTest } from './test-helper'; +// TODO: further clean up describe('Object Additional Properties Tests', () => { let generatedSchemas: any; beforeAll(async () => { - generatedSchemas = await setupValibotTest(); + generatedSchemas = await setupValibotTest( + 'additional-properties.yaml', + 'additional-properties', + ); }); describe('ObjectWithAdditionalPropertiesString', () => { diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/const-values.test.ts b/packages/openapi-ts-tests/main/test/const-values.test.ts similarity index 98% rename from packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/const-values.test.ts rename to packages/openapi-ts-tests/main/test/const-values.test.ts index 473c21802..266caf083 100644 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/const-values.test.ts +++ b/packages/openapi-ts-tests/main/test/const-values.test.ts @@ -1,13 +1,17 @@ import * as v from 'valibot'; import { beforeAll, describe, expect, it } from 'vitest'; -import { setupValibotTest } from '../../test-helper'; +import { setupValibotTest } from './test-helper'; +// TODO: further clean up describe('Number Type Const Values Tests', () => { let generatedSchemas: any; beforeAll(async () => { - generatedSchemas = await setupValibotTest(); + generatedSchemas = await setupValibotTest( + 'const-values.yaml', + 'const-values', + ); }); describe('Number Type Const Validation', () => { diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/formats.test.ts b/packages/openapi-ts-tests/main/test/formats.test.ts similarity index 93% rename from packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/formats.test.ts rename to packages/openapi-ts-tests/main/test/formats.test.ts index 3f1ce37bc..1a5245f48 100644 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/formats.test.ts +++ b/packages/openapi-ts-tests/main/test/formats.test.ts @@ -1,64 +1,65 @@ import * as v from 'valibot'; import { beforeAll, describe, expect, it } from 'vitest'; -import { setupValibotTest } from '../../test-helper'; +import { setupValibotTest } from './test-helper'; +// TODO: further clean up describe('Number Type Formats Tests', () => { let generatedSchemas: any; beforeAll(async () => { - generatedSchemas = await setupValibotTest(); + generatedSchemas = await setupValibotTest('formats.yaml', 'formats'); }); // Format bounds and error messages from INTEGER_FORMATS const FORMAT_BOUNDS = { int16: { max: 32767, - maxError: 'Expected int16 to be <= 2^15-1', + maxError: 'Invalid value: Expected int16 to be <= 32767', min: -32768, - minError: 'Expected int16 to be >= -2^15', + minError: 'Invalid value: Expected int16 to be >= -32768', }, int32: { max: 2147483647, - maxError: 'Expected int32 to be <= 2^31-1', + maxError: 'Invalid value: Expected int32 to be <= 2147483647', min: -2147483648, - minError: 'Expected int32 to be >= -2^31', + minError: 'Invalid value: Expected int32 to be >= -2147483648', }, int64: { max: '9223372036854775807', - maxError: 'Expected int64 to be <= 2^63-1', + maxError: 'Invalid value: Expected int64 to be <= 9223372036854775807', min: '-9223372036854775808', - minError: 'Expected int64 to be >= -2^63', + minError: 'Invalid value: Expected int64 to be >= -9223372036854775808', }, int8: { max: 127, - maxError: 'Expected int8 to be <= 2^7-1', + maxError: 'Invalid value: Expected int8 to be <= 127', min: -128, - minError: 'Expected int8 to be >= -2^7', + minError: 'Invalid value: Expected int8 to be >= -128', }, uint16: { max: 65535, - maxError: 'Expected uint16 to be <= 2^16-1', + maxError: 'Invalid value: Expected uint16 to be <= 65535', min: 0, - minError: 'Expected uint16 to be >= 0', + minError: 'Invalid value: Expected uint16 to be >= 0', }, uint32: { max: 4294967295, - maxError: 'Expected uint32 to be <= 2^32-1', + maxError: 'Invalid value: Expected uint32 to be <= 4294967295', min: 0, - minError: 'Expected uint32 to be >= 0', + minError: 'Invalid value: Expected uint32 to be >= 0', }, uint64: { max: '18446744073709551615', - maxError: 'Expected uint64 to be <= 2^64-1', + maxError: 'Invalid value: Expected uint64 to be <= 18446744073709551615', min: '0', - minError: 'Expected uint64 to be >= 0', + minError: 'Invalid value: Expected uint64 to be >= 0', }, uint8: { max: 255, - maxError: 'Expected uint8 to be <= 2^8-1', + maxError: 'Invalid value: Expected uint8 to be <= 255', min: 0, - minError: 'Expected uint8 to be >= 0', + minError: 'Invalid value: Expected uint8 to be >= 0', }, }; diff --git a/packages/openapi-ts-tests/main/test/plugins/@tanstack/meta-function.test.ts b/packages/openapi-ts-tests/main/test/meta-function.test.ts similarity index 91% rename from packages/openapi-ts-tests/main/test/plugins/@tanstack/meta-function.test.ts rename to packages/openapi-ts-tests/main/test/meta-function.test.ts index 3905b69d3..b66bd6f8f 100644 --- a/packages/openapi-ts-tests/main/test/plugins/@tanstack/meta-function.test.ts +++ b/packages/openapi-ts-tests/main/test/meta-function.test.ts @@ -5,15 +5,17 @@ import { fileURLToPath } from 'node:url'; import { createClient, type UserConfig } from '@hey-api/openapi-ts'; import { describe, expect, it } from 'vitest'; -import { getFilePaths, getSpecsPath } from '../../../../utils'; +import { getFilePaths, getSpecsPath } from '../../utils'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -describe('TanStack Query Meta Function Customization', () => { - const version = '3.1.x'; - const namespace = 'plugins'; +const version = '3.1.x'; +const namespace = 'plugins'; +const outputDir = path.join(__dirname, 'generated', version, namespace); +// TODO: further clean up +describe('TanStack Query Meta Function Customization', () => { const createConfig = ( userConfig: Omit & Pick, 'input'>, ): UserConfig => ({ @@ -57,12 +59,10 @@ describe('TanStack Query Meta Function Customization', () => { const scenarios = frameworks.map((framework) => ({ config: createConfig({ output: path.join( - __dirname, - 'generated', - version, - namespace, + outputDir, '@tanstack', - `${framework.output}/meta-function`, + framework.output, + 'meta-function', ), plugins: [ { diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/min-max-constraints.test.ts b/packages/openapi-ts-tests/main/test/min-max-constraints.test.ts similarity index 99% rename from packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/min-max-constraints.test.ts rename to packages/openapi-ts-tests/main/test/min-max-constraints.test.ts index faeaafbc1..39e020aea 100644 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/test/numberTypeToValibotSchema/min-max-constraints.test.ts +++ b/packages/openapi-ts-tests/main/test/min-max-constraints.test.ts @@ -1,13 +1,17 @@ import * as v from 'valibot'; import { beforeAll, describe, expect, it } from 'vitest'; -import { setupValibotTest } from '../../test-helper'; +import { setupValibotTest } from './test-helper'; +// TODO: further clean up describe('Number Type Min/Max Constraints Tests', () => { let generatedSchemas: any; beforeAll(async () => { - generatedSchemas = await setupValibotTest(); + generatedSchemas = await setupValibotTest( + 'min-max-constraints.yaml', + 'min-max-constraints', + ); }); describe('Basic Number Constraints', () => { diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/test-helper.ts b/packages/openapi-ts-tests/main/test/plugins/valibot/test-helper.ts deleted file mode 100644 index cb8fc413d..000000000 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/test-helper.ts +++ /dev/null @@ -1,211 +0,0 @@ -/** - * Test helper for Valibot plugin tests - * Provides common functionality for schema generation and loading - */ - -import fs from 'node:fs'; -import path from 'node:path'; - -import { createClient } from '@hey-api/openapi-ts'; -import * as v from 'valibot'; - -/** - * Detect test name from the calling file - */ -function detectTestName(): string { - const stack = new Error().stack; - if (!stack) { - throw new Error('Unable to detect test name: no stack trace available'); - } - - // Find the first stack frame that contains a .test.ts file - const testFileMatch = stack.match(/([^\\/]+)\.test\.ts/); - if (!testFileMatch || !testFileMatch[1]) { - throw new Error( - 'Unable to detect test name: no .test.ts file found in stack trace', - ); - } - - return testFileMatch[1]; -} - -/** - * Detect base directory from the calling file - */ -function detectBaseDir(): string { - const stack = new Error().stack; - if (!stack) { - throw new Error( - 'Unable to detect base directory: no stack trace available', - ); - } - - // Try multiple regex patterns to match different stack trace formats - const patterns = [ - /at .* \(([^)]+\.test\.ts):\d+:\d+\)/, // Original pattern - /at ([^:]+\.test\.ts):\d+:\d+/, // Alternative pattern without parentheses - /([^:\s]+\.test\.ts):\d+:\d+/, // Simple pattern - ]; - - for (const pattern of patterns) { - const testFileMatch = stack.match(pattern); - if (testFileMatch && testFileMatch[1]) { - return path.dirname(testFileMatch[1]); - } - } - - throw new Error( - 'Unable to detect base directory: no .test.ts file found in stack trace', - ); -} - -/** - * Detect function name from the test file path - * Extracts the directory name between 'test/' and the test file - * e.g., from 'test/plugins/valibot/test/numberTypeToValibotSchema/formats.test.ts' - * extracts 'numberTypeToValibotSchema' - */ -function detectFunctionName(): string { - const stack = new Error().stack; - if (!stack) { - throw new Error('Unable to detect function name: no stack trace available'); - } - - // Try multiple regex patterns to match different stack trace formats - const patterns = [ - /at .* \(([^)]+\.test\.ts):\d+:\d+\)/, // Original pattern - /at ([^:]+\.test\.ts):\d+:\d+/, // Alternative pattern without parentheses - /([^:\s]+\.test\.ts):\d+:\d+/, // Simple pattern - ]; - - for (const pattern of patterns) { - const testFileMatch = stack.match(pattern); - if (testFileMatch && testFileMatch[1]) { - const testFilePath = testFileMatch[1]; - - // Extract function name from path pattern: .../test/[FUNCTION_NAME]/[TEST_NAME].test.ts - const pathParts = testFilePath.split(/[/\\]/); - const testIndex = pathParts.lastIndexOf('test'); - - if (testIndex !== -1 && testIndex < pathParts.length - 2) { - const functionName = pathParts[testIndex + 1]; - if (functionName) { - return functionName; - } - } - - throw new Error( - `Unable to extract function name from test path: ${testFilePath}\n` + - `Expected path pattern: .../test/[FUNCTION_NAME]/[TEST_NAME].test.ts`, - ); - } - } - - throw new Error( - 'Unable to detect function name: no .test.ts file found in stack trace', - ); -} - -/** - * Load and evaluate the generated schemas - */ -function loadGeneratedSchemas(generatedPath: string): any { - if (!fs.existsSync(generatedPath)) { - throw new Error( - `Generated schema file not found: ${generatedPath}\n` + - `Schema generation may have failed. Check the input schema file for errors.`, - ); - } - - try { - const generatedCode = fs.readFileSync(generatedPath, 'utf-8'); - - // Extract all export statements and create a proper return object - const exportMatches = generatedCode.match(/export const (\w+)/g); - if (!exportMatches) { - // noinspection ExceptionCaughtLocallyJS - throw new Error('No exported schemas found in generated code'); - } - - // Create evaluation code that returns an object with all exports - const schemaNames = exportMatches.map((match: string) => - match.replace('export const ', ''), - ); - const evalCode = - generatedCode - .replace(/import \* as v from 'valibot';/, '') - .replace(/export const/g, 'const') - .replace(/v\./g, 'vModule.') + - `\n\nreturn { ${schemaNames.join(', ')} };`; - - // Wrap in a function to capture the return value - const schemaFunction = new Function('vModule', evalCode); - return schemaFunction(v); - } catch (error) { - throw new Error( - `Failed to load generated schemas from ${generatedPath}: ${error instanceof Error ? error.message : String(error)}\n` + - `The generated file may contain syntax errors or be malformed.`, - ); - } -} - -/** - * Setup function for Valibot tests - * Automatically detects test name and paths, generates schemas, and returns them - */ -export async function setupValibotTest(): Promise { - // Detect test name, function name, and base directory from calling file - const testName = detectTestName(); - const functionName = detectFunctionName(); - const baseDir = detectBaseDir(); - - // Construct paths dynamically based on detected function name - const schemaPath = path.join( - baseDir, - '..', - '..', - 'spec', - functionName, - `${testName}.yaml`, - ); - const outputPath = path.join( - baseDir, - '..', - '..', - 'generated', - functionName, - testName, - ); - - // Check if spec file exists - if (!fs.existsSync(schemaPath)) { - throw new Error( - `Schema file not found: ${schemaPath}\n` + - `Expected schema file for test '${testName}' in function '${functionName}' at the above location.\n` + - `Please ensure the spec file exists and matches the test name.`, - ); - } - - try { - // Create output directory - fs.mkdirSync(outputPath, { recursive: true }); - - // Generate Valibot schemas - await createClient({ - input: schemaPath, - logs: { level: 'silent' }, - output: outputPath, - plugins: ['valibot'], - }); - - // Load and return the generated schemas - const generatedPath = path.join(outputPath, 'valibot.gen.ts'); - return loadGeneratedSchemas(generatedPath); - } catch (error) { - throw new Error( - `Failed to generate schemas for test '${testName}' in function '${functionName}': ${error instanceof Error ? error.message : String(error)}\n` + - `Schema path: ${schemaPath}\n` + - `Output path: ${outputPath}`, - ); - } -} diff --git a/packages/openapi-ts-tests/main/test/test-helper.ts b/packages/openapi-ts-tests/main/test/test-helper.ts new file mode 100644 index 000000000..e1f86ba5a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/test-helper.ts @@ -0,0 +1,80 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { createClient } from '@hey-api/openapi-ts'; +import * as v from 'valibot'; + +import { getSpecsPath } from '../../utils'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const version = '3.1.x'; + +const outputDir = path.join(__dirname, 'generated', version); + +/** + * Load and evaluate the generated schemas + */ +function loadGeneratedSchemas(generatedPath: string): any { + if (!fs.existsSync(generatedPath)) { + throw new Error( + `Generated schema file not found: ${generatedPath}\n` + + `Schema generation may have failed. Check the input schema file for errors.`, + ); + } + + try { + const generatedCode = fs.readFileSync(generatedPath, 'utf-8'); + + // Extract all export statements and create a proper return object + const exportMatches = generatedCode.match(/export const (\w+)/g); + if (!exportMatches) { + // noinspection ExceptionCaughtLocallyJS + throw new Error('No exported schemas found in generated code'); + } + + // Create evaluation code that returns an object with all exports + const schemaNames = exportMatches.map((match: string) => + match.replace('export const ', ''), + ); + const evalCode = + generatedCode + .replace(/import \* as v from 'valibot';/, '') + .replace(/export const/g, 'const') + .replace(/v\./g, 'vModule.') + + `\n\nreturn { ${schemaNames.join(', ')} };`; + + // Wrap in a function to capture the return value + const schemaFunction = new Function('vModule', evalCode); + return schemaFunction(v); + } catch (error) { + throw new Error( + `Failed to load generated schemas from ${generatedPath}: ${error instanceof Error ? error.message : String(error)}\n` + + `The generated file may contain syntax errors or be malformed.`, + ); + } +} + +// TODO: further clean up +export async function setupValibotTest( + input: string, + output: string, +): Promise { + const inputPath = path.join(getSpecsPath(), version, input); + const outputPath = path.join(outputDir, output); + + fs.mkdirSync(outputPath, { recursive: true }); + + await createClient({ + input: inputPath, + logs: { level: 'silent' }, + output: outputPath, + plugins: ['valibot'], + }); + + // Load and return the generated schemas + const generatedPath = path.join(outputPath, 'valibot.gen.ts'); + return loadGeneratedSchemas(generatedPath); +} diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts index e44daf15b..3498fde56 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts @@ -722,7 +722,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))) })), query: z.object({ parameterNumber: z._default(z.number(), 123), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/type-format-zod/zod.gen.ts index 79baa0efd..e21bae535 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z._default(z.coerce.bigint(), BigInt(0)), + foo: z._default(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts index 99cb26f2e..1b73135f9 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts @@ -720,7 +720,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.never().optional(), path: z.object({ - id: z.number().int().optional() + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional() }).optional(), query: z.object({ parameterNumber: z.number().default(123), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/type-format-zod/zod.gen.ts index bcca2e71b..f7a98f3d5 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.number().int().optional(), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts index bc91971e3..f1dca5dcd 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts @@ -722,7 +722,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })) })), query: z.object({ parameterNumber: z.number().default(123), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/type-format-zod/zod.gen.ts index c0a77c99d..9bd41ca58 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts index b6370f67c..eca782560 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -710,8 +710,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z._default(z.optional(z.int().check(z.gte(0))), 0), - size: z.optional(z.int().check(z.gte(1))), + page: z._default(z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(0))), 0), + size: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(1))), sort: z.optional(z.array(z.string())) }); @@ -1127,10 +1127,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().check(z.gte(0)), + z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), z.null() ]), - qux: z.int().check(z.gte(0)) + qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1138,10 +1138,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().check(z.gte(0)), + z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), z.null() ]), - qux: z.int().check(z.gte(0)) + qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) })); /** @@ -1585,7 +1585,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))) })), query: z.object({ parameterNumber: z._default(z.number(), 123), @@ -1731,7 +1731,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.optional(z.readonly(z.object({ - id: z.optional(z.readonly(z.int())), + id: z.optional(z.readonly(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })))), name: z.optional(z.readonly(z.union([ z.readonly(z.string()), z.null() @@ -1739,7 +1739,7 @@ export const zComplexParamsData = z.object({ }))) })), path: z.object({ - id: z.int(), + id: z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })), 'api-version': z.string() }), query: z.optional(z.never()) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/type-format-zod/zod.gen.ts index 79baa0efd..e21bae535 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z._default(z.coerce.bigint(), BigInt(0)), + foo: z._default(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts index e7fb6be96..e9bcaf93a 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -708,8 +708,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.number().int().gte(0).optional().default(0), - size: z.number().int().gte(1).optional(), + page: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0).optional().default(0), + size: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1).optional(), sort: z.array(z.string()).optional() }); @@ -1125,10 +1125,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.number().int().gte(0), + z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.number().int().gte(0) + qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1136,10 +1136,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.number().int().gte(0), + z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.number().int().gte(0) + qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); /** @@ -1583,7 +1583,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.never().optional(), path: z.object({ - id: z.number().int().optional() + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional() }).optional(), query: z.object({ parameterNumber: z.number().default(123), @@ -1729,7 +1729,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.object({ - id: z.number().int().readonly().optional(), + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).readonly().optional(), name: z.union([ z.string().readonly(), z.null() @@ -1737,7 +1737,7 @@ export const zComplexParamsData = z.object({ }).readonly().optional() }).optional(), path: z.object({ - id: z.number().int(), + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }), 'api-version': z.string() }), query: z.never().optional() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/type-format-zod/zod.gen.ts index bcca2e71b..f7a98f3d5 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.number().int().optional(), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts index 3f328c90d..1ff6a0a79 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -710,8 +710,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.optional(z.int().gte(0)).default(0), - size: z.optional(z.int().gte(1)), + page: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0)).default(0), + size: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1)), sort: z.optional(z.array(z.string())) }); @@ -1127,10 +1127,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().gte(0), + z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.int().gte(0) + qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1138,10 +1138,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().gte(0), + z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.int().gte(0) + qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); /** @@ -1585,7 +1585,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })) })), query: z.object({ parameterNumber: z.number().default(123), @@ -1731,7 +1731,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.optional(z.object({ - id: z.optional(z.int().readonly()), + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).readonly()), name: z.optional(z.union([ z.string().readonly(), z.null() @@ -1739,7 +1739,7 @@ export const zComplexParamsData = z.object({ }).readonly()) })), path: z.object({ - id: z.int(), + id: z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), 'api-version': z.string() }), query: z.optional(z.never()) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/type-format-zod/zod.gen.ts index c0a77c99d..9bd41ca58 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts index 7ca3c6f97..f1c5136f7 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -707,8 +707,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z._default(z.optional(z.int().check(z.gte(0))), 0), - size: z.optional(z.int().check(z.gte(1))), + page: z._default(z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(0))), 0), + size: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(1))), sort: z.optional(z.array(z.string())) }); @@ -1133,10 +1133,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().check(z.gte(0)), + z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), z.null() ]), - qux: z.int().check(z.gte(0)) + qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1144,10 +1144,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().check(z.gte(0)), + z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), z.null() ]), - qux: z.int().check(z.gte(0)) + qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) })); /** @@ -1600,7 +1600,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))) })), query: z.object({ parameterNumber: z._default(z.number(), 123), @@ -1747,7 +1747,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.optional(z.readonly(z.object({ - id: z.optional(z.readonly(z.int())), + id: z.optional(z.readonly(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })))), name: z.optional(z.readonly(z.union([ z.readonly(z.string()), z.null() @@ -1755,7 +1755,7 @@ export const zComplexParamsData = z.object({ }))) })), path: z.object({ - id: z.int(), + id: z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })), 'api-version': z.string() }), query: z.optional(z.never()) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts index 10480c6a6..81cbd8cf8 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts @@ -15,23 +15,23 @@ export const zFoo = z.object({ z.literal(true) ])), corge: z.optional(z.record(z.string(), z.unknown())), - garply: z.optional(z.coerce.bigint()), + garply: z.optional(z.literal(BigInt('10'))), numberInt8: z.optional(z.literal(100)), numberInt16: z.optional(z.literal(1000)), numberInt32: z.optional(z.literal(100000)), - numberInt64: z.optional(z.literal(1000000000000)), + numberInt64: z.optional(z.literal(BigInt(1000000000000))), numberUint8: z.optional(z.literal(200)), numberUint16: z.optional(z.literal(50000)), numberUint32: z.optional(z.literal(3000000000)), - numberUint64: z.optional(z.literal(18000000000000000000)), + numberUint64: z.optional(z.literal(BigInt(18000000000000000000))), integerInt8: z.optional(z.literal(-100)), integerInt16: z.optional(z.literal(-1000)), integerInt32: z.optional(z.literal(-100000)), - integerInt64: z.optional(z.literal(-1000000000000)), + integerInt64: z.optional(z.literal(BigInt(-1000000000000))), integerUint8: z.optional(z.literal(255)), integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), - integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal('-9223372036854775808')), - stringUint64: z.optional(z.literal('18446744073709551615')) + integerUint64: z.optional(z.literal(BigInt('18446744073709551615'))), + stringInt64: z.optional(z.literal(BigInt('-9223372036854775808'))), + stringUint64: z.optional(z.literal(BigInt('18446744073709551615'))) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/type-format-zod/zod.gen.ts index 79baa0efd..e21bae535 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z._default(z.coerce.bigint(), BigInt(0)), + foo: z._default(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts index a413f0991..3e765065d 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ - foo: z.optional(z.coerce.bigint().check(z.gte(BigInt(0)), z.lte(BigInt(100)))) + foo: z.optional(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), z.gte(BigInt(0)), z.lte(BigInt(100)))) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts index 75782a6a3..a13f4f5e8 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -705,8 +705,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.number().int().gte(0).optional().default(0), - size: z.number().int().gte(1).optional(), + page: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0).optional().default(0), + size: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1).optional(), sort: z.array(z.string()).optional() }); @@ -1131,10 +1131,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.number().int().gte(0), + z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.number().int().gte(0) + qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1142,10 +1142,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.number().int().gte(0), + z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.number().int().gte(0) + qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); /** @@ -1598,7 +1598,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.never().optional(), path: z.object({ - id: z.number().int().optional() + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional() }).optional(), query: z.object({ parameterNumber: z.number().default(123), @@ -1745,7 +1745,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.object({ - id: z.number().int().readonly().optional(), + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).readonly().optional(), name: z.union([ z.string().readonly(), z.null() @@ -1753,7 +1753,7 @@ export const zComplexParamsData = z.object({ }).readonly().optional() }).optional(), path: z.object({ - id: z.number().int(), + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }), 'api-version': z.string() }), query: z.never().optional() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts index e577fd348..031983c53 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts @@ -15,23 +15,23 @@ export const zFoo = z.object({ z.literal(true) ]).optional(), corge: z.record(z.unknown()).optional(), - garply: z.coerce.bigint().optional(), + garply: z.literal(BigInt('10')).optional(), numberInt8: z.literal(100).optional(), numberInt16: z.literal(1000).optional(), numberInt32: z.literal(100000).optional(), - numberInt64: z.literal(1000000000000).optional(), + numberInt64: z.literal(BigInt(1000000000000)).optional(), numberUint8: z.literal(200).optional(), numberUint16: z.literal(50000).optional(), numberUint32: z.literal(3000000000).optional(), - numberUint64: z.literal(18000000000000000000).optional(), + numberUint64: z.literal(BigInt(18000000000000000000)).optional(), integerInt8: z.literal(-100).optional(), integerInt16: z.literal(-1000).optional(), integerInt32: z.literal(-100000).optional(), - integerInt64: z.literal(-1000000000000).optional(), + integerInt64: z.literal(BigInt(-1000000000000)).optional(), integerUint8: z.literal(255).optional(), integerUint16: z.literal(65535).optional(), integerUint32: z.literal(4294967295).optional(), - integerUint64: z.number().int().optional(), - stringInt64: z.literal('-9223372036854775808').optional(), - stringUint64: z.literal('18446744073709551615').optional() + integerUint64: z.literal(BigInt('18446744073709551615')).optional(), + stringInt64: z.literal(BigInt('-9223372036854775808')).optional(), + stringUint64: z.literal(BigInt('18446744073709551615')).optional() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/type-format-zod/zod.gen.ts index bcca2e71b..f7a98f3d5 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.number().int().optional(), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts index b9a89eb4e..f43066307 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import { z } from 'zod'; export const zFoo = z.object({ - foo: z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100)).optional() + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).gte(BigInt(0)).lte(BigInt(100)).optional() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts index 445c9f103..7b0404494 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -707,8 +707,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.optional(z.int().gte(0)).default(0), - size: z.optional(z.int().gte(1)), + page: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0)).default(0), + size: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1)), sort: z.optional(z.array(z.string())) }); @@ -1133,10 +1133,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().gte(0), + z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.int().gte(0) + qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1144,10 +1144,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().gte(0), + z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.int().gte(0) + qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); /** @@ -1600,7 +1600,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })) })), query: z.object({ parameterNumber: z.number().default(123), @@ -1747,7 +1747,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.optional(z.object({ - id: z.optional(z.int().readonly()), + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).readonly()), name: z.optional(z.union([ z.string().readonly(), z.null() @@ -1755,7 +1755,7 @@ export const zComplexParamsData = z.object({ }).readonly()) })), path: z.object({ - id: z.int(), + id: z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), 'api-version': z.string() }), query: z.optional(z.never()) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts index 961bdec15..aa8e044cd 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts @@ -15,23 +15,23 @@ export const zFoo = z.object({ z.literal(true) ])), corge: z.optional(z.record(z.string(), z.unknown())), - garply: z.optional(z.coerce.bigint()), + garply: z.optional(z.literal(BigInt('10'))), numberInt8: z.optional(z.literal(100)), numberInt16: z.optional(z.literal(1000)), numberInt32: z.optional(z.literal(100000)), - numberInt64: z.optional(z.literal(1000000000000)), + numberInt64: z.optional(z.literal(BigInt(1000000000000))), numberUint8: z.optional(z.literal(200)), numberUint16: z.optional(z.literal(50000)), numberUint32: z.optional(z.literal(3000000000)), - numberUint64: z.optional(z.literal(18000000000000000000)), + numberUint64: z.optional(z.literal(BigInt(18000000000000000000))), integerInt8: z.optional(z.literal(-100)), integerInt16: z.optional(z.literal(-1000)), integerInt32: z.optional(z.literal(-100000)), - integerInt64: z.optional(z.literal(-1000000000000)), + integerInt64: z.optional(z.literal(BigInt(-1000000000000))), integerUint8: z.optional(z.literal(255)), integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), - integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal('-9223372036854775808')), - stringUint64: z.optional(z.literal('18446744073709551615')) + integerUint64: z.optional(z.literal(BigInt('18446744073709551615'))), + stringInt64: z.optional(z.literal(BigInt('-9223372036854775808'))), + stringUint64: z.optional(z.literal(BigInt('18446744073709551615'))) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/type-format-zod/zod.gen.ts index c0a77c99d..9bd41ca58 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts index 8f2b8f572..142f0a8f3 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ - foo: z.optional(z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100))) + foo: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).gte(BigInt(0)).lte(BigInt(100))) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts index e00616a4b..635fd26df 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts @@ -722,7 +722,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))) })), query: z.object({ parameterNumber: z._default(z.number(), 123), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/type-format-zod/zod.gen.ts index c1893f1c6..41a01d04a 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z._default(z.coerce.bigint(), BigInt(0)), + foo: z._default(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts index 93c84d92c..1d61a080e 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts @@ -720,7 +720,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.never().optional(), path: z.object({ - id: z.number().int().optional() + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional() }).optional(), query: z.object({ parameterNumber: z.number().default(123), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/type-format-zod/zod.gen.ts index 38cd69d09..262cf8307 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v3'; export const zFoo = z.object({ bar: z.number().int().optional(), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts index f2848ba82..19de50e8f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts @@ -722,7 +722,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })) })), query: z.object({ parameterNumber: z.number().default(123), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/type-format-zod/zod.gen.ts index 477553d5c..e0b29908f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts index 9734ab8f1..823cd0cb8 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -710,8 +710,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z._default(z.optional(z.int().check(z.gte(0))), 0), - size: z.optional(z.int().check(z.gte(1))), + page: z._default(z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(0))), 0), + size: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(1))), sort: z.optional(z.array(z.string())) }); @@ -1127,10 +1127,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().check(z.gte(0)), + z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), z.null() ]), - qux: z.int().check(z.gte(0)) + qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1138,10 +1138,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().check(z.gte(0)), + z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), z.null() ]), - qux: z.int().check(z.gte(0)) + qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) })); /** @@ -1585,7 +1585,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))) })), query: z.object({ parameterNumber: z._default(z.number(), 123), @@ -1731,7 +1731,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.optional(z.readonly(z.object({ - id: z.optional(z.readonly(z.int())), + id: z.optional(z.readonly(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })))), name: z.optional(z.readonly(z.union([ z.readonly(z.string()), z.null() @@ -1739,7 +1739,7 @@ export const zComplexParamsData = z.object({ }))) })), path: z.object({ - id: z.int(), + id: z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })), 'api-version': z.string() }), query: z.optional(z.never()) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/type-format-zod/zod.gen.ts index c1893f1c6..41a01d04a 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z._default(z.coerce.bigint(), BigInt(0)), + foo: z._default(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts index dc5b79a54..3dd3645b0 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -708,8 +708,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.number().int().gte(0).optional().default(0), - size: z.number().int().gte(1).optional(), + page: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0).optional().default(0), + size: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1).optional(), sort: z.array(z.string()).optional() }); @@ -1125,10 +1125,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.number().int().gte(0), + z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.number().int().gte(0) + qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1136,10 +1136,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.number().int().gte(0), + z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.number().int().gte(0) + qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); /** @@ -1583,7 +1583,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.never().optional(), path: z.object({ - id: z.number().int().optional() + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional() }).optional(), query: z.object({ parameterNumber: z.number().default(123), @@ -1729,7 +1729,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.object({ - id: z.number().int().readonly().optional(), + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).readonly().optional(), name: z.union([ z.string().readonly(), z.null() @@ -1737,7 +1737,7 @@ export const zComplexParamsData = z.object({ }).readonly().optional() }).optional(), path: z.object({ - id: z.number().int(), + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }), 'api-version': z.string() }), query: z.never().optional() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/type-format-zod/zod.gen.ts index 38cd69d09..262cf8307 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v3'; export const zFoo = z.object({ bar: z.number().int().optional(), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts index 925cc7bf2..9ed580eef 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -710,8 +710,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.optional(z.int().gte(0)).default(0), - size: z.optional(z.int().gte(1)), + page: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0)).default(0), + size: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1)), sort: z.optional(z.array(z.string())) }); @@ -1127,10 +1127,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().gte(0), + z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.int().gte(0) + qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1138,10 +1138,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().gte(0), + z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.int().gte(0) + qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); /** @@ -1585,7 +1585,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })) })), query: z.object({ parameterNumber: z.number().default(123), @@ -1731,7 +1731,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.optional(z.object({ - id: z.optional(z.int().readonly()), + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).readonly()), name: z.optional(z.union([ z.string().readonly(), z.null() @@ -1739,7 +1739,7 @@ export const zComplexParamsData = z.object({ }).readonly()) })), path: z.object({ - id: z.int(), + id: z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), 'api-version': z.string() }), query: z.optional(z.never()) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/type-format-zod/zod.gen.ts index 477553d5c..e0b29908f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts index 45ebeaf53..081f00347 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -707,8 +707,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z._default(z.optional(z.int().check(z.gte(0))), 0), - size: z.optional(z.int().check(z.gte(1))), + page: z._default(z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(0))), 0), + size: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(1))), sort: z.optional(z.array(z.string())) }); @@ -1133,10 +1133,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().check(z.gte(0)), + z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), z.null() ]), - qux: z.int().check(z.gte(0)) + qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1144,10 +1144,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().check(z.gte(0)), + z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), z.null() ]), - qux: z.int().check(z.gte(0)) + qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) })); /** @@ -1600,7 +1600,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))) })), query: z.object({ parameterNumber: z._default(z.number(), 123), @@ -1747,7 +1747,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.optional(z.readonly(z.object({ - id: z.optional(z.readonly(z.int())), + id: z.optional(z.readonly(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })))), name: z.optional(z.readonly(z.union([ z.readonly(z.string()), z.null() @@ -1755,7 +1755,7 @@ export const zComplexParamsData = z.object({ }))) })), path: z.object({ - id: z.int(), + id: z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })), 'api-version': z.string() }), query: z.optional(z.never()) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts index 1b4e0e1cf..c71fbc30a 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts @@ -15,23 +15,23 @@ export const zFoo = z.object({ z.literal(true) ])), corge: z.optional(z.record(z.string(), z.unknown())), - garply: z.optional(z.coerce.bigint()), + garply: z.optional(z.literal(BigInt('10'))), numberInt8: z.optional(z.literal(100)), numberInt16: z.optional(z.literal(1000)), numberInt32: z.optional(z.literal(100000)), - numberInt64: z.optional(z.literal(1000000000000)), + numberInt64: z.optional(z.literal(BigInt(1000000000000))), numberUint8: z.optional(z.literal(200)), numberUint16: z.optional(z.literal(50000)), numberUint32: z.optional(z.literal(3000000000)), - numberUint64: z.optional(z.literal(18000000000000000000)), + numberUint64: z.optional(z.literal(BigInt(18000000000000000000))), integerInt8: z.optional(z.literal(-100)), integerInt16: z.optional(z.literal(-1000)), integerInt32: z.optional(z.literal(-100000)), - integerInt64: z.optional(z.literal(-1000000000000)), + integerInt64: z.optional(z.literal(BigInt(-1000000000000))), integerUint8: z.optional(z.literal(255)), integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), - integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal('-9223372036854775808')), - stringUint64: z.optional(z.literal('18446744073709551615')) + integerUint64: z.optional(z.literal(BigInt('18446744073709551615'))), + stringInt64: z.optional(z.literal(BigInt('-9223372036854775808'))), + stringUint64: z.optional(z.literal(BigInt('18446744073709551615'))) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/type-format-zod/zod.gen.ts index c1893f1c6..41a01d04a 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z._default(z.coerce.bigint(), BigInt(0)), + foo: z._default(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts index 4c7407f99..53111a6ed 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ - foo: z.optional(z.coerce.bigint().check(z.gte(BigInt(0)), z.lte(BigInt(100)))) + foo: z.optional(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), z.gte(BigInt(0)), z.lte(BigInt(100)))) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts index 6d118b7c7..1c578caa7 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -705,8 +705,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.number().int().gte(0).optional().default(0), - size: z.number().int().gte(1).optional(), + page: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0).optional().default(0), + size: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1).optional(), sort: z.array(z.string()).optional() }); @@ -1131,10 +1131,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.number().int().gte(0), + z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.number().int().gte(0) + qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1142,10 +1142,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.number().int().gte(0), + z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.number().int().gte(0) + qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); /** @@ -1598,7 +1598,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.never().optional(), path: z.object({ - id: z.number().int().optional() + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional() }).optional(), query: z.object({ parameterNumber: z.number().default(123), @@ -1745,7 +1745,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.object({ - id: z.number().int().readonly().optional(), + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).readonly().optional(), name: z.union([ z.string().readonly(), z.null() @@ -1753,7 +1753,7 @@ export const zComplexParamsData = z.object({ }).readonly().optional() }).optional(), path: z.object({ - id: z.number().int(), + id: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }), 'api-version': z.string() }), query: z.never().optional() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts index 2f582cbad..fa700cc48 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts @@ -15,23 +15,23 @@ export const zFoo = z.object({ z.literal(true) ]).optional(), corge: z.record(z.unknown()).optional(), - garply: z.coerce.bigint().optional(), + garply: z.literal(BigInt('10')).optional(), numberInt8: z.literal(100).optional(), numberInt16: z.literal(1000).optional(), numberInt32: z.literal(100000).optional(), - numberInt64: z.literal(1000000000000).optional(), + numberInt64: z.literal(BigInt(1000000000000)).optional(), numberUint8: z.literal(200).optional(), numberUint16: z.literal(50000).optional(), numberUint32: z.literal(3000000000).optional(), - numberUint64: z.literal(18000000000000000000).optional(), + numberUint64: z.literal(BigInt(18000000000000000000)).optional(), integerInt8: z.literal(-100).optional(), integerInt16: z.literal(-1000).optional(), integerInt32: z.literal(-100000).optional(), - integerInt64: z.literal(-1000000000000).optional(), + integerInt64: z.literal(BigInt(-1000000000000)).optional(), integerUint8: z.literal(255).optional(), integerUint16: z.literal(65535).optional(), integerUint32: z.literal(4294967295).optional(), - integerUint64: z.number().int().optional(), - stringInt64: z.literal('-9223372036854775808').optional(), - stringUint64: z.literal('18446744073709551615').optional() + integerUint64: z.literal(BigInt('18446744073709551615')).optional(), + stringInt64: z.literal(BigInt('-9223372036854775808')).optional(), + stringUint64: z.literal(BigInt('18446744073709551615')).optional() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/type-format-zod/zod.gen.ts index 38cd69d09..262cf8307 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod/v3'; export const zFoo = z.object({ bar: z.number().int().optional(), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts index d2ab7d427..93d8d8201 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import { z } from 'zod/v3'; export const zFoo = z.object({ - foo: z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100)).optional() + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).gte(BigInt(0)).lte(BigInt(100)).optional() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts index d490dd142..a211770dc 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -707,8 +707,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.optional(z.int().gte(0)).default(0), - size: z.optional(z.int().gte(1)), + page: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0)).default(0), + size: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1)), sort: z.optional(z.array(z.string())) }); @@ -1133,10 +1133,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().gte(0), + z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.int().gte(0) + qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1144,10 +1144,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().gte(0), + z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), z.null() ]), - qux: z.int().gte(0) + qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) })); /** @@ -1600,7 +1600,7 @@ export const zCollectionFormatData = z.object({ export const zTypesData = z.object({ body: z.optional(z.never()), path: z.optional(z.object({ - id: z.optional(z.int()) + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })) })), query: z.object({ parameterNumber: z.number().default(123), @@ -1747,7 +1747,7 @@ export const zComplexParamsData = z.object({ zModelWithDictionary ]), user: z.optional(z.object({ - id: z.optional(z.int().readonly()), + id: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).readonly()), name: z.optional(z.union([ z.string().readonly(), z.null() @@ -1755,7 +1755,7 @@ export const zComplexParamsData = z.object({ }).readonly()) })), path: z.object({ - id: z.int(), + id: z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), 'api-version': z.string() }), query: z.optional(z.never()) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts index 2b7e1c462..6f3e7c7c6 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts @@ -15,23 +15,23 @@ export const zFoo = z.object({ z.literal(true) ])), corge: z.optional(z.record(z.string(), z.unknown())), - garply: z.optional(z.coerce.bigint()), + garply: z.optional(z.literal(BigInt('10'))), numberInt8: z.optional(z.literal(100)), numberInt16: z.optional(z.literal(1000)), numberInt32: z.optional(z.literal(100000)), - numberInt64: z.optional(z.literal(1000000000000)), + numberInt64: z.optional(z.literal(BigInt(1000000000000))), numberUint8: z.optional(z.literal(200)), numberUint16: z.optional(z.literal(50000)), numberUint32: z.optional(z.literal(3000000000)), - numberUint64: z.optional(z.literal(18000000000000000000)), + numberUint64: z.optional(z.literal(BigInt(18000000000000000000))), integerInt8: z.optional(z.literal(-100)), integerInt16: z.optional(z.literal(-1000)), integerInt32: z.optional(z.literal(-100000)), - integerInt64: z.optional(z.literal(-1000000000000)), + integerInt64: z.optional(z.literal(BigInt(-1000000000000))), integerUint8: z.optional(z.literal(255)), integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), - integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal('-9223372036854775808')), - stringUint64: z.optional(z.literal('18446744073709551615')) + integerUint64: z.optional(z.literal(BigInt('18446744073709551615'))), + stringInt64: z.optional(z.literal(BigInt('-9223372036854775808'))), + stringUint64: z.optional(z.literal(BigInt('18446744073709551615'))) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/type-format-zod/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/type-format-zod/zod.gen.ts index 477553d5c..e0b29908f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/type-format-zod/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/type-format-zod/zod.gen.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; export const zFoo = z.object({ bar: z.optional(z.int()), - foo: z.coerce.bigint().default(BigInt(0)), + foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(0)), id: z.string() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts index f04eccbf2..a05845133 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import { z } from 'zod'; export const zFoo = z.object({ - foo: z.optional(z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100))) + foo: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).gte(BigInt(0)).lte(BigInt(100))) }); diff --git a/packages/openapi-ts/src/plugins/shared/utils/coerce.ts b/packages/openapi-ts/src/plugins/shared/utils/coerce.ts new file mode 100644 index 000000000..71bd74498 --- /dev/null +++ b/packages/openapi-ts/src/plugins/shared/utils/coerce.ts @@ -0,0 +1,25 @@ +import { $ } from '~/ts-dsl'; + +export const shouldCoerceToBigInt = (format: string | undefined): boolean => + format === 'int64' || format === 'uint64'; + +export const maybeBigInt = ( + value: unknown, + format: string | undefined, +): ReturnType => { + if (!shouldCoerceToBigInt(format)) { + return $.fromValue(value); + } + + if (typeof value === 'string') { + // handle invalid input + if (value.endsWith('n')) value = value.slice(0, -1); + return $('BigInt').call($.fromValue(value)); + } + + if (typeof value === 'number') { + return $('BigInt').call($.fromValue(value)); + } + + return $.fromValue(value); +}; diff --git a/packages/openapi-ts/src/plugins/shared/utils/formats.ts b/packages/openapi-ts/src/plugins/shared/utils/formats.ts new file mode 100644 index 000000000..b29ec10d2 --- /dev/null +++ b/packages/openapi-ts/src/plugins/shared/utils/formats.ts @@ -0,0 +1,34 @@ +type Range = number | string; + +interface IntegerLimit { + maxError: string; + maxValue: Range; + minError: string; + minValue: Range; +} + +const rangeErrors = (format: string, range: [Range, Range]) => ({ + maxError: `Invalid value: Expected ${format} to be <= ${range[1]}`, + minError: `Invalid value: Expected ${format} to be >= ${range[0]}`, +}); + +const integerRange: Record = { + int16: [-32768, 32767], + int32: [-2147483648, 2147483647], + int64: ['-9223372036854775808', '9223372036854775807'], + int8: [-128, 127], + uint16: [0, 65535], + uint32: [0, 4294967295], + uint64: ['0', '18446744073709551615'], + uint8: [0, 255], +}; + +export function getIntegerLimit( + format: string | undefined, +): IntegerLimit | undefined { + if (!format) return; + const range = integerRange[format]; + if (!range) return; + const errors = rangeErrors(format, range); + return { maxValue: range[1], minValue: range[0], ...errors }; +} diff --git a/packages/openapi-ts/src/plugins/valibot/shared/export.ts b/packages/openapi-ts/src/plugins/valibot/shared/export.ts index fe8acdc79..21200813c 100644 --- a/packages/openapi-ts/src/plugins/valibot/shared/export.ts +++ b/packages/openapi-ts/src/plugins/valibot/shared/export.ts @@ -32,6 +32,6 @@ export const exportAst = ({ .$if(state.hasLazyExpression['~ref'], (c) => c.type($.type(v).attr(ast.typeName || identifiers.types.GenericSchema)), ) - .assign(pipesToAst({ pipes: ast.pipes, plugin })); + .assign(pipesToAst(ast.pipes, plugin)); plugin.node(statement); }; diff --git a/packages/openapi-ts/src/plugins/valibot/shared/numbers.ts b/packages/openapi-ts/src/plugins/valibot/shared/numbers.ts deleted file mode 100644 index 6261a7a40..000000000 --- a/packages/openapi-ts/src/plugins/valibot/shared/numbers.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { $ } from '~/ts-dsl'; - -export const INTEGER_FORMATS = { - int16: { - max: 32767, - maxError: 'Invalid value: Expected int16 to be <= 2^15-1', - min: -32768, - minError: 'Invalid value: Expected int16 to be >= -2^15', - needsBigInt: false, - }, - int32: { - max: 2147483647, - maxError: 'Invalid value: Expected int32 to be <= 2^31-1', - min: -2147483648, - minError: 'Invalid value: Expected int32 to be >= -2^31', - needsBigInt: false, - }, - int64: { - max: '9223372036854775807', - maxError: 'Invalid value: Expected int64 to be <= 2^63-1', - min: '-9223372036854775808', - minError: 'Invalid value: Expected int64 to be >= -2^63', - needsBigInt: true, - }, - int8: { - max: 127, - maxError: 'Invalid value: Expected int8 to be <= 2^7-1', - min: -128, - minError: 'Invalid value: Expected int8 to be >= -2^7', - needsBigInt: false, - }, - uint16: { - max: 65535, - maxError: 'Invalid value: Expected uint16 to be <= 2^16-1', - min: 0, - minError: 'Invalid value: Expected uint16 to be >= 0', - needsBigInt: false, - }, - uint32: { - max: 4294967295, - maxError: 'Invalid value: Expected uint32 to be <= 2^32-1', - min: 0, - minError: 'Invalid value: Expected uint32 to be >= 0', - needsBigInt: false, - }, - uint64: { - max: '18446744073709551615', - maxError: 'Invalid value: Expected uint64 to be <= 2^64-1', - min: '0', - minError: 'Invalid value: Expected uint64 to be >= 0', - needsBigInt: true, - }, - uint8: { - max: 255, - maxError: 'Invalid value: Expected uint8 to be <= 2^8-1', - min: 0, - minError: 'Invalid value: Expected uint8 to be >= 0', - needsBigInt: false, - }, -} as const; - -export type IntegerFormat = keyof typeof INTEGER_FORMATS; - -export const isIntegerFormat = ( - format: string | undefined, -): format is IntegerFormat => format !== undefined && format in INTEGER_FORMATS; - -export const needsBigIntForFormat = (format: string | undefined): boolean => - isIntegerFormat(format) && INTEGER_FORMATS[format].needsBigInt; - -export const numberParameter = ({ - isBigInt, - value, -}: { - isBigInt: boolean; - value: unknown; -}): ReturnType => { - const expression = $.fromValue(value); - - if ( - isBigInt && - (typeof value === 'bigint' || - typeof value === 'number' || - typeof value === 'string' || - typeof value === 'boolean') - ) { - return $('BigInt').call(expression); - } - - return expression; -}; diff --git a/packages/openapi-ts/src/plugins/valibot/shared/pipesToAst.ts b/packages/openapi-ts/src/plugins/valibot/shared/pipesToAst.ts index 4e5f6b8eb..3f595c4a1 100644 --- a/packages/openapi-ts/src/plugins/valibot/shared/pipesToAst.ts +++ b/packages/openapi-ts/src/plugins/valibot/shared/pipesToAst.ts @@ -3,13 +3,10 @@ import { $ } from '~/ts-dsl'; import type { ValibotPlugin } from '../types'; import { identifiers } from '../v1/constants'; -export const pipesToAst = ({ - pipes, - plugin, -}: { - pipes: ReadonlyArray>; - plugin: ValibotPlugin['Instance']; -}): ReturnType => { +export const pipesToAst = ( + pipes: ReadonlyArray>, + plugin: ValibotPlugin['Instance'], +): ReturnType => { if (pipes.length === 1) { return pipes[0]!; } diff --git a/packages/openapi-ts/src/plugins/valibot/types.d.ts b/packages/openapi-ts/src/plugins/valibot/types.d.ts index 49364fe0f..ee01cc71d 100644 --- a/packages/openapi-ts/src/plugins/valibot/types.d.ts +++ b/packages/openapi-ts/src/plugins/valibot/types.d.ts @@ -358,6 +358,29 @@ type ValidatorResolver = ( ) => MaybeArray> | null | undefined; type Resolvers = Plugin.Resolvers<{ + /** + * Resolvers for number schemas. + * + * Allows customization of how number types are rendered, including + * per-format handling. + */ + number?: { + /** + * Resolvers for number formats (e.g., `float`, `double`, `int32`). + * + * Each key represents a specific format name with a custom + * resolver function that controls how that format is rendered. + * + * Example path: `~resolvers.number.formats.float` + * + * Returning `undefined` from a resolver will apply the default + * generation behavior for that format. + */ + formats?: Record< + string, + (args: FormatResolverArgs) => boolean | number | undefined + >; + }; /** * Resolvers for object schemas. * diff --git a/packages/openapi-ts/src/plugins/valibot/v1/plugin.ts b/packages/openapi-ts/src/plugins/valibot/v1/plugin.ts index 641485704..b22a52b24 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/plugin.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/plugin.ts @@ -5,11 +5,11 @@ import { deduplicateSchema } from '~/ir/schema'; import type { IR } from '~/ir/types'; import { buildName } from '~/openApi/shared/utils/name'; import type { SchemaWithType } from '~/plugins'; +import { maybeBigInt } from '~/plugins/shared/utils/coerce'; import { $ } from '~/ts-dsl'; import { pathToJsonPointer, refToName } from '~/utils/ref'; import { exportAst } from '../shared/export'; -import { numberParameter } from '../shared/numbers'; import { irOperationToAst } from '../shared/operation'; import { pipesToAst } from '../shared/pipesToAst'; import type { Ast, IrSchemaToAstOptions, PluginState } from '../shared/types'; @@ -87,7 +87,7 @@ export const irSchemaToAst = ({ path: ref([...fromRef(state.path), 'items', index]), }, }); - return pipesToAst({ pipes: itemAst.pipes, plugin }); + return pipesToAst(itemAst.pipes, plugin); }); if (schema.logicalOperator === 'and') { @@ -124,23 +124,22 @@ export const irSchemaToAst = ({ ast.pipes.push(readonlyExpression); } - let callParameter: ReturnType | undefined; - if (schema.default !== undefined) { - const isBigInt = schema.type === 'integer' && schema.format === 'int64'; - callParameter = numberParameter({ isBigInt, value: schema.default }); ast.pipes = [ $(v) .attr(identifiers.schemas.optional) - .call(pipesToAst({ pipes: ast.pipes, plugin }), callParameter), + .call( + pipesToAst(ast.pipes, plugin), + schema.type === 'integer' || schema.type === 'number' + ? maybeBigInt(schema.default, schema.format) + : $.fromValue(schema.default), + ), ]; - } - - if (optional && !callParameter) { + } else if (optional) { ast.pipes = [ $(v) .attr(identifiers.schemas.optional) - .call(pipesToAst({ pipes: ast.pipes, plugin })), + .call(pipesToAst(ast.pipes, plugin)), ]; } } diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/array.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/array.ts index c60ae4504..fdde3a56c 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/array.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/array.ts @@ -54,7 +54,7 @@ export const arrayToAst = ({ if (itemAst.hasLazyExpression) { result.hasLazyExpression = true; } - return pipesToAst({ pipes: itemAst.pipes, plugin }); + return pipesToAst(itemAst.pipes, plugin); }); if (itemExpressions.length === 1) { diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/boolean.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/boolean.ts index 5e6f3415a..9a6c8f215 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/boolean.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/boolean.ts @@ -22,9 +22,9 @@ export const booleanToAst = ({ pipes.push( $(v).attr(identifiers.schemas.literal).call($.literal(schema.const)), ); - return pipesToAst({ pipes, plugin }); + return pipesToAst(pipes, plugin); } pipes.push($(v).attr(identifiers.schemas.boolean).call()); - return pipesToAst({ pipes, plugin }); + return pipesToAst(pipes, plugin); }; diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/index.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/index.ts index e6800609a..c3674b068 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/index.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/index.ts @@ -1,4 +1,5 @@ import type { SchemaWithType } from '~/plugins'; +import { shouldCoerceToBigInt } from '~/plugins/shared/utils/coerce'; import type { $ } from '~/ts-dsl'; import { pipesToAst } from '../../shared/pipesToAst'; @@ -28,13 +29,13 @@ export const irSchemaWithTypeToAst = ({ switch (schema.type) { case 'array': return { - expression: pipesToAst({ - pipes: arrayToAst({ + expression: pipesToAst( + arrayToAst({ ...args, schema: schema as SchemaWithType<'array'>, }).pipes, - plugin: args.plugin, - }), + args.plugin, + ), }; case 'boolean': return { @@ -74,39 +75,35 @@ export const irSchemaWithTypeToAst = ({ }; case 'object': return { - expression: pipesToAst({ - pipes: objectToAst({ + expression: pipesToAst( + objectToAst({ ...args, schema: schema as SchemaWithType<'object'>, }).pipes, - plugin: args.plugin, - }), + args.plugin, + ), }; case 'string': - // For string schemas with int64/uint64 formats, use number handler to generate union with transform - if (schema.format === 'int64' || schema.format === 'uint64') { - return { - expression: numberToAst({ - ...args, - schema: schema as SchemaWithType<'integer' | 'number'>, - }), - }; - } return { - expression: stringToAst({ - ...args, - schema: schema as SchemaWithType<'string'>, - }), + expression: shouldCoerceToBigInt(schema.format) + ? numberToAst({ + ...args, + schema: { ...schema, type: 'number' }, + }) + : stringToAst({ + ...args, + schema: schema as SchemaWithType<'string'>, + }), }; case 'tuple': return { - expression: pipesToAst({ - pipes: tupleToAst({ + expression: pipesToAst( + tupleToAst({ ...args, schema: schema as SchemaWithType<'tuple'>, }).pipes, - plugin: args.plugin, - }), + args.plugin, + ), }; case 'undefined': return { diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts index 6f02cc2d5..8d750db3d 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts @@ -1,12 +1,11 @@ import type { SchemaWithType } from '~/plugins'; +import { + maybeBigInt, + shouldCoerceToBigInt, +} from '~/plugins/shared/utils/coerce'; +import { getIntegerLimit } from '~/plugins/shared/utils/formats'; import { $ } from '~/ts-dsl'; -import { - INTEGER_FORMATS, - isIntegerFormat, - needsBigIntForFormat, - numberParameter, -} from '../../shared/numbers'; import { pipesToAst } from '../../shared/pipesToAst'; import type { IrSchemaToAstOptions } from '../../shared/types'; import { identifiers } from '../constants'; @@ -17,141 +16,86 @@ export const numberToAst = ({ }: IrSchemaToAstOptions & { schema: SchemaWithType<'integer' | 'number'>; }) => { - const format = schema.format; - const isInteger = schema.type === 'integer'; - const isBigInt = needsBigIntForFormat(format); - const formatInfo = isIntegerFormat(format) ? INTEGER_FORMATS[format] : null; - const v = plugin.referenceSymbol({ category: 'external', resource: 'valibot.v', }); - // Return early if const is defined since we can create a literal type directly without additional validation - if (schema.const !== undefined && schema.const !== null) { - const constValue = schema.const; - let literalValue: ReturnType; - - // Case 1: Number with no format -> generate literal with the number - if (typeof constValue === 'number' && !format) { - literalValue = $.literal(constValue); - } - // Case 2: Number with format -> check if format needs BigInt, generate appropriate literal - else if (typeof constValue === 'number' && format) { - if (isBigInt) { - // Format requires BigInt, convert number to BigInt - literalValue = $('BigInt').call($.literal(constValue)); - } else { - // Regular format, use number as-is - literalValue = $.literal(constValue); - } - } - // Case 3: Format that allows string -> generate BigInt literal (for int64/uint64 formats) - else if (typeof constValue === 'string' && isBigInt) { - // Remove 'n' suffix if present in string - const cleanString = constValue.endsWith('n') - ? constValue.slice(0, -1) - : constValue; - literalValue = $('BigInt').call($.literal(cleanString)); - } - // Case 4: Const is typeof bigint (literal) -> transform from literal to BigInt() - else if (typeof constValue === 'bigint') { - // Convert BigInt to string and remove 'n' suffix that toString() adds - const bigintString = constValue.toString(); - const cleanString = bigintString.endsWith('n') - ? bigintString.slice(0, -1) - : bigintString; - literalValue = $('BigInt').call($.literal(cleanString)); - } - // Default case: use value as-is for other types - else { - literalValue = $.fromValue(constValue); - } - - return $(v).attr(identifiers.schemas.literal).call(literalValue); + if (schema.const !== undefined) { + return $(v) + .attr(identifiers.schemas.literal) + .call(maybeBigInt(schema.const, schema.format)); } const pipes: Array> = []; - // For bigint formats (int64, uint64), create union of number, string, and bigint with transform - if (isBigInt) { - const unionExpression = $(v) - .attr(identifiers.schemas.union) - .call( - $.array( - $(v).attr(identifiers.schemas.number).call(), - $(v).attr(identifiers.schemas.string).call(), - $(v).attr(identifiers.schemas.bigInt).call(), + if (shouldCoerceToBigInt(schema.format)) { + pipes.push( + $(v) + .attr(identifiers.schemas.union) + .call( + $.array( + $(v).attr(identifiers.schemas.number).call(), + $(v).attr(identifiers.schemas.string).call(), + $(v).attr(identifiers.schemas.bigInt).call(), + ), ), - ); - pipes.push(unionExpression); - - // Add transform to convert to BigInt - const transformExpression = $(v) - .attr(identifiers.actions.transform) - .call($.func().param('x').do($('BigInt').call('x').return())); - pipes.push(transformExpression); + $(v) + .attr(identifiers.actions.transform) + .call($.func().param('x').do($('BigInt').call('x').return())), + ); } else { - // For regular number formats, use number schema - const expression = $(v).attr(identifiers.schemas.number).call(); - pipes.push(expression); - } - - // Add integer validation for integer types (except when using bigint union) - if (!isBigInt && isInteger) { - const expression = $(v).attr(identifiers.actions.integer).call(); - pipes.push(expression); + pipes.push($(v).attr(identifiers.schemas.number).call()); + if (schema.type === 'integer') { + pipes.push($(v).attr(identifiers.actions.integer).call()); + } } - // Add format-specific range validations - if (formatInfo) { - const minValue = formatInfo.min; - const maxValue = formatInfo.max; - const minErrorMessage = formatInfo.minError; - const maxErrorMessage = formatInfo.maxError; - - // Add minimum value validation - const minExpression = $(v) - .attr(identifiers.actions.minValue) - .call( - isBigInt ? $('BigInt').call($.literal(minValue)) : $.literal(minValue), - $.literal(minErrorMessage), - ); - pipes.push(minExpression); - - // Add maximum value validation - const maxExpression = $(v) - .attr(identifiers.actions.maxValue) - .call( - isBigInt ? $('BigInt').call($.literal(maxValue)) : $.literal(maxValue), - $.literal(maxErrorMessage), - ); - pipes.push(maxExpression); + const integerLimit = getIntegerLimit(schema.format); + if (integerLimit) { + pipes.push( + $(v) + .attr(identifiers.actions.minValue) + .call( + maybeBigInt(integerLimit.minValue, schema.format), + $.literal(integerLimit.minError), + ), + $(v) + .attr(identifiers.actions.maxValue) + .call( + maybeBigInt(integerLimit.maxValue, schema.format), + $.literal(integerLimit.maxError), + ), + ); } if (schema.exclusiveMinimum !== undefined) { - const expression = $(v) - .attr(identifiers.actions.gtValue) - .call(numberParameter({ isBigInt, value: schema.exclusiveMinimum })); - pipes.push(expression); + pipes.push( + $(v) + .attr(identifiers.actions.gtValue) + .call(maybeBigInt(schema.exclusiveMinimum, schema.format)), + ); } else if (schema.minimum !== undefined) { - const expression = $(v) - .attr(identifiers.actions.minValue) - .call(numberParameter({ isBigInt, value: schema.minimum })); - pipes.push(expression); + pipes.push( + $(v) + .attr(identifiers.actions.minValue) + .call(maybeBigInt(schema.minimum, schema.format)), + ); } if (schema.exclusiveMaximum !== undefined) { - const expression = $(v) - .attr(identifiers.actions.ltValue) - .call(numberParameter({ isBigInt, value: schema.exclusiveMaximum })); - pipes.push(expression); + pipes.push( + $(v) + .attr(identifiers.actions.ltValue) + .call(maybeBigInt(schema.exclusiveMaximum, schema.format)), + ); } else if (schema.maximum !== undefined) { - const expression = $(v) - .attr(identifiers.actions.maxValue) - .call(numberParameter({ isBigInt, value: schema.maximum })); - pipes.push(expression); + pipes.push( + $(v) + .attr(identifiers.actions.maxValue) + .call(maybeBigInt(schema.maximum, schema.format)), + ); } - return pipesToAst({ pipes, plugin }); + return pipesToAst(pipes, plugin); }; diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts index e8c145a88..e2a4af103 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts @@ -75,7 +75,7 @@ export const objectToAst = ({ }); if (propertyAst.hasLazyExpression) result.hasLazyExpression = true; - shape.prop(name, pipesToAst({ pipes: propertyAst.pipes, plugin })); + shape.prop(name, pipesToAst(propertyAst.pipes, plugin)); } let additional: ReturnType | null | undefined; @@ -92,7 +92,7 @@ export const objectToAst = ({ }, }); if (additionalAst.hasLazyExpression) result.hasLazyExpression = true; - additional = pipesToAst({ pipes: additionalAst.pipes, plugin }); + additional = pipesToAst(additionalAst.pipes, plugin); } } @@ -107,6 +107,6 @@ export const objectToAst = ({ const resolver = plugin.config['~resolvers']?.object?.base; if (!resolver?.(args)) defaultObjectBaseResolver(args); - result.pipes = [pipesToAst({ pipes, plugin })]; + result.pipes = [pipesToAst(pipes, plugin)]; return result as Omit; }; diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts index 5a0300335..7e2293714 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts @@ -43,20 +43,16 @@ export const stringToAst = ({ }: IrSchemaToAstOptions & { schema: SchemaWithType<'string'>; }): ReturnType => { - const pipes: Array> = []; - const v = plugin.referenceSymbol({ category: 'external', resource: 'valibot.v', }); if (typeof schema.const === 'string') { - pipes.push( - $(v).attr(identifiers.schemas.literal).call($.literal(schema.const)), - ); - return pipesToAst({ pipes, plugin }); + return $(v).attr(identifiers.schemas.literal).call($.literal(schema.const)); } + const pipes: Array> = []; pipes.push($(v).attr(identifiers.schemas.string).call()); if (schema.format) { @@ -94,5 +90,5 @@ export const stringToAst = ({ ); } - return pipesToAst({ pipes, plugin }); + return pipesToAst(pipes, plugin); }; diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/tuple.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/tuple.ts index ab604c9f4..f86b6795b 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/tuple.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/tuple.ts @@ -48,7 +48,7 @@ export const tupleToAst = ({ if (schemaPipes.hasLazyExpression) { result.hasLazyExpression = true; } - return pipesToAst({ pipes: schemaPipes.pipes, plugin }); + return pipesToAst(schemaPipes.pipes, plugin); }); result.pipes = [ $(v) diff --git a/packages/openapi-ts/src/plugins/zod/constants.ts b/packages/openapi-ts/src/plugins/zod/constants.ts index 5d44c6710..58875daca 100644 --- a/packages/openapi-ts/src/plugins/zod/constants.ts +++ b/packages/openapi-ts/src/plugins/zod/constants.ts @@ -32,8 +32,10 @@ export const identifiers = { lte: 'lte', max: 'max', maxLength: 'maxLength', + maximum: 'maximum', // Zod Mini min: 'min', minLength: 'minLength', + minimum: 'minimum', // Zod Mini never: 'never', null: 'null', nullable: 'nullable', diff --git a/packages/openapi-ts/src/plugins/zod/mini/plugin.ts b/packages/openapi-ts/src/plugins/zod/mini/plugin.ts index 711da00db..da510afd6 100644 --- a/packages/openapi-ts/src/plugins/zod/mini/plugin.ts +++ b/packages/openapi-ts/src/plugins/zod/mini/plugin.ts @@ -5,13 +5,13 @@ import { deduplicateSchema } from '~/ir/schema'; import type { IR } from '~/ir/types'; import { buildName } from '~/openApi/shared/utils/name'; import type { SchemaWithType } from '~/plugins'; +import { maybeBigInt } from '~/plugins/shared/utils/coerce'; import { $ } from '~/ts-dsl'; import { pathToJsonPointer, refToName } from '~/utils/ref'; import { identifiers } from '../constants'; import { exportAst } from '../shared/export'; import { getZodModule } from '../shared/module'; -import { numberParameter } from '../shared/numbers'; import { irOperationToAst } from '../shared/operation'; import type { Ast, IrSchemaToAstOptions, PluginState } from '../shared/types'; import { irWebhookToAst } from '../shared/webhook'; @@ -152,15 +152,13 @@ export const irSchemaToAst = ({ } if (schema.default !== undefined) { - const isBigInt = schema.type === 'integer' && schema.format === 'int64'; ast.expression = $(z) .attr(identifiers._default) .call( ast.expression, - numberParameter({ - isBigInt, - value: schema.default, - }), + schema.type === 'integer' || schema.type === 'number' + ? maybeBigInt(schema.default, schema.format) + : $.fromValue(schema.default), ); } } diff --git a/packages/openapi-ts/src/plugins/zod/mini/toAst/index.ts b/packages/openapi-ts/src/plugins/zod/mini/toAst/index.ts index 8c2a5848e..c7459e181 100644 --- a/packages/openapi-ts/src/plugins/zod/mini/toAst/index.ts +++ b/packages/openapi-ts/src/plugins/zod/mini/toAst/index.ts @@ -1,4 +1,5 @@ import type { SchemaWithType } from '~/plugins'; +import { shouldCoerceToBigInt } from '~/plugins/shared/utils/coerce'; import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; import { arrayToAst } from './array'; @@ -58,10 +59,15 @@ export const irSchemaWithTypeToAst = ({ schema: schema as SchemaWithType<'object'>, }); case 'string': - return stringToAst({ - ...args, - schema: schema as SchemaWithType<'string'>, - }); + return shouldCoerceToBigInt(schema.format) + ? numberToAst({ + ...args, + schema: { ...schema, type: 'number' }, + }) + : stringToAst({ + ...args, + schema: schema as SchemaWithType<'string'>, + }); case 'tuple': return tupleToAst({ ...args, diff --git a/packages/openapi-ts/src/plugins/zod/mini/toAst/number.ts b/packages/openapi-ts/src/plugins/zod/mini/toAst/number.ts index feee19866..9f55d6ee0 100644 --- a/packages/openapi-ts/src/plugins/zod/mini/toAst/number.ts +++ b/packages/openapi-ts/src/plugins/zod/mini/toAst/number.ts @@ -1,8 +1,12 @@ import type { SchemaWithType } from '~/plugins'; +import { + maybeBigInt, + shouldCoerceToBigInt, +} from '~/plugins/shared/utils/coerce'; +import { getIntegerLimit } from '~/plugins/shared/utils/formats'; import { $ } from '~/ts-dsl'; import { identifiers } from '../../constants'; -import { numberParameter } from '../../shared/numbers'; import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; export const numberToAst = ({ @@ -11,44 +15,63 @@ export const numberToAst = ({ }: IrSchemaToAstOptions & { schema: SchemaWithType<'integer' | 'number'>; }): Omit => { + const result: Partial> = {}; + const z = plugin.referenceSymbol({ category: 'external', resource: 'zod.z', }); - const result: Partial> = {}; - - const isBigInt = schema.type === 'integer' && schema.format === 'int64'; - - if (typeof schema.const === 'number') { - // TODO: parser - handle bigint constants + if (schema.const !== undefined) { result.expression = $(z) .attr(identifiers.literal) - .call($.literal(schema.const)); + .call(maybeBigInt(schema.const, schema.format)); return result as Omit; } - result.expression = isBigInt - ? $(z).attr(identifiers.coerce).attr(identifiers.bigint).call() - : $(z).attr(identifiers.number).call(); - - if (!isBigInt && schema.type === 'integer') { - result.expression = $(z).attr(identifiers.int).call(); + if (shouldCoerceToBigInt(schema.format)) { + result.expression = $(z) + .attr(identifiers.coerce) + .attr(identifiers.bigint) + .call(); + } else { + result.expression = $(z).attr(identifiers.number).call(); + if (schema.type === 'integer') { + result.expression = $(z).attr(identifiers.int).call(); + } } const checks: Array> = []; + const integerLimit = getIntegerLimit(schema.format); + if (integerLimit) { + checks.push( + $(z) + .attr(identifiers.minimum) + .call( + maybeBigInt(integerLimit.minValue, schema.format), + $.object().prop('error', $.literal(integerLimit.minError)), + ), + $(z) + .attr(identifiers.maximum) + .call( + maybeBigInt(integerLimit.maxValue, schema.format), + $.object().prop('error', $.literal(integerLimit.maxError)), + ), + ); + } + if (schema.exclusiveMinimum !== undefined) { checks.push( $(z) .attr(identifiers.gt) - .call(numberParameter({ isBigInt, value: schema.exclusiveMinimum })), + .call(maybeBigInt(schema.exclusiveMinimum, schema.format)), ); } else if (schema.minimum !== undefined) { checks.push( $(z) .attr(identifiers.gte) - .call(numberParameter({ isBigInt, value: schema.minimum })), + .call(maybeBigInt(schema.minimum, schema.format)), ); } @@ -56,13 +79,13 @@ export const numberToAst = ({ checks.push( $(z) .attr(identifiers.lt) - .call(numberParameter({ isBigInt, value: schema.exclusiveMaximum })), + .call(maybeBigInt(schema.exclusiveMaximum, schema.format)), ); } else if (schema.maximum !== undefined) { checks.push( $(z) .attr(identifiers.lte) - .call(numberParameter({ isBigInt, value: schema.maximum })), + .call(maybeBigInt(schema.maximum, schema.format)), ); } diff --git a/packages/openapi-ts/src/plugins/zod/shared/numbers.ts b/packages/openapi-ts/src/plugins/zod/shared/numbers.ts deleted file mode 100644 index 5667521bc..000000000 --- a/packages/openapi-ts/src/plugins/zod/shared/numbers.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { $ } from '~/ts-dsl'; - -export const numberParameter = ({ - isBigInt, - value, -}: { - isBigInt: boolean; - value: unknown; -}): ReturnType => { - const expr = $.fromValue(value); - - if ( - isBigInt && - (typeof value === 'bigint' || - typeof value === 'number' || - typeof value === 'string' || - typeof value === 'boolean') - ) { - return $('BigInt').call(expr); - } - - return expr; -}; diff --git a/packages/openapi-ts/src/plugins/zod/types.d.ts b/packages/openapi-ts/src/plugins/zod/types.d.ts index 9038967a2..28baeb3d5 100644 --- a/packages/openapi-ts/src/plugins/zod/types.d.ts +++ b/packages/openapi-ts/src/plugins/zod/types.d.ts @@ -782,6 +782,29 @@ type ValidatorResolver = ( ) => MaybeArray> | null | undefined; type Resolvers = Plugin.Resolvers<{ + /** + * Resolvers for number schemas. + * + * Allows customization of how number types are rendered, including + * per-format handling. + */ + number?: { + /** + * Resolvers for number formats (e.g., `float`, `double`, `int32`). + * + * Each key represents a specific format name with a custom + * resolver function that controls how that format is rendered. + * + * Example path: `~resolvers.number.formats.float` + * + * Returning `undefined` from a resolver will apply the default + * generation behavior for that format. + */ + formats?: Record< + string, + (args: FormatResolverArgs) => boolean | number | undefined + >; + }; /** * Resolvers for object schemas. * diff --git a/packages/openapi-ts/src/plugins/zod/v3/plugin.ts b/packages/openapi-ts/src/plugins/zod/v3/plugin.ts index 6eedd716c..e9eae2eaa 100644 --- a/packages/openapi-ts/src/plugins/zod/v3/plugin.ts +++ b/packages/openapi-ts/src/plugins/zod/v3/plugin.ts @@ -5,13 +5,13 @@ import { deduplicateSchema } from '~/ir/schema'; import type { IR } from '~/ir/types'; import { buildName } from '~/openApi/shared/utils/name'; import type { SchemaWithType } from '~/plugins'; +import { maybeBigInt } from '~/plugins/shared/utils/coerce'; import { $ } from '~/ts-dsl'; import { pathToJsonPointer, refToName } from '~/utils/ref'; import { identifiers } from '../constants'; import { exportAst } from '../shared/export'; import { getZodModule } from '../shared/module'; -import { numberParameter } from '../shared/numbers'; import { irOperationToAst } from '../shared/operation'; import type { Ast, IrSchemaToAstOptions, PluginState } from '../shared/types'; import { irWebhookToAst } from '../shared/webhook'; @@ -139,13 +139,13 @@ export const irSchemaToAst = ({ } if (schema.default !== undefined) { - const isBigInt = schema.type === 'integer' && schema.format === 'int64'; - ast.expression = ast.expression.attr(identifiers.default).call( - numberParameter({ - isBigInt, - value: schema.default, - }), - ); + ast.expression = ast.expression + .attr(identifiers.default) + .call( + schema.type === 'integer' || schema.type === 'number' + ? maybeBigInt(schema.default, schema.format) + : $.fromValue(schema.default), + ); } } diff --git a/packages/openapi-ts/src/plugins/zod/v3/toAst/index.ts b/packages/openapi-ts/src/plugins/zod/v3/toAst/index.ts index eb8294b5a..ed20025aa 100644 --- a/packages/openapi-ts/src/plugins/zod/v3/toAst/index.ts +++ b/packages/openapi-ts/src/plugins/zod/v3/toAst/index.ts @@ -1,4 +1,5 @@ import type { SchemaWithType } from '~/plugins'; +import { shouldCoerceToBigInt } from '~/plugins/shared/utils/coerce'; import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; import { arrayToAst } from './array'; @@ -71,10 +72,15 @@ export const irSchemaWithTypeToAst = ({ }); case 'string': return { - expression: stringToAst({ - ...args, - schema: schema as SchemaWithType<'string'>, - }), + expression: shouldCoerceToBigInt(schema.format) + ? numberToAst({ + ...args, + schema: { ...schema, type: 'number' }, + }) + : stringToAst({ + ...args, + schema: schema as SchemaWithType<'string'>, + }), }; case 'tuple': return tupleToAst({ diff --git a/packages/openapi-ts/src/plugins/zod/v3/toAst/number.ts b/packages/openapi-ts/src/plugins/zod/v3/toAst/number.ts index 1e9bb5198..990003b43 100644 --- a/packages/openapi-ts/src/plugins/zod/v3/toAst/number.ts +++ b/packages/openapi-ts/src/plugins/zod/v3/toAst/number.ts @@ -1,8 +1,12 @@ import type { SchemaWithType } from '~/plugins'; +import { + maybeBigInt, + shouldCoerceToBigInt, +} from '~/plugins/shared/utils/coerce'; +import { getIntegerLimit } from '~/plugins/shared/utils/formats'; import { $ } from '~/ts-dsl'; import { identifiers } from '../../constants'; -import { numberParameter } from '../../shared/numbers'; import type { IrSchemaToAstOptions } from '../../shared/types'; export const numberToAst = ({ @@ -16,42 +20,60 @@ export const numberToAst = ({ resource: 'zod.z', }); - const isBigInt = schema.type === 'integer' && schema.format === 'int64'; - - if (typeof schema.const === 'number') { - // TODO: parser - handle bigint constants + if (schema.const !== undefined) { const expression = $(z) .attr(identifiers.literal) - .call($.literal(schema.const)); + .call(maybeBigInt(schema.const, schema.format)); return expression; } - let numberExpression = isBigInt - ? $(z).attr(identifiers.coerce).attr(identifiers.bigint).call() - : $(z).attr(identifiers.number).call(); + let numberExpression: ReturnType; + + if (shouldCoerceToBigInt(schema.format)) { + numberExpression = $(z) + .attr(identifiers.coerce) + .attr(identifiers.bigint) + .call(); + } else { + numberExpression = $(z).attr(identifiers.number).call(); + if (schema.type === 'integer') { + numberExpression = numberExpression.attr(identifiers.int).call(); + } + } - if (!isBigInt && schema.type === 'integer') { - numberExpression = numberExpression.attr(identifiers.int).call(); + const integerLimit = getIntegerLimit(schema.format); + if (integerLimit) { + numberExpression = numberExpression + .attr(identifiers.min) + .call( + maybeBigInt(integerLimit.minValue, schema.format), + $.object().prop('message', $.literal(integerLimit.minError)), + ) + .attr(identifiers.max) + .call( + maybeBigInt(integerLimit.maxValue, schema.format), + $.object().prop('message', $.literal(integerLimit.maxError)), + ); } if (schema.exclusiveMinimum !== undefined) { numberExpression = numberExpression .attr(identifiers.gt) - .call(numberParameter({ isBigInt, value: schema.exclusiveMinimum })); + .call(maybeBigInt(schema.exclusiveMinimum, schema.format)); } else if (schema.minimum !== undefined) { numberExpression = numberExpression .attr(identifiers.gte) - .call(numberParameter({ isBigInt, value: schema.minimum })); + .call(maybeBigInt(schema.minimum, schema.format)); } if (schema.exclusiveMaximum !== undefined) { numberExpression = numberExpression .attr(identifiers.lt) - .call(numberParameter({ isBigInt, value: schema.exclusiveMaximum })); + .call(maybeBigInt(schema.exclusiveMaximum, schema.format)); } else if (schema.maximum !== undefined) { numberExpression = numberExpression .attr(identifiers.lte) - .call(numberParameter({ isBigInt, value: schema.maximum })); + .call(maybeBigInt(schema.maximum, schema.format)); } return numberExpression; diff --git a/packages/openapi-ts/src/plugins/zod/v4/plugin.ts b/packages/openapi-ts/src/plugins/zod/v4/plugin.ts index e7afa63ad..be71113d6 100644 --- a/packages/openapi-ts/src/plugins/zod/v4/plugin.ts +++ b/packages/openapi-ts/src/plugins/zod/v4/plugin.ts @@ -5,13 +5,13 @@ import { deduplicateSchema } from '~/ir/schema'; import type { IR } from '~/ir/types'; import { buildName } from '~/openApi/shared/utils/name'; import type { SchemaWithType } from '~/plugins'; +import { maybeBigInt } from '~/plugins/shared/utils/coerce'; import { $ } from '~/ts-dsl'; import { pathToJsonPointer, refToName } from '~/utils/ref'; import { identifiers } from '../constants'; import { exportAst } from '../shared/export'; import { getZodModule } from '../shared/module'; -import { numberParameter } from '../shared/numbers'; import { irOperationToAst } from '../shared/operation'; import type { Ast, IrSchemaToAstOptions, PluginState } from '../shared/types'; import { irWebhookToAst } from '../shared/webhook'; @@ -155,13 +155,13 @@ export const irSchemaToAst = ({ } if (schema.default !== undefined) { - const isBigInt = schema.type === 'integer' && schema.format === 'int64'; - ast.expression = ast.expression.attr(identifiers.default).call( - numberParameter({ - isBigInt, - value: schema.default, - }), - ); + ast.expression = ast.expression + .attr(identifiers.default) + .call( + schema.type === 'integer' || schema.type === 'number' + ? maybeBigInt(schema.default, schema.format) + : $.fromValue(schema.default), + ); } } diff --git a/packages/openapi-ts/src/plugins/zod/v4/toAst/index.ts b/packages/openapi-ts/src/plugins/zod/v4/toAst/index.ts index 8c2a5848e..c7459e181 100644 --- a/packages/openapi-ts/src/plugins/zod/v4/toAst/index.ts +++ b/packages/openapi-ts/src/plugins/zod/v4/toAst/index.ts @@ -1,4 +1,5 @@ import type { SchemaWithType } from '~/plugins'; +import { shouldCoerceToBigInt } from '~/plugins/shared/utils/coerce'; import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; import { arrayToAst } from './array'; @@ -58,10 +59,15 @@ export const irSchemaWithTypeToAst = ({ schema: schema as SchemaWithType<'object'>, }); case 'string': - return stringToAst({ - ...args, - schema: schema as SchemaWithType<'string'>, - }); + return shouldCoerceToBigInt(schema.format) + ? numberToAst({ + ...args, + schema: { ...schema, type: 'number' }, + }) + : stringToAst({ + ...args, + schema: schema as SchemaWithType<'string'>, + }); case 'tuple': return tupleToAst({ ...args, diff --git a/packages/openapi-ts/src/plugins/zod/v4/toAst/number.ts b/packages/openapi-ts/src/plugins/zod/v4/toAst/number.ts index 0ff204b32..0d6c50054 100644 --- a/packages/openapi-ts/src/plugins/zod/v4/toAst/number.ts +++ b/packages/openapi-ts/src/plugins/zod/v4/toAst/number.ts @@ -1,8 +1,12 @@ import type { SchemaWithType } from '~/plugins'; +import { + maybeBigInt, + shouldCoerceToBigInt, +} from '~/plugins/shared/utils/coerce'; +import { getIntegerLimit } from '~/plugins/shared/utils/formats'; import { $ } from '~/ts-dsl'; import { identifiers } from '../../constants'; -import { numberParameter } from '../../shared/numbers'; import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; export const numberToAst = ({ @@ -13,47 +17,63 @@ export const numberToAst = ({ }): Omit => { const result: Partial> = {}; - const isBigInt = schema.type === 'integer' && schema.format === 'int64'; - const z = plugin.referenceSymbol({ category: 'external', resource: 'zod.z', }); - if (typeof schema.const === 'number') { - // TODO: parser - handle bigint constants + if (schema.const !== undefined) { result.expression = $(z) .attr(identifiers.literal) - .call($.literal(schema.const)); + .call(maybeBigInt(schema.const, schema.format)); return result as Omit; } - result.expression = isBigInt - ? $(z).attr(identifiers.coerce).attr(identifiers.bigint).call() - : $(z).attr(identifiers.number).call(); + if (shouldCoerceToBigInt(schema.format)) { + result.expression = $(z) + .attr(identifiers.coerce) + .attr(identifiers.bigint) + .call(); + } else { + result.expression = $(z).attr(identifiers.number).call(); + if (schema.type === 'integer') { + result.expression = $(z).attr(identifiers.int).call(); + } + } - if (!isBigInt && schema.type === 'integer') { - result.expression = $(z).attr(identifiers.int).call(); + const integerLimit = getIntegerLimit(schema.format); + if (integerLimit) { + result.expression = result.expression + .attr(identifiers.min) + .call( + maybeBigInt(integerLimit.minValue, schema.format), + $.object().prop('error', $.literal(integerLimit.minError)), + ) + .attr(identifiers.max) + .call( + maybeBigInt(integerLimit.maxValue, schema.format), + $.object().prop('error', $.literal(integerLimit.maxError)), + ); } if (schema.exclusiveMinimum !== undefined) { result.expression = result.expression .attr(identifiers.gt) - .call(numberParameter({ isBigInt, value: schema.exclusiveMinimum })); + .call(maybeBigInt(schema.exclusiveMinimum, schema.format)); } else if (schema.minimum !== undefined) { result.expression = result.expression .attr(identifiers.gte) - .call(numberParameter({ isBigInt, value: schema.minimum })); + .call(maybeBigInt(schema.minimum, schema.format)); } if (schema.exclusiveMaximum !== undefined) { result.expression = result.expression .attr(identifiers.lt) - .call(numberParameter({ isBigInt, value: schema.exclusiveMaximum })); + .call(maybeBigInt(schema.exclusiveMaximum, schema.format)); } else if (schema.maximum !== undefined) { result.expression = result.expression .attr(identifiers.lte) - .call(numberParameter({ isBigInt, value: schema.maximum })); + .call(maybeBigInt(schema.maximum, schema.format)); } return result as Omit; diff --git a/packages/openapi-ts/src/ts-dsl/expr/fromValue.ts b/packages/openapi-ts/src/ts-dsl/expr/fromValue.ts index 6afc3d68d..663f5541c 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/fromValue.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/fromValue.ts @@ -16,14 +16,12 @@ export const fromValue = ( return input as TsDsl; } - if (input === null) { - return new LiteralTsDsl(input); - } - if ( + input === null || typeof input === 'number' || typeof input === 'boolean' || - typeof input === 'string' + typeof input === 'string' || + typeof input === 'bigint' ) { return new LiteralTsDsl(input); } diff --git a/packages/openapi-ts/src/ts-dsl/expr/literal.ts b/packages/openapi-ts/src/ts-dsl/expr/literal.ts index 68199b449..6bf8122eb 100644 --- a/packages/openapi-ts/src/ts-dsl/expr/literal.ts +++ b/packages/openapi-ts/src/ts-dsl/expr/literal.ts @@ -5,14 +5,16 @@ import { TsDsl } from '../base'; import { PrefixTsDsl } from '../expr/prefix'; import { AsMixin } from '../mixins/as'; +export type LiteralValue = string | number | boolean | bigint | null; + const Mixed = AsMixin(TsDsl); export class LiteralTsDsl extends Mixed { readonly '~dsl' = 'LiteralTsDsl'; - protected value: string | number | boolean | null; + protected value: LiteralValue; - constructor(value: string | number | boolean | null) { + constructor(value: LiteralValue) { super(); this.value = value; } @@ -34,6 +36,9 @@ export class LiteralTsDsl extends Mixed { if (typeof this.value === 'string') { return ts.factory.createStringLiteral(this.value, true); } + if (typeof this.value === 'bigint') { + return ts.factory.createBigIntLiteral(this.value.toString()); + } if (this.value === null) { return ts.factory.createNull(); } diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/spec/objectAdditionalProperties/additional-properties.yaml b/specs/3.1.x/additional-properties.yaml similarity index 69% rename from packages/openapi-ts-tests/main/test/plugins/valibot/spec/objectAdditionalProperties/additional-properties.yaml rename to specs/3.1.x/additional-properties.yaml index 6698c4f84..ebfd4ecc2 100644 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/spec/objectAdditionalProperties/additional-properties.yaml +++ b/specs/3.1.x/additional-properties.yaml @@ -1,11 +1,9 @@ -openapi: '3.1.0' +openapi: 3.1.0 info: - title: Object Additional Properties Test API - version: '1.0.0' -paths: {} + title: OpenAPI 3.1.0 additional properties example + version: '1' components: schemas: - # Test case from the issue: object with additionalProperties type string ObjectWithAdditionalPropertiesString: type: object properties: @@ -13,26 +11,18 @@ components: type: object additionalProperties: type: string - - # Object with no properties, only additionalProperties with string type ObjectOnlyAdditionalPropertiesString: type: object additionalProperties: type: string - - # Object with no properties, only additionalProperties with number type ObjectOnlyAdditionalPropertiesNumber: type: object additionalProperties: type: number - - # Object with no properties, only additionalProperties with boolean type ObjectOnlyAdditionalPropertiesBoolean: type: object additionalProperties: type: boolean - - # Object with properties and additionalProperties number ObjectWithPropertiesAndAdditionalPropertiesNumber: type: object properties: @@ -42,8 +32,6 @@ components: type: integer additionalProperties: type: number - - # Object with additionalProperties as object type ObjectWithAdditionalPropertiesObject: type: object properties: @@ -54,8 +42,6 @@ components: properties: value: type: string - - # Already working case: object with no properties and additionalProperties object ObjectOnlyAdditionalPropertiesObject: type: object additionalProperties: @@ -63,8 +49,6 @@ components: properties: name: type: string - - # Object with additionalProperties set to false (no additional properties allowed) ObjectWithAdditionalPropertiesFalse: type: object properties: @@ -73,8 +57,6 @@ components: count: type: integer additionalProperties: false - - # Object with nested object that has additionalProperties: false ObjectWithNestedAdditionalPropertiesFalse: type: object properties: diff --git a/specs/3.1.x/array-items-all-of.yaml b/specs/3.1.x/array-items-all-of.yaml index fc70640fd..a47244e4a 100644 --- a/specs/3.1.x/array-items-all-of.yaml +++ b/specs/3.1.x/array-items-all-of.yaml @@ -4,7 +4,6 @@ info: version: '1' components: schemas: - # Test case 1: Array with allOf of object schemas ArrayWithAllOfObjects: type: array items: @@ -17,14 +16,12 @@ components: properties: name: type: string - # Test case 2: Array with allOf of primitives ArrayWithAllOfPrimitives: type: array items: allOf: - type: number - type: string - # Test case 3: Array with allOf including refs ArrayWithAllOfRefs: type: array items: diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/const-values.yaml b/specs/3.1.x/const-values.yaml similarity index 95% rename from packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/const-values.yaml rename to specs/3.1.x/const-values.yaml index 31fef4d21..1e7331a81 100644 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/const-values.yaml +++ b/specs/3.1.x/const-values.yaml @@ -1,8 +1,7 @@ -openapi: '3.1.0' +openapi: 3.1.0 info: - title: Number Type Const Values Test API - version: '1.0.0' -paths: {} + title: OpenAPI 3.1.0 const values example + version: '1' components: schemas: NumberNoFormat: diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/formats.yaml b/specs/3.1.x/formats.yaml similarity index 94% rename from packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/formats.yaml rename to specs/3.1.x/formats.yaml index 8fc26a6f4..f9d124a84 100644 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/formats.yaml +++ b/specs/3.1.x/formats.yaml @@ -1,7 +1,7 @@ -openapi: '3.1.0' +openapi: 3.1.0 info: - title: Integer Formats Test - version: '1.0.0' + title: OpenAPI 3.1.0 formats example + version: '1' components: schemas: NumberNoFormat: diff --git a/packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/min-max-constraints.yaml b/specs/3.1.x/min-max-constraints.yaml similarity index 97% rename from packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/min-max-constraints.yaml rename to specs/3.1.x/min-max-constraints.yaml index be4c35945..e0f9ad55f 100644 --- a/packages/openapi-ts-tests/main/test/plugins/valibot/spec/numberTypeToValibotSchema/min-max-constraints.yaml +++ b/specs/3.1.x/min-max-constraints.yaml @@ -1,8 +1,7 @@ -openapi: '3.1.0' +openapi: 3.1.0 info: - title: Number Type Min/Max Constraints Test API - version: '1.0.0' -paths: {} + title: OpenAPI 3.1.0 min max constraints example + version: '1' components: schemas: NumberWithMinimum: