From 6aa9110995402597dbda94805bd175234980eb49 Mon Sep 17 00:00:00 2001 From: soartec-lab Date: Fri, 27 Dec 2024 01:34:41 +0000 Subject: [PATCH] chore: regenerate sample apps --- .../next-app/app/gen/pets/pets.ts | 4 + .../form-data-mutator/endpoints.ts | 99 +++++++------------ .../form-data-mutator/models/pet.ts | 20 ++-- samples/react-query/form-data/endpoints.ts | 99 +++++++------------ samples/react-query/form-data/models/pet.ts | 20 ++-- .../form-url-encoded-mutator/endpoints.ts | 99 +++++++------------ .../form-url-encoded-mutator/models/pet.ts | 20 ++-- .../react-query/form-url-encoded/endpoints.ts | 99 +++++++------------ .../form-url-encoded/models/pet.ts | 20 ++-- samples/react-query/hook-mutator/endpoints.ts | 99 +++++++------------ .../react-query/hook-mutator/models/pet.ts | 20 ++-- 11 files changed, 219 insertions(+), 380 deletions(-) diff --git a/samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts b/samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts index b152d7ea1..a5ce38504 100644 --- a/samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts +++ b/samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts @@ -42,6 +42,7 @@ export const listPets = async ( ...options, method: 'GET', }); + const data = await res.json(); return { status: res.status, data, headers: res.headers }; @@ -70,6 +71,7 @@ export const createPets = async ( headers: { 'Content-Type': 'application/json', ...options?.headers }, body: JSON.stringify(createPetsBodyItem), }); + const data = await res.json(); return { status: res.status, data, headers: res.headers }; @@ -98,6 +100,7 @@ export const updatePets = async ( headers: { 'Content-Type': 'application/json', ...options?.headers }, body: JSON.stringify(pet), }); + const data = await res.json(); return { status: res.status, data, headers: res.headers }; @@ -124,6 +127,7 @@ export const showPetById = async ( ...options, method: 'GET', }); + const data = await res.json(); return { status: res.status, data, headers: res.headers }; diff --git a/samples/react-query/form-data-mutator/endpoints.ts b/samples/react-query/form-data-mutator/endpoints.ts index 66ab52930..de65cf0cc 100644 --- a/samples/react-query/form-data-mutator/endpoints.ts +++ b/samples/react-query/form-data-mutator/endpoints.ts @@ -50,13 +50,7 @@ export const getListPetsQueryOptions = < TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -67,7 +61,7 @@ export const getListPetsQueryOptions = < }) => listPets(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -87,13 +81,7 @@ export function useListPets< TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsQueryOptions(params, options); @@ -123,22 +111,25 @@ export const createPets = ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationOptions< - Awaited>, - TError, - { data: CreatePetsBody }, - TContext -> => { - const { mutation: mutationOptions } = options ?? {}; +}) => { + const mutationKey = ['createPets']; + const { mutation: mutationOptions } = options + ? options.mutation && + 'mutationKey' in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey } }; const mutationFn: MutationFunction< Awaited>, @@ -149,7 +140,12 @@ export const getCreatePetsMutationOptions = < return createPets(data); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBody }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -161,19 +157,18 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const useCreatePets = (options?: { +export const useCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationResult< - Awaited>, - TError, - { data: CreatePetsBody }, - TContext -> => { +}): UseMutationResult => { const mutationOptions = getCreatePetsMutationOptions(options); return useMutation(mutationOptions); @@ -205,13 +200,7 @@ export const getListPetsNestedArrayQueryOptions = < TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -223,7 +212,7 @@ export const getListPetsNestedArrayQueryOptions = < > = ({ signal }) => listPetsNestedArray(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -243,13 +232,7 @@ export function useListPetsNestedArray< TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsNestedArrayQueryOptions(params, options); @@ -278,13 +261,7 @@ export const getShowPetByIdQueryOptions = < TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -299,11 +276,7 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: !!petId, ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: QueryKey }; + } as UseQueryOptions & { queryKey: QueryKey }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -320,13 +293,7 @@ export function useShowPetById< TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getShowPetByIdQueryOptions(petId, options); diff --git a/samples/react-query/form-data-mutator/models/pet.ts b/samples/react-query/form-data-mutator/models/pet.ts index 80f8d0a2b..15f469683 100644 --- a/samples/react-query/form-data-mutator/models/pet.ts +++ b/samples/react-query/form-data-mutator/models/pet.ts @@ -8,16 +8,6 @@ import type { PetCallingCode } from './petCallingCode'; import type { PetCountry } from './petCountry'; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -25,9 +15,19 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; } diff --git a/samples/react-query/form-data/endpoints.ts b/samples/react-query/form-data/endpoints.ts index 66ab52930..de65cf0cc 100644 --- a/samples/react-query/form-data/endpoints.ts +++ b/samples/react-query/form-data/endpoints.ts @@ -50,13 +50,7 @@ export const getListPetsQueryOptions = < TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -67,7 +61,7 @@ export const getListPetsQueryOptions = < }) => listPets(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -87,13 +81,7 @@ export function useListPets< TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsQueryOptions(params, options); @@ -123,22 +111,25 @@ export const createPets = ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationOptions< - Awaited>, - TError, - { data: CreatePetsBody }, - TContext -> => { - const { mutation: mutationOptions } = options ?? {}; +}) => { + const mutationKey = ['createPets']; + const { mutation: mutationOptions } = options + ? options.mutation && + 'mutationKey' in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey } }; const mutationFn: MutationFunction< Awaited>, @@ -149,7 +140,12 @@ export const getCreatePetsMutationOptions = < return createPets(data); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBody }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -161,19 +157,18 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const useCreatePets = (options?: { +export const useCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationResult< - Awaited>, - TError, - { data: CreatePetsBody }, - TContext -> => { +}): UseMutationResult => { const mutationOptions = getCreatePetsMutationOptions(options); return useMutation(mutationOptions); @@ -205,13 +200,7 @@ export const getListPetsNestedArrayQueryOptions = < TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -223,7 +212,7 @@ export const getListPetsNestedArrayQueryOptions = < > = ({ signal }) => listPetsNestedArray(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -243,13 +232,7 @@ export function useListPetsNestedArray< TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsNestedArrayQueryOptions(params, options); @@ -278,13 +261,7 @@ export const getShowPetByIdQueryOptions = < TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -299,11 +276,7 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: !!petId, ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: QueryKey }; + } as UseQueryOptions & { queryKey: QueryKey }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -320,13 +293,7 @@ export function useShowPetById< TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getShowPetByIdQueryOptions(petId, options); diff --git a/samples/react-query/form-data/models/pet.ts b/samples/react-query/form-data/models/pet.ts index 80f8d0a2b..15f469683 100644 --- a/samples/react-query/form-data/models/pet.ts +++ b/samples/react-query/form-data/models/pet.ts @@ -8,16 +8,6 @@ import type { PetCallingCode } from './petCallingCode'; import type { PetCountry } from './petCountry'; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -25,9 +15,19 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; } diff --git a/samples/react-query/form-url-encoded-mutator/endpoints.ts b/samples/react-query/form-url-encoded-mutator/endpoints.ts index 66c683524..c1d25a988 100644 --- a/samples/react-query/form-url-encoded-mutator/endpoints.ts +++ b/samples/react-query/form-url-encoded-mutator/endpoints.ts @@ -51,13 +51,7 @@ export const getListPetsQueryOptions = < TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -68,7 +62,7 @@ export const getListPetsQueryOptions = < }) => listPets(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -88,13 +82,7 @@ export function useListPets< TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsQueryOptions(params, options); @@ -124,22 +112,25 @@ export const createPets = ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationOptions< - Awaited>, - TError, - { data: CreatePetsBody }, - TContext -> => { - const { mutation: mutationOptions } = options ?? {}; +}) => { + const mutationKey = ['createPets']; + const { mutation: mutationOptions } = options + ? options.mutation && + 'mutationKey' in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey } }; const mutationFn: MutationFunction< Awaited>, @@ -150,7 +141,12 @@ export const getCreatePetsMutationOptions = < return createPets(data); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBody }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -162,19 +158,18 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const useCreatePets = (options?: { +export const useCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationResult< - Awaited>, - TError, - { data: CreatePetsBody }, - TContext -> => { +}): UseMutationResult => { const mutationOptions = getCreatePetsMutationOptions(options); return useMutation(mutationOptions); @@ -206,13 +201,7 @@ export const getListPetsNestedArrayQueryOptions = < TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -224,7 +213,7 @@ export const getListPetsNestedArrayQueryOptions = < > = ({ signal }) => listPetsNestedArray(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -244,13 +233,7 @@ export function useListPetsNestedArray< TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsNestedArrayQueryOptions(params, options); @@ -279,13 +262,7 @@ export const getShowPetByIdQueryOptions = < TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -300,11 +277,7 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: !!petId, ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: QueryKey }; + } as UseQueryOptions & { queryKey: QueryKey }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -321,13 +294,7 @@ export function useShowPetById< TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getShowPetByIdQueryOptions(petId, options); diff --git a/samples/react-query/form-url-encoded-mutator/models/pet.ts b/samples/react-query/form-url-encoded-mutator/models/pet.ts index 80f8d0a2b..15f469683 100644 --- a/samples/react-query/form-url-encoded-mutator/models/pet.ts +++ b/samples/react-query/form-url-encoded-mutator/models/pet.ts @@ -8,16 +8,6 @@ import type { PetCallingCode } from './petCallingCode'; import type { PetCountry } from './petCountry'; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -25,9 +15,19 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; } diff --git a/samples/react-query/form-url-encoded/endpoints.ts b/samples/react-query/form-url-encoded/endpoints.ts index 66ab52930..de65cf0cc 100644 --- a/samples/react-query/form-url-encoded/endpoints.ts +++ b/samples/react-query/form-url-encoded/endpoints.ts @@ -50,13 +50,7 @@ export const getListPetsQueryOptions = < TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -67,7 +61,7 @@ export const getListPetsQueryOptions = < }) => listPets(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -87,13 +81,7 @@ export function useListPets< TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsQueryOptions(params, options); @@ -123,22 +111,25 @@ export const createPets = ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationOptions< - Awaited>, - TError, - { data: CreatePetsBody }, - TContext -> => { - const { mutation: mutationOptions } = options ?? {}; +}) => { + const mutationKey = ['createPets']; + const { mutation: mutationOptions } = options + ? options.mutation && + 'mutationKey' in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey } }; const mutationFn: MutationFunction< Awaited>, @@ -149,7 +140,12 @@ export const getCreatePetsMutationOptions = < return createPets(data); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBody }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -161,19 +157,18 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const useCreatePets = (options?: { +export const useCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationResult< - Awaited>, - TError, - { data: CreatePetsBody }, - TContext -> => { +}): UseMutationResult => { const mutationOptions = getCreatePetsMutationOptions(options); return useMutation(mutationOptions); @@ -205,13 +200,7 @@ export const getListPetsNestedArrayQueryOptions = < TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -223,7 +212,7 @@ export const getListPetsNestedArrayQueryOptions = < > = ({ signal }) => listPetsNestedArray(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -243,13 +232,7 @@ export function useListPetsNestedArray< TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsNestedArrayQueryOptions(params, options); @@ -278,13 +261,7 @@ export const getShowPetByIdQueryOptions = < TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -299,11 +276,7 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: !!petId, ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: QueryKey }; + } as UseQueryOptions & { queryKey: QueryKey }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -320,13 +293,7 @@ export function useShowPetById< TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = getShowPetByIdQueryOptions(petId, options); diff --git a/samples/react-query/form-url-encoded/models/pet.ts b/samples/react-query/form-url-encoded/models/pet.ts index 80f8d0a2b..15f469683 100644 --- a/samples/react-query/form-url-encoded/models/pet.ts +++ b/samples/react-query/form-url-encoded/models/pet.ts @@ -8,16 +8,6 @@ import type { PetCallingCode } from './petCallingCode'; import type { PetCountry } from './petCountry'; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -25,9 +15,19 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; } diff --git a/samples/react-query/hook-mutator/endpoints.ts b/samples/react-query/hook-mutator/endpoints.ts index 79cde0bf1..dcbe771ef 100644 --- a/samples/react-query/hook-mutator/endpoints.ts +++ b/samples/react-query/hook-mutator/endpoints.ts @@ -53,13 +53,7 @@ export const useListPetsQueryOptions = < TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -72,7 +66,7 @@ export const useListPetsQueryOptions = < > = ({ signal }) => listPets(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -92,13 +86,7 @@ export function useListPets< TError = Error, >( params?: ListPetsParams, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = useListPetsQueryOptions(params, options); @@ -132,22 +120,25 @@ export const useCreatePetsHook = () => { }; export const useCreatePetsMutationOptions = < + TData = Awaited>>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationOptions< - Awaited>>, - TError, - { data: CreatePetsBody }, - TContext -> => { - const { mutation: mutationOptions } = options ?? {}; +}) => { + const mutationKey = ['createPets']; + const { mutation: mutationOptions } = options + ? options.mutation && + 'mutationKey' in options.mutation && + options.mutation.mutationKey + ? options + : { ...options, mutation: { ...options.mutation, mutationKey } } + : { mutation: { mutationKey } }; const createPets = useCreatePetsHook(); @@ -160,7 +151,12 @@ export const useCreatePetsMutationOptions = < return createPets(data); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBody }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -172,19 +168,18 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const useCreatePets = (options?: { +export const useCreatePets = < + TData = Awaited>>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>>, + TData, TError, { data: CreatePetsBody }, TContext >; -}): UseMutationResult< - Awaited>>, - TError, - { data: CreatePetsBody }, - TContext -> => { +}): UseMutationResult => { const mutationOptions = useCreatePetsMutationOptions(options); return useMutation(mutationOptions); @@ -220,13 +215,7 @@ export const useListPetsNestedArrayQueryOptions = < TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -240,7 +229,7 @@ export const useListPetsNestedArrayQueryOptions = < > = ({ signal }) => listPetsNestedArray(params, signal); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -260,13 +249,7 @@ export function useListPetsNestedArray< TError = Error, >( params?: ListPetsNestedArrayParams, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = useListPetsNestedArrayQueryOptions(params, options); @@ -302,13 +285,7 @@ export const useShowPetByIdQueryOptions = < TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -325,11 +302,7 @@ export const useShowPetByIdQueryOptions = < queryFn, enabled: !!petId, ...queryOptions, - } as UseQueryOptions< - Awaited>>, - TError, - TData - > & { queryKey: QueryKey }; + } as UseQueryOptions & { queryKey: QueryKey }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -346,13 +319,7 @@ export function useShowPetById< TError = Error, >( petId: string, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = useShowPetByIdQueryOptions(petId, options); diff --git a/samples/react-query/hook-mutator/models/pet.ts b/samples/react-query/hook-mutator/models/pet.ts index 80f8d0a2b..15f469683 100644 --- a/samples/react-query/hook-mutator/models/pet.ts +++ b/samples/react-query/hook-mutator/models/pet.ts @@ -8,16 +8,6 @@ import type { PetCallingCode } from './petCallingCode'; import type { PetCountry } from './petCountry'; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -25,9 +15,19 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }