diff --git a/packages/react/src/shared/ReactTemplate.tsx b/packages/react/src/shared/ReactTemplate.tsx index 1f6d4be23..3ac11a964 100644 --- a/packages/react/src/shared/ReactTemplate.tsx +++ b/packages/react/src/shared/ReactTemplate.tsx @@ -106,6 +106,9 @@ export class ReactTemplate { this.#lastFiles = files } onError(error: Error): void { + if (process.env.NODE_ENV === 'test') { + console.error(error) + } if (!this.logger) { console.error(error) } diff --git a/packages/swagger-tanstack-query/src/OperationGenerator.test.tsx b/packages/swagger-tanstack-query/src/OperationGenerator.test.tsx index 9fbf8f2cb..c6482d668 100644 --- a/packages/swagger-tanstack-query/src/OperationGenerator.test.tsx +++ b/packages/swagger-tanstack-query/src/OperationGenerator.test.tsx @@ -1,4 +1,3 @@ -import { FileManager } from '@kubb/core' import { mockedPluginManager } from '@kubb/core/mocks' import { OasManager } from '@kubb/swagger' @@ -8,8 +7,7 @@ import { QueryKey } from './components/QueryKey.tsx' import { QueryOptions } from './components/QueryOptions.tsx' import { OperationGenerator } from './OperationGenerator.tsx' -import type { KubbFile } from '@kubb/core' -import type { Plugin } from '@kubb/core' +import { FileManager, KubbFile, type Plugin } from '@kubb/core' import type { GetOperationGeneratorOptions } from '@kubb/swagger' import type { PluginOptions } from './types.ts' diff --git a/packages/swagger-tanstack-query/src/components/Mutation.test.tsx b/packages/swagger-tanstack-query/src/components/Mutation.test.tsx index f87c746e6..69f36fbcc 100644 --- a/packages/swagger-tanstack-query/src/components/Mutation.test.tsx +++ b/packages/swagger-tanstack-query/src/components/Mutation.test.tsx @@ -66,7 +66,7 @@ describe('', async () => { ) test('pets', async () => { - const operation = oas.operation('/pets', 'post') + const operation = oas.operation('/pets/{uuid}', 'post') const schemas = og.getSchemas(operation) const context: AppContextProps = { meta: { oas, pluginManager: mockedPluginManager, plugin, schemas, operation } } diff --git a/packages/swagger-tanstack-query/src/components/__snapshots__/Mutation/Pets.ts b/packages/swagger-tanstack-query/src/components/__snapshots__/Mutation/Pets.ts index e69de29bb..e7709ee17 100644 --- a/packages/swagger-tanstack-query/src/components/__snapshots__/Mutation/Pets.ts +++ b/packages/swagger-tanstack-query/src/components/__snapshots__/Mutation/Pets.ts @@ -0,0 +1,55 @@ +type CreatePetsClient = typeof client +type CreatePets = { + data: CreatePetsMutationResponse + error: never + request: CreatePetsMutationRequest + pathParams: CreatePetsPathParams + queryParams: CreatePetsQueryParams + headerParams: CreatePetsHeaderParams + response: CreatePetsMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} + +/** + * @summary Create a pet + * @link /pets/:uuid */ + +export function useCreatePets( + options: { + mutation?: UseMutationOptions< + CreatePets['response'], + CreatePets['error'], + { uuid: CreatePetsPathParams['uuid']; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] } + > + client?: CreatePets['client']['parameters'] + } = {}, +): UseMutationResult< + CreatePets['response'], + CreatePets['error'], + { uuid: CreatePetsPathParams['uuid']; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] } +> { + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + + return useMutation< + CreatePets['response'], + CreatePets['error'], + { uuid: CreatePetsPathParams['uuid']; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] } + >({ + mutationFn: async ({ uuid, headers, data, params }) => { + const res = await client({ + method: 'post', + url: `/pets/${uuid}`, + params, + data, + headers: { ...headers, ...clientOptions.headers }, + ...clientOptions, + }) + + return res.data + }, + ...mutationOptions, + }) +}