From 25072b2a72eb57364d2b7528bb448cfca60f8bc6 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 20:32:17 +0000 Subject: [PATCH 1/9] feat(plugin-axios,plugin-fetch): add unwrap() to every generated call kubb-labs/discussions#3952 asked for a way to get a generated call's success body without destructuring { data } at every call site. Rather than a plugin-wide returnType default (see PR #818), take the Redux-Toolkit approach: every call's promise gains an unwrap() method, resolving to the bare success body or rejecting with `error`. Plain `await getPetById(...)` keeps returning the full result, so existing code and the query plugins (react-query, vue-query, swr, mcp) are unaffected. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN --- .changeset/client-unwrap-method.md | 13 ++++++++ .../client/src/builders/generics.test.ts | 8 ++++- internals/client/src/builders/generics.ts | 12 +++++++ .../src/builders/returnStatement.test.ts | 4 +-- .../client/src/builders/returnStatement.ts | 11 ++++--- internals/client/src/builders/sdkMethod.ts | 2 +- .../client/src/builders/signature.test.ts | 4 +-- internals/client/src/builders/signature.ts | 7 ++-- internals/client/src/components/Operation.tsx | 2 +- .../client/src/generators/clientGenerator.tsx | 6 ++-- .../client/src/generators/sdkGenerator.tsx | 4 +-- .../__snapshots__/addPetMultiStatus/addPet.ts | 8 ++--- .../addPetMultiStatusWithZod/addPet.ts | 10 +++--- .../deletePetNoContent/deletePet.ts | 8 ++--- .../findPetsByTags/findPetsByTags.ts | 8 ++--- .../__snapshots__/getPetById/getPetById.ts | 8 ++--- .../getPetByIdWithSecurity/getPetById.ts | 15 ++++----- .../__snapshots__/getProject/getProject.ts | 8 ++--- .../listPetsWithStyles/listPetsStyled.ts | 20 ++++++------ .../__snapshots__/sdkClass/petClient.ts | 12 +++---- .../__snapshots__/sdkClass/projectClient.ts | 8 ++--- .../__snapshots__/sdkClass/storeClient.ts | 8 ++--- .../sdkClassWithName/petClient.ts | 12 +++---- .../sdkClassWithName/projectClient.ts | 8 ++--- .../sdkClassWithName/storeClient.ts | 8 ++--- .../__snapshots__/sdkSingle/petStore.ts | 20 ++++++------ packages/plugin-axios/templates/axios.test.ts | 31 +++++++++++++++++- packages/plugin-axios/templates/axios.ts | 28 ++++++++++++++++ .../__snapshots__/addPetMultiStatus/addPet.ts | 8 ++--- .../addPetMultiStatusWithZod/addPet.ts | 10 +++--- .../addPetWithSecurity/addPet.ts | 10 +++--- .../deletePetNoContent/deletePet.ts | 8 ++--- .../findPetsByTags/findPetsByTags.ts | 8 ++--- .../findPetsByTags.ts | 8 ++--- .../__snapshots__/getPetById/getPetById.ts | 8 ++--- .../getPetById.ts | 15 ++++----- .../__snapshots__/getProject/getProject.ts | 8 ++--- .../listPetsWithStyles/listPetsStyled.ts | 20 ++++++------ .../__snapshots__/sdkClass/petClient.ts | 12 +++---- .../__snapshots__/sdkClass/projectClient.ts | 8 ++--- .../__snapshots__/sdkClass/storeClient.ts | 8 ++--- .../sdkClassWithName/petClient.ts | 12 +++---- .../sdkClassWithName/projectClient.ts | 8 ++--- .../sdkClassWithName/storeClient.ts | 8 ++--- .../sdkClassWithSecurity/petStore.ts | 27 +++++++--------- .../__snapshots__/sdkSingle/petStore.ts | 20 ++++++------ .../uploadFileMultipart/uploadFile.ts | 8 ++--- packages/plugin-fetch/templates/fetch.test.ts | 28 ++++++++++++++++ packages/plugin-fetch/templates/fetch.ts | 28 ++++++++++++++++ .../pluginAxios/default/.kubb/client.ts | 28 ++++++++++++++++ .../pluginAxios/default/clients/addPet.ts | 8 ++--- .../pluginAxios/default/clients/deletePet.ts | 8 ++--- .../default/clients/findPetsByStatus.ts | 8 ++--- .../default/clients/getInventory.ts | 8 ++--- .../pluginAxios/default/clients/getPetById.ts | 8 ++--- .../pluginAxios/default/clients/placeOrder.ts | 8 ++--- .../pluginAxios/default/clients/uploadFile.ts | 8 ++--- .../pluginAxios/paramsCasing/.kubb/client.ts | 28 ++++++++++++++++ .../paramsCasing/clients/updatePet.ts | 8 ++--- .../pluginAxios/sdkClass/.kubb/client.ts | 28 ++++++++++++++++ .../pluginAxios/sdkClass/clients/petClient.ts | 24 +++++++------- .../sdkClass/clients/storeClient.ts | 12 +++---- .../sdkClassWithName/.kubb/client.ts | 28 ++++++++++++++++ .../sdkClassWithName/clients/petClient.ts | 24 +++++++------- .../sdkClassWithName/clients/storeClient.ts | 12 +++---- .../pluginAxios/sdkSingle/.kubb/client.ts | 28 ++++++++++++++++ .../pluginAxios/sdkSingle/clients/petStore.ts | 32 +++++++++---------- .../pluginAxios/zodTypes/.kubb/client.ts | 28 ++++++++++++++++ .../pluginAxios/zodTypes/clients/addPet.ts | 8 ++--- .../pluginAxios/zodTypes/clients/deletePet.ts | 8 ++--- .../zodTypes/clients/findPetsByStatus.ts | 8 ++--- .../zodTypes/clients/getInventory.ts | 8 ++--- .../zodTypes/clients/getPetById.ts | 8 ++--- .../zodTypes/clients/placeOrder.ts | 8 ++--- .../zodTypes/clients/uploadFile.ts | 8 ++--- .../pluginFetch/default/.kubb/client.ts | 28 ++++++++++++++++ .../pluginFetch/default/clients/addPet.ts | 8 ++--- .../pluginFetch/default/clients/deletePet.ts | 8 ++--- .../default/clients/findPetsByStatus.ts | 8 ++--- .../default/clients/getInventory.ts | 8 ++--- .../pluginFetch/default/clients/getPetById.ts | 8 ++--- .../pluginFetch/default/clients/placeOrder.ts | 8 ++--- .../pluginFetch/default/clients/uploadFile.ts | 8 ++--- .../pluginFetch/paramsCasing/.kubb/client.ts | 28 ++++++++++++++++ .../paramsCasing/clients/updatePet.ts | 8 ++--- .../pluginFetch/sdkClass/.kubb/client.ts | 28 ++++++++++++++++ .../pluginFetch/sdkClass/clients/petClient.ts | 24 +++++++------- .../sdkClass/clients/storeClient.ts | 12 +++---- .../sdkClassWithName/.kubb/client.ts | 28 ++++++++++++++++ .../sdkClassWithName/clients/petClient.ts | 24 +++++++------- .../sdkClassWithName/clients/storeClient.ts | 12 +++---- .../pluginFetch/sdkSingle/.kubb/client.ts | 28 ++++++++++++++++ .../pluginFetch/sdkSingle/clients/petStore.ts | 32 +++++++++---------- .../pluginFetch/zodTypes/.kubb/client.ts | 28 ++++++++++++++++ .../pluginFetch/zodTypes/clients/addPet.ts | 8 ++--- .../pluginFetch/zodTypes/clients/deletePet.ts | 8 ++--- .../zodTypes/clients/findPetsByStatus.ts | 8 ++--- .../zodTypes/clients/getInventory.ts | 8 ++--- .../zodTypes/clients/getPetById.ts | 8 ++--- .../zodTypes/clients/placeOrder.ts | 8 ++--- .../zodTypes/clients/uploadFile.ts | 8 ++--- .../pluginFetch/zodTypesSdk/.kubb/client.ts | 28 ++++++++++++++++ .../zodTypesSdk/clients/petClient.ts | 24 +++++++------- .../zodTypesSdk/clients/storeClient.ts | 12 +++---- .../excludeByOperationId/.kubb/client.ts | 28 ++++++++++++++++ .../excludeByOperationId/clients/addPet.ts | 8 ++--- .../excludeByOperationId/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../clients/getInventory.ts | 8 ++--- .../clients/getPetById.ts | 8 ++--- .../clients/placeOrder.ts | 8 ++--- .../clients/uploadFile.ts | 8 ++--- .../pluginMcp/groupByTag/.kubb/client.ts | 28 ++++++++++++++++ .../pluginMcp/groupByTag/clients/addPet.ts | 8 ++--- .../pluginMcp/groupByTag/clients/deletePet.ts | 8 ++--- .../groupByTag/clients/findPetsByStatus.ts | 8 ++--- .../groupByTag/clients/getInventory.ts | 8 ++--- .../groupByTag/clients/getPetById.ts | 8 ++--- .../groupByTag/clients/placeOrder.ts | 8 ++--- .../groupByTag/clients/uploadFile.ts | 8 ++--- .../pluginMcp/includeByTag/.kubb/client.ts | 28 ++++++++++++++++ .../pluginMcp/includeByTag/clients/addPet.ts | 8 ++--- .../includeByTag/clients/deletePet.ts | 8 ++--- .../includeByTag/clients/findPetsByStatus.ts | 8 ++--- .../includeByTag/clients/getInventory.ts | 8 ++--- .../includeByTag/clients/getPetById.ts | 8 ++--- .../includeByTag/clients/placeOrder.ts | 8 ++--- .../includeByTag/clients/uploadFile.ts | 8 ++--- .../pluginMcp/paramsCasing/.kubb/client.ts | 28 ++++++++++++++++ .../paramsCasing/clients/updatePet.ts | 8 ++--- .../pluginMcp/petStore/.kubb/client.ts | 28 ++++++++++++++++ .../pluginMcp/petStore/clients/addPet.ts | 8 ++--- .../pluginMcp/petStore/clients/deletePet.ts | 8 ++--- .../petStore/clients/findPetsByStatus.ts | 8 ++--- .../petStore/clients/getInventory.ts | 8 ++--- .../pluginMcp/petStore/clients/getPetById.ts | 8 ++--- .../pluginMcp/petStore/clients/placeOrder.ts | 8 ++--- .../pluginMcp/petStore/clients/uploadFile.ts | 8 ++--- .../withClientPlugin/.kubb/client.ts | 28 ++++++++++++++++ .../withClientPlugin/clients/addPet.ts | 8 ++--- .../withClientPlugin/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../withClientPlugin/clients/getInventory.ts | 8 ++--- .../withClientPlugin/clients/getPetById.ts | 8 ++--- .../withClientPlugin/clients/placeOrder.ts | 8 ++--- .../withClientPlugin/clients/uploadFile.ts | 8 ++--- .../excludeByOperationId/.kubb/client.ts | 28 ++++++++++++++++ .../excludeByOperationId/clients/addPet.ts | 8 ++--- .../excludeByOperationId/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../clients/getInventory.ts | 8 ++--- .../clients/getPetById.ts | 8 ++--- .../clients/placeOrder.ts | 8 ++--- .../clients/uploadFile.ts | 8 ++--- .../groupByTag/.kubb/client.ts | 28 ++++++++++++++++ .../groupByTag/clients/addPet.ts | 8 ++--- .../groupByTag/clients/deletePet.ts | 8 ++--- .../groupByTag/clients/findPetsByStatus.ts | 8 ++--- .../groupByTag/clients/getInventory.ts | 8 ++--- .../groupByTag/clients/getPetById.ts | 8 ++--- .../groupByTag/clients/placeOrder.ts | 8 ++--- .../groupByTag/clients/uploadFile.ts | 8 ++--- .../includeByTag/.kubb/client.ts | 28 ++++++++++++++++ .../includeByTag/clients/addPet.ts | 8 ++--- .../includeByTag/clients/deletePet.ts | 8 ++--- .../includeByTag/clients/findPetsByStatus.ts | 8 ++--- .../includeByTag/clients/getInventory.ts | 8 ++--- .../includeByTag/clients/getPetById.ts | 8 ++--- .../includeByTag/clients/placeOrder.ts | 8 ++--- .../includeByTag/clients/uploadFile.ts | 8 ++--- .../pluginReactQuery/infinite/.kubb/client.ts | 28 ++++++++++++++++ .../infinite/clients/addPet.ts | 8 ++--- .../infinite/clients/deletePet.ts | 8 ++--- .../infinite/clients/findPetsByStatus.ts | 8 ++--- .../infinite/clients/getInventory.ts | 8 ++--- .../infinite/clients/getPetById.ts | 8 ++--- .../infinite/clients/placeOrder.ts | 8 ++--- .../infinite/clients/uploadFile.ts | 8 ++--- .../mutationDisabled/.kubb/client.ts | 28 ++++++++++++++++ .../mutationDisabled/clients/addPet.ts | 8 ++--- .../mutationDisabled/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../mutationDisabled/clients/getInventory.ts | 8 ++--- .../mutationDisabled/clients/getPetById.ts | 8 ++--- .../mutationDisabled/clients/placeOrder.ts | 8 ++--- .../mutationDisabled/clients/uploadFile.ts | 8 ++--- .../paramsCasing/.kubb/client.ts | 28 ++++++++++++++++ .../paramsCasing/clients/updatePet.ts | 8 ++--- .../parserZod/.kubb/client.ts | 28 ++++++++++++++++ .../parserZod/clients/addPet.ts | 8 ++--- .../parserZod/clients/deletePet.ts | 8 ++--- .../parserZod/clients/findPetsByStatus.ts | 8 ++--- .../parserZod/clients/getInventory.ts | 8 ++--- .../parserZod/clients/getPetById.ts | 8 ++--- .../parserZod/clients/placeOrder.ts | 8 ++--- .../parserZod/clients/uploadFile.ts | 8 ++--- .../pluginReactQuery/petStore/.kubb/client.ts | 28 ++++++++++++++++ .../petStore/clients/addPet.ts | 8 ++--- .../petStore/clients/deletePet.ts | 8 ++--- .../petStore/clients/findPetsByStatus.ts | 8 ++--- .../petStore/clients/getInventory.ts | 8 ++--- .../petStore/clients/getPetById.ts | 8 ++--- .../petStore/clients/placeOrder.ts | 8 ++--- .../petStore/clients/uploadFile.ts | 8 ++--- .../queryMethods/.kubb/client.ts | 28 ++++++++++++++++ .../queryMethods/clients/addPet.ts | 8 ++--- .../queryMethods/clients/deletePet.ts | 8 ++--- .../queryMethods/clients/findPetsByStatus.ts | 8 ++--- .../queryMethods/clients/getInventory.ts | 8 ++--- .../queryMethods/clients/getPetById.ts | 8 ++--- .../queryMethods/clients/placeOrder.ts | 8 ++--- .../queryMethods/clients/uploadFile.ts | 8 ++--- .../pluginReactQuery/suspense/.kubb/client.ts | 28 ++++++++++++++++ .../suspense/clients/addPet.ts | 8 ++--- .../suspense/clients/deletePet.ts | 8 ++--- .../suspense/clients/findPetsByStatus.ts | 8 ++--- .../suspense/clients/getInventory.ts | 8 ++--- .../suspense/clients/getPetById.ts | 8 ++--- .../suspense/clients/placeOrder.ts | 8 ++--- .../suspense/clients/uploadFile.ts | 8 ++--- .../withClientPlugin/.kubb/client.ts | 28 ++++++++++++++++ .../withClientPlugin/clients/addPet.ts | 8 ++--- .../withClientPlugin/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../withClientPlugin/clients/getInventory.ts | 8 ++--- .../withClientPlugin/clients/getPetById.ts | 8 ++--- .../withClientPlugin/clients/placeOrder.ts | 8 ++--- .../withClientPlugin/clients/uploadFile.ts | 8 ++--- .../excludeByOperationId/.kubb/client.ts | 28 ++++++++++++++++ .../excludeByOperationId/clients/addPet.ts | 8 ++--- .../excludeByOperationId/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../clients/getInventory.ts | 8 ++--- .../clients/getPetById.ts | 8 ++--- .../clients/placeOrder.ts | 8 ++--- .../clients/uploadFile.ts | 8 ++--- .../pluginSwr/groupByTag/.kubb/client.ts | 28 ++++++++++++++++ .../pluginSwr/groupByTag/clients/addPet.ts | 8 ++--- .../pluginSwr/groupByTag/clients/deletePet.ts | 8 ++--- .../groupByTag/clients/findPetsByStatus.ts | 8 ++--- .../groupByTag/clients/getInventory.ts | 8 ++--- .../groupByTag/clients/getPetById.ts | 8 ++--- .../groupByTag/clients/placeOrder.ts | 8 ++--- .../groupByTag/clients/uploadFile.ts | 8 ++--- .../pluginSwr/includeByTag/.kubb/client.ts | 28 ++++++++++++++++ .../pluginSwr/includeByTag/clients/addPet.ts | 8 ++--- .../includeByTag/clients/deletePet.ts | 8 ++--- .../includeByTag/clients/findPetsByStatus.ts | 8 ++--- .../includeByTag/clients/getInventory.ts | 8 ++--- .../includeByTag/clients/getPetById.ts | 8 ++--- .../includeByTag/clients/placeOrder.ts | 8 ++--- .../includeByTag/clients/uploadFile.ts | 8 ++--- .../mutationDisabled/.kubb/client.ts | 28 ++++++++++++++++ .../mutationDisabled/clients/addPet.ts | 8 ++--- .../mutationDisabled/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../mutationDisabled/clients/getInventory.ts | 8 ++--- .../mutationDisabled/clients/getPetById.ts | 8 ++--- .../mutationDisabled/clients/placeOrder.ts | 8 ++--- .../mutationDisabled/clients/uploadFile.ts | 8 ++--- .../pluginSwr/paramsCasing/.kubb/client.ts | 28 ++++++++++++++++ .../paramsCasing/clients/updatePet.ts | 8 ++--- .../pluginSwr/parserZod/.kubb/client.ts | 28 ++++++++++++++++ .../pluginSwr/parserZod/clients/addPet.ts | 8 ++--- .../pluginSwr/parserZod/clients/deletePet.ts | 8 ++--- .../parserZod/clients/findPetsByStatus.ts | 8 ++--- .../parserZod/clients/getInventory.ts | 8 ++--- .../pluginSwr/parserZod/clients/getPetById.ts | 8 ++--- .../pluginSwr/parserZod/clients/placeOrder.ts | 8 ++--- .../pluginSwr/parserZod/clients/uploadFile.ts | 8 ++--- .../pluginSwr/petStore/.kubb/client.ts | 28 ++++++++++++++++ .../pluginSwr/petStore/clients/addPet.ts | 8 ++--- .../pluginSwr/petStore/clients/deletePet.ts | 8 ++--- .../petStore/clients/findPetsByStatus.ts | 8 ++--- .../petStore/clients/getInventory.ts | 8 ++--- .../pluginSwr/petStore/clients/getPetById.ts | 8 ++--- .../pluginSwr/petStore/clients/placeOrder.ts | 8 ++--- .../pluginSwr/petStore/clients/uploadFile.ts | 8 ++--- .../pluginSwr/queryDisabled/.kubb/client.ts | 28 ++++++++++++++++ .../pluginSwr/queryDisabled/clients/addPet.ts | 8 ++--- .../queryDisabled/clients/deletePet.ts | 8 ++--- .../queryDisabled/clients/findPetsByStatus.ts | 8 ++--- .../queryDisabled/clients/getInventory.ts | 8 ++--- .../queryDisabled/clients/getPetById.ts | 8 ++--- .../queryDisabled/clients/placeOrder.ts | 8 ++--- .../queryDisabled/clients/uploadFile.ts | 8 ++--- .../pluginSwr/queryMethods/.kubb/client.ts | 28 ++++++++++++++++ .../pluginSwr/queryMethods/clients/addPet.ts | 8 ++--- .../queryMethods/clients/deletePet.ts | 8 ++--- .../queryMethods/clients/findPetsByStatus.ts | 8 ++--- .../queryMethods/clients/getInventory.ts | 8 ++--- .../queryMethods/clients/getPetById.ts | 8 ++--- .../queryMethods/clients/placeOrder.ts | 8 ++--- .../queryMethods/clients/uploadFile.ts | 8 ++--- .../withClientPlugin/.kubb/client.ts | 28 ++++++++++++++++ .../withClientPlugin/clients/addPet.ts | 8 ++--- .../withClientPlugin/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../withClientPlugin/clients/getInventory.ts | 8 ++--- .../withClientPlugin/clients/getPetById.ts | 8 ++--- .../withClientPlugin/clients/placeOrder.ts | 8 ++--- .../withClientPlugin/clients/uploadFile.ts | 8 ++--- .../excludeByOperationId/.kubb/client.ts | 28 ++++++++++++++++ .../excludeByOperationId/clients/addPet.ts | 8 ++--- .../excludeByOperationId/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../clients/getInventory.ts | 8 ++--- .../clients/getPetById.ts | 8 ++--- .../clients/placeOrder.ts | 8 ++--- .../clients/uploadFile.ts | 8 ++--- .../pluginVueQuery/groupByTag/.kubb/client.ts | 28 ++++++++++++++++ .../groupByTag/clients/addPet.ts | 8 ++--- .../groupByTag/clients/deletePet.ts | 8 ++--- .../groupByTag/clients/findPetsByStatus.ts | 8 ++--- .../groupByTag/clients/getInventory.ts | 8 ++--- .../groupByTag/clients/getPetById.ts | 8 ++--- .../groupByTag/clients/placeOrder.ts | 8 ++--- .../groupByTag/clients/uploadFile.ts | 8 ++--- .../includeByTag/.kubb/client.ts | 28 ++++++++++++++++ .../includeByTag/clients/addPet.ts | 8 ++--- .../includeByTag/clients/deletePet.ts | 8 ++--- .../includeByTag/clients/findPetsByStatus.ts | 8 ++--- .../includeByTag/clients/getInventory.ts | 8 ++--- .../includeByTag/clients/getPetById.ts | 8 ++--- .../includeByTag/clients/placeOrder.ts | 8 ++--- .../includeByTag/clients/uploadFile.ts | 8 ++--- .../pluginVueQuery/infinite/.kubb/client.ts | 28 ++++++++++++++++ .../pluginVueQuery/infinite/clients/addPet.ts | 8 ++--- .../infinite/clients/deletePet.ts | 8 ++--- .../infinite/clients/findPetsByStatus.ts | 8 ++--- .../infinite/clients/getInventory.ts | 8 ++--- .../infinite/clients/getPetById.ts | 8 ++--- .../infinite/clients/placeOrder.ts | 8 ++--- .../infinite/clients/uploadFile.ts | 8 ++--- .../mutationDisabled/.kubb/client.ts | 28 ++++++++++++++++ .../mutationDisabled/clients/addPet.ts | 8 ++--- .../mutationDisabled/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../mutationDisabled/clients/getInventory.ts | 8 ++--- .../mutationDisabled/clients/getPetById.ts | 8 ++--- .../mutationDisabled/clients/placeOrder.ts | 8 ++--- .../mutationDisabled/clients/uploadFile.ts | 8 ++--- .../paramsCasing/.kubb/client.ts | 28 ++++++++++++++++ .../paramsCasing/clients/updatePet.ts | 8 ++--- .../pluginVueQuery/parserZod/.kubb/client.ts | 28 ++++++++++++++++ .../parserZod/clients/addPet.ts | 8 ++--- .../parserZod/clients/deletePet.ts | 8 ++--- .../parserZod/clients/findPetsByStatus.ts | 8 ++--- .../parserZod/clients/getInventory.ts | 8 ++--- .../parserZod/clients/getPetById.ts | 8 ++--- .../parserZod/clients/placeOrder.ts | 8 ++--- .../parserZod/clients/uploadFile.ts | 8 ++--- .../pluginVueQuery/petStore/.kubb/client.ts | 28 ++++++++++++++++ .../pluginVueQuery/petStore/clients/addPet.ts | 8 ++--- .../petStore/clients/deletePet.ts | 8 ++--- .../petStore/clients/findPetsByStatus.ts | 8 ++--- .../petStore/clients/getInventory.ts | 8 ++--- .../petStore/clients/getPetById.ts | 8 ++--- .../petStore/clients/placeOrder.ts | 8 ++--- .../petStore/clients/uploadFile.ts | 8 ++--- .../withClientPlugin/.kubb/client.ts | 28 ++++++++++++++++ .../withClientPlugin/clients/addPet.ts | 8 ++--- .../withClientPlugin/clients/deletePet.ts | 8 ++--- .../clients/findPetsByStatus.ts | 8 ++--- .../withClientPlugin/clients/getInventory.ts | 8 ++--- .../withClientPlugin/clients/getPetById.ts | 8 ++--- .../withClientPlugin/clients/placeOrder.ts | 8 ++--- .../withClientPlugin/clients/uploadFile.ts | 8 ++--- 368 files changed, 2880 insertions(+), 1363 deletions(-) create mode 100644 .changeset/client-unwrap-method.md diff --git a/.changeset/client-unwrap-method.md b/.changeset/client-unwrap-method.md new file mode 100644 index 000000000..992aa1e77 --- /dev/null +++ b/.changeset/client-unwrap-method.md @@ -0,0 +1,13 @@ +--- +'@kubb/plugin-axios': minor +'@kubb/plugin-fetch': minor +--- + +Every generated call now resolves to a promise with an extra `unwrap()` method, Redux-Toolkit-style: +`unwrap()` resolves to the bare success body, or rejects with `error` for a result that carried one. +`await getPetById(...)` still resolves to the full `{ status, data, error, contentType, request, response }` +result as before, so this is additive. + +```ts +const pet = await getPetById({ path: { petId: 1 } }).unwrap() +``` diff --git a/internals/client/src/builders/generics.test.ts b/internals/client/src/builders/generics.test.ts index 6f55ad37e..a337d14af 100644 --- a/internals/client/src/builders/generics.test.ts +++ b/internals/client/src/builders/generics.test.ts @@ -1,7 +1,7 @@ import { ast } from 'kubb/kit' import { resolverTs } from '@kubb/plugin-ts' import { describe, expect, test } from 'vitest' -import { buildRequestResultGenerics } from './generics.ts' +import { buildRequestResultGenerics, buildResultType } from './generics.ts' const node = ast.factory.createOperation({ operationId: 'getPetById', @@ -17,3 +17,9 @@ describe('buildRequestResultGenerics', () => { expect(buildRequestResultGenerics({ node, types: resolverTs })).toBe('GetPetByIdResponses, ThrowOnError') }) }) + +describe('buildResultType', () => { + test('wraps RequestResult in Unwrappable', () => { + expect(buildResultType({ node, types: resolverTs })).toBe('Unwrappable>') + }) +}) diff --git a/internals/client/src/builders/generics.ts b/internals/client/src/builders/generics.ts index 451b61f7c..0d68081fa 100644 --- a/internals/client/src/builders/generics.ts +++ b/internals/client/src/builders/generics.ts @@ -12,3 +12,15 @@ import type { OperationTypeNames } from '../resolveOperationTypes.ts' export function buildRequestResultGenerics({ node, types }: { node: ast.OperationNode; types: OperationTypeNames }): string { return `${types.response.responses(node)}, ThrowOnError` } + +/** + * Builds the result type name an operation's function signature and return statement use: the + * runtime's `Unwrappable`, wrapping `RequestResult` so the resolved call also carries an + * RTK-style `unwrap()` method. + * + * @example + * `buildResultType({ node, types }) // 'Unwrappable>'` + */ +export function buildResultType({ node, types }: { node: ast.OperationNode; types: OperationTypeNames }): string { + return `Unwrappable>` +} diff --git a/internals/client/src/builders/returnStatement.test.ts b/internals/client/src/builders/returnStatement.test.ts index 27f5d005a..c187454ca 100644 --- a/internals/client/src/builders/returnStatement.test.ts +++ b/internals/client/src/builders/returnStatement.test.ts @@ -12,10 +12,10 @@ const node = ast.factory.createOperation({ }) describe('buildReturnStatement', () => { - test('forwards the call config and casts to the operation RequestResult', () => { + test('wraps the call in withUnwrap and casts to the operation Unwrappable', () => { const callConfig = "{ method: 'POST', url: '/pet', ...config }" expect(buildReturnStatement({ node, types: resolverTs, callConfig })).toBe( - "return request({ method: 'POST', url: '/pet', ...config }) as Promise>", + "return withUnwrap(request({ method: 'POST', url: '/pet', ...config })) as Unwrappable>", ) }) }) diff --git a/internals/client/src/builders/returnStatement.ts b/internals/client/src/builders/returnStatement.ts index 19d680019..f59400dcb 100644 --- a/internals/client/src/builders/returnStatement.ts +++ b/internals/client/src/builders/returnStatement.ts @@ -1,15 +1,16 @@ import type { ast } from 'kubb/kit' import type { OperationTypeNames } from '../resolveOperationTypes.ts' -import { buildRequestResultGenerics } from './generics.ts' +import { buildResultType } from './generics.ts' /** * Builds the return statement of a generated operation function. The runtime call already resolves - * to `{ data, error, request, response }`; the generated code forwards that result and casts it to - * the operation's `RequestResult`, which carries the `throwOnError` discrimination. + * to `{ data, error, request, response }`; the generated code wraps that promise with `withUnwrap` + * so the caller can `await` it directly or call `.unwrap()` for the bare success body, then casts + * the result to the operation's `Unwrappable>`. * * @example - * `return request({ method: 'POST', url: '/pet', ...config }) as Promise>` + * `return withUnwrap(request({ method: 'POST', url: '/pet', ...config })) as Unwrappable>` */ export function buildReturnStatement({ node, types, callConfig }: { node: ast.OperationNode; types: OperationTypeNames; callConfig: string }): string { - return `return request(${callConfig}) as Promise>` + return `return withUnwrap(request(${callConfig})) as ${buildResultType({ node, types })}` } diff --git a/internals/client/src/builders/sdkMethod.ts b/internals/client/src/builders/sdkMethod.ts index c569a5cc6..95ec2221d 100644 --- a/internals/client/src/builders/sdkMethod.ts +++ b/internals/client/src/builders/sdkMethod.ts @@ -47,7 +47,7 @@ function buildCallConfig({ /** * Builds a single instance method for a generated SDK class. The body forwards the single grouped * `options` object to the instance's own client (`this.client`, built once in the constructor) and - * returns the `RequestResult`. A per-call `options.client` still overrides the instance client, so + * returns the `Unwrappable`. A per-call `options.client` still overrides the instance client, so * one operation can be routed to a different environment without a new instance. */ export function buildSdkMethod({ diff --git a/internals/client/src/builders/signature.test.ts b/internals/client/src/builders/signature.test.ts index a3efd0c71..a09a9b575 100644 --- a/internals/client/src/builders/signature.test.ts +++ b/internals/client/src/builders/signature.test.ts @@ -41,8 +41,8 @@ describe('buildGroupedOptionsSignature', () => { expect(signature.paramsSignature).toBe('options: Options = {}') }) - test('keys the return type on the plugin-ts per-status responses record', () => { + test('keys the return type on the plugin-ts per-status responses record, wrapped in Unwrappable', () => { const signature = buildGroupedOptionsSignature({ node: addPet, types: resolverTs }) - expect(signature.returnType).toBe('Promise>') + expect(signature.returnType).toBe('Unwrappable>') }) }) diff --git a/internals/client/src/builders/signature.ts b/internals/client/src/builders/signature.ts index efd4f12e8..0f8d0a8ac 100644 --- a/internals/client/src/builders/signature.ts +++ b/internals/client/src/builders/signature.ts @@ -2,7 +2,7 @@ import type { ast } from 'kubb/kit' import { getRequestGroupOptionality } from '@internals/shared' import { createFunctionParameter, createFunctionParameters, functionPrinter } from '@kubb/plugin-ts' import type { OperationTypeNames } from '../resolveOperationTypes.ts' -import { buildRequestResultGenerics } from './generics.ts' +import { buildResultType } from './generics.ts' const declarationPrinter = functionPrinter({ mode: 'declaration' }) @@ -15,7 +15,7 @@ export type GroupedOptionsSignature = { */ paramsSignature: string /** - * The function return type: `PromiseResponses, ThrowOnError>>`. + * The function return type: `UnwrappableResponses, ThrowOnError>>`. */ returnType: string /** @@ -35,7 +35,6 @@ export type GroupedOptionsSignature = { */ export function buildGroupedOptionsSignature({ node, types }: { node: ast.OperationNode; types: OperationTypeNames }): GroupedOptionsSignature { const optionsName = types.response.options(node) - const resultGenerics = buildRequestResultGenerics({ node, types }) const { isOptional } = getRequestGroupOptionality(node) const paramsSignature = @@ -47,7 +46,7 @@ export function buildGroupedOptionsSignature({ node, types }: { node: ast.Operat return { paramsSignature, - returnType: `Promise>`, + returnType: buildResultType({ node, types }), generics: ['ThrowOnError extends boolean = true'], } } diff --git a/internals/client/src/components/Operation.tsx b/internals/client/src/components/Operation.tsx index a1f3baa7b..45f59f318 100644 --- a/internals/client/src/components/Operation.tsx +++ b/internals/client/src/components/Operation.tsx @@ -44,7 +44,7 @@ type Props = { /** * Renders one client operation: the grouped `Request` type and the function that forwards a - * single `options` object to the resolved client and returns the `RequestResult`. The type, signature, + * single `options` object to the resolved client and returns the `Unwrappable`. The type, signature, * and call config are built with the AST factory, and only the jsx-renderer emits the source. */ export function Operation({ name, node, types, zodResolver, validator, security, isExportable = true, isIndexable = true }: Props): KubbReactNode { diff --git a/internals/client/src/generators/clientGenerator.tsx b/internals/client/src/generators/clientGenerator.tsx index eca24ef39..3b0271012 100644 --- a/internals/client/src/generators/clientGenerator.tsx +++ b/internals/client/src/generators/clientGenerator.tsx @@ -14,7 +14,7 @@ import type { ContractClientFactory } from '../types.ts' * Builds the built-in per-operation generator shared by the client plugins (`@kubb/plugin-fetch`, * `@kubb/plugin-axios`). Emits one async function per OpenAPI operation using the shared * `Operation` component: a grouped `Request` type and a function that forwards a single - * `options` object to the bundled `client` and returns the `RequestResult`. Only the generator + * `options` object to the bundled `client` and returns the `Unwrappable`. Only the generator * `name` differs between plugins; every other resolution, import, and rendering step is identical. */ export function createClientGenerator(name: string): Generator { @@ -87,9 +87,9 @@ export function createClientGenerator(na banner={resolver.default.banner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })} footer={resolver.default.footer(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })} > - + (): Ge return ( - - + + {validator === 'zod' && ops.some((op) => op.node.requestBody?.content?.[0]?.schema != null) && } diff --git a/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatus/addPet.ts b/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatus/addPet.ts index 3cd33d53f..a7ea99afa 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatus/addPet.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatus/addPet.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { AddPetOptions, AddPetResponses } from './AddPet' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet} */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', ...config })) as Unwrappable> } diff --git a/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts b/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts index 321048af4..d2af06c37 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { AddPetOptions, AddPetResponses } from './AddPet' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' import { AddPetResponse } from './AddPet' /** @@ -10,8 +10,10 @@ import { AddPetResponse } from './AddPet' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', validator: { response: AddPetResponse }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', validator: { response: AddPetResponse }, ...config })) as Unwrappable< + RequestResult + > } diff --git a/packages/plugin-axios/src/generators/__snapshots__/deletePetNoContent/deletePet.ts b/packages/plugin-axios/src/generators/__snapshots__/deletePetNoContent/deletePet.ts index d03515c81..bb6c0ce5e 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/deletePetNoContent/deletePet.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/deletePetNoContent/deletePet.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/:petId} */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } diff --git a/packages/plugin-axios/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts b/packages/plugin-axios/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts index 56b72240e..ab984857f 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from './FindPetsByTags' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/findByTags} */ export function findPetsByTags( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByTags', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByTags', ...config })) as Unwrappable> } diff --git a/packages/plugin-axios/src/generators/__snapshots__/getPetById/getPetById.ts b/packages/plugin-axios/src/generators/__snapshots__/getPetById/getPetById.ts index 695457e65..5db400e5d 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/getPetById/getPetById.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/getPetById/getPetById.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/:petId} */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> } diff --git a/packages/plugin-axios/src/generators/__snapshots__/getPetByIdWithSecurity/getPetById.ts b/packages/plugin-axios/src/generators/__snapshots__/getPetByIdWithSecurity/getPetById.ts index b0481cf25..81cb173de 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/getPetByIdWithSecurity/getPetById.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/getPetByIdWithSecurity/getPetById.ts @@ -1,21 +1,18 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/:petId} */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }), + ) as Unwrappable> } diff --git a/packages/plugin-axios/src/generators/__snapshots__/getProject/getProject.ts b/packages/plugin-axios/src/generators/__snapshots__/getProject/getProject.ts index e82d50621..e5489beb6 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/getProject/getProject.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/getProject/getProject.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /projects/:project_id} */ export function getProject( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } diff --git a/packages/plugin-axios/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts b/packages/plugin-axios/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts index eea2dbbc7..e9efb1c8a 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts @@ -1,21 +1,23 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { ListPetsStyledOptions, ListPetsStyledResponses } from './ListPetsStyled' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pets/:petId} */ export function listPetsStyled( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pets/{petId}', - styles: { path: { petId: { style: 'matrix', explode: true } }, query: { tags: { style: 'pipeDelimited', explode: false } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pets/{petId}', + styles: { path: { petId: { style: 'matrix', explode: true } }, query: { tags: { style: 'pipeDelimited', explode: false } } }, + ...config, + }), + ) as Unwrappable> } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/petClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/petClient.ts index 1955a4ead..9dc693850 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/petClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/petClient.ts @@ -1,9 +1,9 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class PetClient { private readonly client: ClientInstance @@ -17,10 +17,10 @@ export class PetClient { */ public getPetById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -28,9 +28,9 @@ export class PetClient { */ public deletePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/projectClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/projectClient.ts index 1dd660841..345af6331 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/projectClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/projectClient.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class ProjectClient { private readonly client: ClientInstance @@ -16,9 +16,9 @@ export class ProjectClient { */ public getProject( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/storeClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/storeClient.ts index 4dc93913f..4993cf2b7 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/storeClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/storeClient.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from './GetInventory' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class StoreClient { private readonly client: ClientInstance @@ -16,9 +16,9 @@ export class StoreClient { */ public getInventory( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/petClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/petClient.ts index 1955a4ead..9dc693850 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/petClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/petClient.ts @@ -1,9 +1,9 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class PetClient { private readonly client: ClientInstance @@ -17,10 +17,10 @@ export class PetClient { */ public getPetById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -28,9 +28,9 @@ export class PetClient { */ public deletePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/projectClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/projectClient.ts index 1dd660841..345af6331 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/projectClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/projectClient.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class ProjectClient { private readonly client: ClientInstance @@ -16,9 +16,9 @@ export class ProjectClient { */ public getProject( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/storeClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/storeClient.ts index 4dc93913f..4993cf2b7 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/storeClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/storeClient.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from './GetInventory' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class StoreClient { private readonly client: ClientInstance @@ -16,9 +16,9 @@ export class StoreClient { */ public getInventory( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkSingle/petStore.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkSingle/petStore.ts index fea34019d..e453d47d9 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkSingle/petStore.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkSingle/petStore.ts @@ -1,11 +1,11 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' import type { GetInventoryOptions, GetInventoryResponses } from './GetInventory' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class PetStore { private readonly client: ClientInstance @@ -19,10 +19,10 @@ export class PetStore { */ public getPetById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -30,10 +30,10 @@ export class PetStore { */ public deletePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -41,10 +41,10 @@ export class PetStore { */ public getInventory( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> } /** @@ -52,9 +52,9 @@ export class PetStore { */ public getProject( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-axios/templates/axios.test.ts b/packages/plugin-axios/templates/axios.test.ts index 30bc1bb51..a7d289e09 100644 --- a/packages/plugin-axios/templates/axios.test.ts +++ b/packages/plugin-axios/templates/axios.test.ts @@ -1,6 +1,6 @@ import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios' import { describe, expect, test, vi } from 'vitest' -import { type CallResult, createClientCore, parseEventStream, ResponseError, resolveAuth } from './axios.ts' +import { type CallResult, createClientCore, parseEventStream, ResponseError, resolveAuth, withUnwrap } from './axios.ts' import { applyHeaderStyles, defaultBodySerializer, defaultPathSerializer, defaultQuerySerializer, serializeCookies } from './serializers.ts' type Programmed = { data?: unknown; status?: number; statusText?: string } @@ -716,6 +716,35 @@ describe('getUrl', () => { }) }) +describe('withUnwrap', () => { + test('unwrap() resolves to the success data', async () => { + const { instance } = fakeAxios({ data: { id: 1 }, status: 200 }) + const client = createClientCore({ transport: instance }) + const result = await withUnwrap(client({ method: 'GET', url: '/pet/1' }) as Promise).unwrap() + expect(result).toStrictEqual({ id: 1 }) + }) + + test('unwrap() rejects with error for a non-throwing error result', async () => { + const { instance } = fakeAxios({ data: { message: 'not found' }, status: 404 }) + const client = createClientCore({ transport: instance, validateStatus: () => true }) + await expect(withUnwrap(client({ method: 'GET', url: '/pet/999' }) as Promise).unwrap()).rejects.toStrictEqual({ message: 'not found' }) + }) + + test('the wrapped promise still resolves to the full result when awaited directly', async () => { + const { instance } = fakeAxios({ data: { id: 1 }, status: 200 }) + const client = createClientCore({ transport: instance }) + const result = await withUnwrap(client({ method: 'GET', url: '/pet/1' }) as Promise) + expect(result.status).toBe(200) + expect(result.data).toStrictEqual({ id: 1 }) + }) + + test('a throwing call rejects before unwrap() has a chance to run', async () => { + const { instance } = fakeAxios({ data: { message: 'not found' }, status: 404 }) + const client = createClientCore({ transport: instance }) + await expect(withUnwrap(client({ method: 'GET', url: '/pet/999' }) as Promise).unwrap()).rejects.toBeInstanceOf(ResponseError) + }) +}) + describe('resolveAuth', () => { test('places a bearer token on the Authorization header', async () => { const headers: Record = {} diff --git a/packages/plugin-axios/templates/axios.ts b/packages/plugin-axios/templates/axios.ts index d928c18f3..bc1594660 100644 --- a/packages/plugin-axios/templates/axios.ts +++ b/packages/plugin-axios/templates/axios.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatus/addPet.ts b/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatus/addPet.ts index 3cd33d53f..a7ea99afa 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatus/addPet.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatus/addPet.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { AddPetOptions, AddPetResponses } from './AddPet' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet} */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', ...config })) as Unwrappable> } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts b/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts index 321048af4..d2af06c37 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { AddPetOptions, AddPetResponses } from './AddPet' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' import { AddPetResponse } from './AddPet' /** @@ -10,8 +10,10 @@ import { AddPetResponse } from './AddPet' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', validator: { response: AddPetResponse }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', validator: { response: AddPetResponse }, ...config })) as Unwrappable< + RequestResult + > } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/addPetWithSecurity/addPet.ts b/packages/plugin-fetch/src/generators/__snapshots__/addPetWithSecurity/addPet.ts index 37bea9794..dc3f468ed 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/addPetWithSecurity/addPet.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/addPetWithSecurity/addPet.ts @@ -1,16 +1,18 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { AddPetOptions, AddPetResponses } from './AddPet' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet} */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable< + RequestResult + > } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/deletePetNoContent/deletePet.ts b/packages/plugin-fetch/src/generators/__snapshots__/deletePetNoContent/deletePet.ts index d03515c81..bb6c0ce5e 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/deletePetNoContent/deletePet.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/deletePetNoContent/deletePet.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/:petId} */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts b/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts index 56b72240e..ab984857f 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from './FindPetsByTags' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/findByTags} */ export function findPetsByTags( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByTags', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByTags', ...config })) as Unwrappable> } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTagsWithGlobalSecurity/findPetsByTags.ts b/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTagsWithGlobalSecurity/findPetsByTags.ts index 568c2b5bf..24b0deded 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTagsWithGlobalSecurity/findPetsByTags.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTagsWithGlobalSecurity/findPetsByTags.ts @@ -1,18 +1,18 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from './FindPetsByTags' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/findByTags} */ export function findPetsByTags( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'http', scheme: 'bearer' }], ...config }) as Promise< + return withUnwrap(request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'http', scheme: 'bearer' }], ...config })) as Unwrappable< RequestResult > } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/getPetById/getPetById.ts b/packages/plugin-fetch/src/generators/__snapshots__/getPetById/getPetById.ts index 695457e65..5db400e5d 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/getPetById/getPetById.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/getPetById/getPetById.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/:petId} */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/getPetByIdWithMultipleSchemes/getPetById.ts b/packages/plugin-fetch/src/generators/__snapshots__/getPetByIdWithMultipleSchemes/getPetById.ts index b0481cf25..81cb173de 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/getPetByIdWithMultipleSchemes/getPetById.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/getPetByIdWithMultipleSchemes/getPetById.ts @@ -1,21 +1,18 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/:petId} */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }), + ) as Unwrappable> } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/getProject/getProject.ts b/packages/plugin-fetch/src/generators/__snapshots__/getProject/getProject.ts index e82d50621..e5489beb6 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/getProject/getProject.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/getProject/getProject.ts @@ -1,16 +1,16 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /projects/:project_id} */ export function getProject( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts b/packages/plugin-fetch/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts index eea2dbbc7..e9efb1c8a 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts @@ -1,21 +1,23 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { ListPetsStyledOptions, ListPetsStyledResponses } from './ListPetsStyled' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pets/:petId} */ export function listPetsStyled( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pets/{petId}', - styles: { path: { petId: { style: 'matrix', explode: true } }, query: { tags: { style: 'pipeDelimited', explode: false } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pets/{petId}', + styles: { path: { petId: { style: 'matrix', explode: true } }, query: { tags: { style: 'pipeDelimited', explode: false } } }, + ...config, + }), + ) as Unwrappable> } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/petClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/petClient.ts index 1955a4ead..9dc693850 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/petClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/petClient.ts @@ -1,9 +1,9 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class PetClient { private readonly client: ClientInstance @@ -17,10 +17,10 @@ export class PetClient { */ public getPetById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -28,9 +28,9 @@ export class PetClient { */ public deletePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/projectClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/projectClient.ts index 1dd660841..345af6331 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/projectClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/projectClient.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class ProjectClient { private readonly client: ClientInstance @@ -16,9 +16,9 @@ export class ProjectClient { */ public getProject( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/storeClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/storeClient.ts index 4dc93913f..4993cf2b7 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/storeClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/storeClient.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from './GetInventory' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class StoreClient { private readonly client: ClientInstance @@ -16,9 +16,9 @@ export class StoreClient { */ public getInventory( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/petClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/petClient.ts index 1955a4ead..9dc693850 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/petClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/petClient.ts @@ -1,9 +1,9 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class PetClient { private readonly client: ClientInstance @@ -17,10 +17,10 @@ export class PetClient { */ public getPetById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -28,9 +28,9 @@ export class PetClient { */ public deletePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/projectClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/projectClient.ts index 1dd660841..345af6331 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/projectClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/projectClient.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class ProjectClient { private readonly client: ClientInstance @@ -16,9 +16,9 @@ export class ProjectClient { */ public getProject( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/storeClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/storeClient.ts index 4dc93913f..4993cf2b7 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/storeClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/storeClient.ts @@ -1,8 +1,8 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from './GetInventory' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class StoreClient { private readonly client: ClientInstance @@ -16,9 +16,9 @@ export class StoreClient { */ public getInventory( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithSecurity/petStore.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithSecurity/petStore.ts index df57dc8d8..2fafe6c8d 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithSecurity/petStore.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithSecurity/petStore.ts @@ -1,11 +1,11 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' import type { GetInventoryOptions, GetInventoryResponses } from './GetInventory' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class PetStore { private readonly client: ClientInstance @@ -19,15 +19,12 @@ export class PetStore { */ public getPetById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }), + ) as Unwrappable> } /** @@ -35,10 +32,10 @@ export class PetStore { */ public deletePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -46,10 +43,10 @@ export class PetStore { */ public getInventory( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> } /** @@ -57,9 +54,9 @@ export class PetStore { */ public getProject( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkSingle/petStore.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkSingle/petStore.ts index fea34019d..e453d47d9 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkSingle/petStore.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkSingle/petStore.ts @@ -1,11 +1,11 @@ /* eslint-disable no-alert, no-console */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from './.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from './.kubb/client' import type { DeletePetOptions, DeletePetResponses } from './DeletePet' import type { GetInventoryOptions, GetInventoryResponses } from './GetInventory' import type { GetPetByIdOptions, GetPetByIdResponses } from './GetPetById' import type { GetProjectOptions, GetProjectResponses } from './GetProject' -import { createClient } from './.kubb/client' +import { createClient, withUnwrap } from './.kubb/client' export class PetStore { private readonly client: ClientInstance @@ -19,10 +19,10 @@ export class PetStore { */ public getPetById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -30,10 +30,10 @@ export class PetStore { */ public deletePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> } /** @@ -41,10 +41,10 @@ export class PetStore { */ public getInventory( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> } /** @@ -52,9 +52,9 @@ export class PetStore { */ public getProject( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/uploadFileMultipart/uploadFile.ts b/packages/plugin-fetch/src/generators/__snapshots__/uploadFileMultipart/uploadFile.ts index 55cddb6e0..1c7adffd9 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/uploadFileMultipart/uploadFile.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/uploadFileMultipart/uploadFile.ts @@ -1,18 +1,18 @@ /* eslint-disable no-alert, no-console */ -import type { Options, RequestResult } from './.kubb/client' +import type { Options, Unwrappable, RequestResult } from './.kubb/client' import type { UploadFileOptions, UploadFileResponses } from './UploadFile' -import { client } from './.kubb/client' +import { client, withUnwrap } from './.kubb/client' /** * {@link /pet/:petId/uploadImage} */ export function uploadFile( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', contentType: { request: 'multipart/form-data' }, ...config }) as Promise< + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', contentType: { request: 'multipart/form-data' }, ...config })) as Unwrappable< RequestResult > } diff --git a/packages/plugin-fetch/templates/fetch.test.ts b/packages/plugin-fetch/templates/fetch.test.ts index e2dfc90b9..cba8407c3 100644 --- a/packages/plugin-fetch/templates/fetch.test.ts +++ b/packages/plugin-fetch/templates/fetch.test.ts @@ -10,6 +10,7 @@ import { type ServerSentEvent, type Transport, type TransportResult, + withUnwrap, } from './fetch.ts' import { applyHeaderStyles, defaultBodySerializer, defaultPathSerializer, defaultQuerySerializer, serializeCookies } from './serializers.ts' @@ -649,6 +650,33 @@ describe('getUrl', () => { }) }) +describe('withUnwrap', () => { + test('unwrap() resolves to the success data', async () => { + const { client } = createClient({ data: { id: 1 }, status: 200 }) + const result = await withUnwrap(client({ method: 'GET', url: '/pet/1' }) as Promise>).unwrap() + expect(result).toStrictEqual({ id: 1 }) + }) + + test('unwrap() rejects with error for a non-throwing error result', async () => { + const { client } = createClient({ data: { message: 'invalid' }, status: 405 }) + await expect( + withUnwrap(client({ method: 'POST', url: '/pet', throwOnError: false }) as Promise>).unwrap(), + ).rejects.toStrictEqual({ message: 'invalid' }) + }) + + test('the wrapped promise still resolves to the full result when awaited directly', async () => { + const { client } = createClient({ data: { id: 1 }, status: 200 }) + const result = await withUnwrap(client({ method: 'GET', url: '/pet/1' }) as Promise>) + expect(result.status).toBe(200) + expect(result.data).toStrictEqual({ id: 1 }) + }) + + test('a throwing call rejects before unwrap() has a chance to run', async () => { + const { client } = createClient({ data: { message: 'invalid' }, status: 405 }) + await expect(withUnwrap(client({ method: 'POST', url: '/pet' }) as Promise>).unwrap()).rejects.toBeInstanceOf(ResponseError) + }) +}) + describe('resolveAuth', () => { test('places a bearer token on the Authorization header', async () => { const headers: Record = {} diff --git a/packages/plugin-fetch/templates/fetch.ts b/packages/plugin-fetch/templates/fetch.ts index f80182aca..064cff868 100644 --- a/packages/plugin-fetch/templates/fetch.ts +++ b/packages/plugin-fetch/templates/fetch.ts @@ -82,6 +82,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/clients/updatePet.ts index c8b4a7c7c..9a1ffdbf6 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/clients/updatePet.ts @@ -3,15 +3,15 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../types/UpdatePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * {@link /pets/:pet_id} */ -export function updatePet(options: Options): Promise> { +export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/petClient.ts index 2a7a28beb..4d7cc3e0f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/petClient.ts @@ -3,13 +3,13 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class PetClient { private readonly client: ClientInstance @@ -23,10 +23,10 @@ export class PetClient { * @summary Add a new pet to the store * {@link /pet} */ - public addPet(options: Options): Promise> { + public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -34,10 +34,10 @@ export class PetClient { * @summary Finds Pets by status * {@link /pet/findByStatus} */ - public findPetsByStatus(options: Options = {}): Promise> { + public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -45,10 +45,10 @@ export class PetClient { * @summary Find pet by ID * {@link /pet/:petId} */ - public getPetById(options: Options): Promise> { + public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -56,19 +56,19 @@ export class PetClient { * @summary Deletes a pet * {@link /pet/:petId} */ - public deletePet(options: Options): Promise> { + public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ - public uploadFile(options: Options): Promise> { + public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/storeClient.ts index 174c15837..f647fb5a9 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/storeClient.ts @@ -3,10 +3,10 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class StoreClient { private readonly client: ClientInstance @@ -20,10 +20,10 @@ export class StoreClient { * @summary Returns pet inventories by status * {@link /store/inventory} */ - public getInventory(options: Options = {}): Promise> { + public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } /** @@ -31,9 +31,9 @@ export class StoreClient { * @summary Place an order for a pet * {@link /store/order} */ - public placeOrder(options: Options): Promise> { + public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/petClient.ts index 2a7a28beb..4d7cc3e0f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/petClient.ts @@ -3,13 +3,13 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class PetClient { private readonly client: ClientInstance @@ -23,10 +23,10 @@ export class PetClient { * @summary Add a new pet to the store * {@link /pet} */ - public addPet(options: Options): Promise> { + public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -34,10 +34,10 @@ export class PetClient { * @summary Finds Pets by status * {@link /pet/findByStatus} */ - public findPetsByStatus(options: Options = {}): Promise> { + public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -45,10 +45,10 @@ export class PetClient { * @summary Find pet by ID * {@link /pet/:petId} */ - public getPetById(options: Options): Promise> { + public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -56,19 +56,19 @@ export class PetClient { * @summary Deletes a pet * {@link /pet/:petId} */ - public deletePet(options: Options): Promise> { + public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ - public uploadFile(options: Options): Promise> { + public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/storeClient.ts index 174c15837..f647fb5a9 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/storeClient.ts @@ -3,10 +3,10 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class StoreClient { private readonly client: ClientInstance @@ -20,10 +20,10 @@ export class StoreClient { * @summary Returns pet inventories by status * {@link /store/inventory} */ - public getInventory(options: Options = {}): Promise> { + public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } /** @@ -31,9 +31,9 @@ export class StoreClient { * @summary Place an order for a pet * {@link /store/order} */ - public placeOrder(options: Options): Promise> { + public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/clients/petStore.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/clients/petStore.ts index 2904cdd30..8fab984a5 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/clients/petStore.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/clients/petStore.ts @@ -3,7 +3,7 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' @@ -11,7 +11,7 @@ import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInv import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class PetStore { private readonly client: ClientInstance @@ -25,10 +25,10 @@ export class PetStore { * @summary Add a new pet to the store * {@link /pet} */ - public addPet(options: Options): Promise> { + public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -36,10 +36,10 @@ export class PetStore { * @summary Finds Pets by status * {@link /pet/findByStatus} */ - public findPetsByStatus(options: Options = {}): Promise> { + public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -47,10 +47,10 @@ export class PetStore { * @summary Find pet by ID * {@link /pet/:petId} */ - public getPetById(options: Options): Promise> { + public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -58,20 +58,20 @@ export class PetStore { * @summary Deletes a pet * {@link /pet/:petId} */ - public deletePet(options: Options): Promise> { + public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ - public uploadFile(options: Options): Promise> { + public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -79,10 +79,10 @@ export class PetStore { * @summary Returns pet inventories by status * {@link /store/inventory} */ - public getInventory(options: Options = {}): Promise> { + public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } /** @@ -90,9 +90,9 @@ export class PetStore { * @summary Place an order for a pet * {@link /store/order} */ - public placeOrder(options: Options): Promise> { + public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/addPet.ts index 03d71616a..c1ed606e3 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptionsSchemaType, AddPetResponsesSchemaType } from '../zod/addPetSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' /** @@ -13,8 +13,8 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/deletePet.ts index 245a40ec1..ee540afe9 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptionsSchemaType, DeletePetResponsesSchemaType } from '../zod/deletePetSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetSchema' /** @@ -13,8 +13,8 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/findPetsByStatus.ts index 5065d1d14..e7a914e57 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptionsSchemaType, FindPetsByStatusResponsesSchemaType } from '../zod/findPetsByStatusSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../zod/findPetsByStatusSchema' /** @@ -13,8 +13,8 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getInventory.ts index 83c566b28..37f35c03d 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptionsSchemaType, GetInventoryResponsesSchemaType } from '../zod/getInventorySchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getInventoryResponseSchema } from '../zod/getInventorySchema' /** @@ -13,8 +13,8 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getPetById.ts index c79fe3fd8..40625a0b4 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptionsSchemaType, GetPetByIdResponsesSchemaType } from '../zod/getPetByIdSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetByIdSchema' /** @@ -13,8 +13,8 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/placeOrder.ts index 352496d50..d840043ca 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptionsSchemaType, PlaceOrderResponsesSchemaType } from '../zod/placeOrderSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrderSchema' /** @@ -13,8 +13,8 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/uploadFile.ts index 3c7bf3cc8..8f5c0401f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/uploadFile.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptionsSchemaType, UploadFileResponsesSchemaType } from '../zod/uploadFileSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { uploadFileResponseSchema } from '../zod/uploadFileSchema' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts index f80182aca..064cff868 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts @@ -82,6 +82,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts index f80182aca..064cff868 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts @@ -82,6 +82,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/clients/updatePet.ts index c8b4a7c7c..9a1ffdbf6 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/clients/updatePet.ts @@ -3,15 +3,15 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../types/UpdatePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * {@link /pets/:pet_id} */ -export function updatePet(options: Options): Promise> { +export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts index f80182aca..064cff868 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts @@ -82,6 +82,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/petClient.ts index 2a7a28beb..4d7cc3e0f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/petClient.ts @@ -3,13 +3,13 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class PetClient { private readonly client: ClientInstance @@ -23,10 +23,10 @@ export class PetClient { * @summary Add a new pet to the store * {@link /pet} */ - public addPet(options: Options): Promise> { + public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -34,10 +34,10 @@ export class PetClient { * @summary Finds Pets by status * {@link /pet/findByStatus} */ - public findPetsByStatus(options: Options = {}): Promise> { + public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -45,10 +45,10 @@ export class PetClient { * @summary Find pet by ID * {@link /pet/:petId} */ - public getPetById(options: Options): Promise> { + public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -56,19 +56,19 @@ export class PetClient { * @summary Deletes a pet * {@link /pet/:petId} */ - public deletePet(options: Options): Promise> { + public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ - public uploadFile(options: Options): Promise> { + public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/storeClient.ts index 174c15837..f647fb5a9 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/storeClient.ts @@ -3,10 +3,10 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class StoreClient { private readonly client: ClientInstance @@ -20,10 +20,10 @@ export class StoreClient { * @summary Returns pet inventories by status * {@link /store/inventory} */ - public getInventory(options: Options = {}): Promise> { + public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } /** @@ -31,9 +31,9 @@ export class StoreClient { * @summary Place an order for a pet * {@link /store/order} */ - public placeOrder(options: Options): Promise> { + public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts index f80182aca..064cff868 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts @@ -82,6 +82,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/petClient.ts index 2a7a28beb..4d7cc3e0f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/petClient.ts @@ -3,13 +3,13 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class PetClient { private readonly client: ClientInstance @@ -23,10 +23,10 @@ export class PetClient { * @summary Add a new pet to the store * {@link /pet} */ - public addPet(options: Options): Promise> { + public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -34,10 +34,10 @@ export class PetClient { * @summary Finds Pets by status * {@link /pet/findByStatus} */ - public findPetsByStatus(options: Options = {}): Promise> { + public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -45,10 +45,10 @@ export class PetClient { * @summary Find pet by ID * {@link /pet/:petId} */ - public getPetById(options: Options): Promise> { + public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -56,19 +56,19 @@ export class PetClient { * @summary Deletes a pet * {@link /pet/:petId} */ - public deletePet(options: Options): Promise> { + public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ - public uploadFile(options: Options): Promise> { + public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/storeClient.ts index 174c15837..f647fb5a9 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/storeClient.ts @@ -3,10 +3,10 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class StoreClient { private readonly client: ClientInstance @@ -20,10 +20,10 @@ export class StoreClient { * @summary Returns pet inventories by status * {@link /store/inventory} */ - public getInventory(options: Options = {}): Promise> { + public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } /** @@ -31,9 +31,9 @@ export class StoreClient { * @summary Place an order for a pet * {@link /store/order} */ - public placeOrder(options: Options): Promise> { + public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts index f80182aca..064cff868 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts @@ -82,6 +82,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/clients/petStore.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/clients/petStore.ts index 2904cdd30..8fab984a5 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/clients/petStore.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/clients/petStore.ts @@ -3,7 +3,7 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' @@ -11,7 +11,7 @@ import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInv import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' export class PetStore { private readonly client: ClientInstance @@ -25,10 +25,10 @@ export class PetStore { * @summary Add a new pet to the store * {@link /pet} */ - public addPet(options: Options): Promise> { + public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -36,10 +36,10 @@ export class PetStore { * @summary Finds Pets by status * {@link /pet/findByStatus} */ - public findPetsByStatus(options: Options = {}): Promise> { + public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -47,10 +47,10 @@ export class PetStore { * @summary Find pet by ID * {@link /pet/:petId} */ - public getPetById(options: Options): Promise> { + public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -58,20 +58,20 @@ export class PetStore { * @summary Deletes a pet * {@link /pet/:petId} */ - public deletePet(options: Options): Promise> { + public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ - public uploadFile(options: Options): Promise> { + public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } /** @@ -79,10 +79,10 @@ export class PetStore { * @summary Returns pet inventories by status * {@link /store/inventory} */ - public getInventory(options: Options = {}): Promise> { + public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } /** @@ -90,9 +90,9 @@ export class PetStore { * @summary Place an order for a pet * {@link /store/order} */ - public placeOrder(options: Options): Promise> { + public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts index f80182aca..064cff868 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts @@ -82,6 +82,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/addPet.ts index 03d71616a..c1ed606e3 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptionsSchemaType, AddPetResponsesSchemaType } from '../zod/addPetSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' /** @@ -13,8 +13,8 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/deletePet.ts index 245a40ec1..ee540afe9 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptionsSchemaType, DeletePetResponsesSchemaType } from '../zod/deletePetSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetSchema' /** @@ -13,8 +13,8 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/findPetsByStatus.ts index 5065d1d14..e7a914e57 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptionsSchemaType, FindPetsByStatusResponsesSchemaType } from '../zod/findPetsByStatusSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../zod/findPetsByStatusSchema' /** @@ -13,8 +13,8 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getInventory.ts index 83c566b28..37f35c03d 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptionsSchemaType, GetInventoryResponsesSchemaType } from '../zod/getInventorySchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getInventoryResponseSchema } from '../zod/getInventorySchema' /** @@ -13,8 +13,8 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getPetById.ts index c79fe3fd8..40625a0b4 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptionsSchemaType, GetPetByIdResponsesSchemaType } from '../zod/getPetByIdSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetByIdSchema' /** @@ -13,8 +13,8 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/placeOrder.ts index 352496d50..d840043ca 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptionsSchemaType, PlaceOrderResponsesSchemaType } from '../zod/placeOrderSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrderSchema' /** @@ -13,8 +13,8 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/uploadFile.ts index 3c7bf3cc8..8f5c0401f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/uploadFile.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptionsSchemaType, UploadFileResponsesSchemaType } from '../zod/uploadFileSchema' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { uploadFileResponseSchema } from '../zod/uploadFileSchema' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts index f80182aca..064cff868 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts @@ -82,6 +82,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/petClient.ts index eef8fd252..ad22132e1 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/petClient.ts @@ -3,13 +3,13 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptionsSchemaType, AddPetResponsesSchemaType } from '../zod/addPetSchema' import type { DeletePetOptionsSchemaType, DeletePetResponsesSchemaType } from '../zod/deletePetSchema' import type { FindPetsByStatusOptionsSchemaType, FindPetsByStatusResponsesSchemaType } from '../zod/findPetsByStatusSchema' import type { GetPetByIdOptionsSchemaType, GetPetByIdResponsesSchemaType } from '../zod/getPetByIdSchema' import type { UploadFileOptionsSchemaType, UploadFileResponsesSchemaType } from '../zod/uploadFileSchema' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' import { addPetResponseSchema } from '../zod/addPetSchema' import { deletePetResponseSchema } from '../zod/deletePetSchema' import { findPetsByStatusResponseSchema } from '../zod/findPetsByStatusSchema' @@ -28,10 +28,10 @@ export class PetClient { * @summary Add a new pet to the store * {@link /pet} */ - public addPet(options: Options): Promise> { + public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema }, ...config })) as Unwrappable> } /** @@ -39,10 +39,10 @@ export class PetClient { * @summary Finds Pets by status * {@link /pet/findByStatus} */ - public findPetsByStatus(options: Options = {}): Promise> { + public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], validator: { response: findPetsByStatusResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], validator: { response: findPetsByStatusResponseSchema }, ...config })) as Unwrappable> } /** @@ -50,10 +50,10 @@ export class PetClient { * @summary Find pet by ID * {@link /pet/:petId} */ - public getPetById(options: Options): Promise> { + public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema }, ...config })) as Unwrappable> } /** @@ -61,19 +61,19 @@ export class PetClient { * @summary Deletes a pet * {@link /pet/:petId} */ - public deletePet(options: Options): Promise> { + public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema }, ...config })) as Unwrappable> } /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ - public uploadFile(options: Options): Promise> { + public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/storeClient.ts index 6e71f3733..3ecac617c 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/storeClient.ts @@ -3,10 +3,10 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptionsSchemaType, GetInventoryResponsesSchemaType } from '../zod/getInventorySchema' import type { PlaceOrderOptionsSchemaType, PlaceOrderResponsesSchemaType } from '../zod/placeOrderSchema' -import { createClient } from '../.kubb/client' +import { createClient, withUnwrap } from '../.kubb/client' import { getInventoryResponseSchema } from '../zod/getInventorySchema' import { placeOrderResponseSchema } from '../zod/placeOrderSchema' @@ -22,10 +22,10 @@ export class StoreClient { * @summary Returns pet inventories by status * {@link /store/inventory} */ - public getInventory(options: Options = {}): Promise> { + public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> } /** @@ -33,9 +33,9 @@ export class StoreClient { * @summary Place an order for a pet * {@link /store/order} */ - public placeOrder(options: Options): Promise> { + public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema }, ...config })) as Unwrappable> } } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/clients/updatePet.ts index c8b4a7c7c..9a1ffdbf6 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/clients/updatePet.ts @@ -3,15 +3,15 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../types/UpdatePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * {@link /pets/:pet_id} */ -export function updatePet(options: Options): Promise> { +export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/clients/updatePet.ts index c8b4a7c7c..9a1ffdbf6 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/clients/updatePet.ts @@ -3,15 +3,15 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../types/UpdatePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * {@link /pets/:pet_id} */ -export function updatePet(options: Options): Promise> { +export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/addPet.ts index 7e5366344..b23f13436 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' /** @@ -13,8 +13,8 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/deletePet.ts index 3d3119966..28ebb6b60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetSchema' /** @@ -13,8 +13,8 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/findPetsByStatus.ts index 2d39d3b70..b72b584bc 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../zod/findPetsByStatusSchema' /** @@ -13,8 +13,8 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getInventory.ts index f4ed2eda7..c8641d728 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getInventoryResponseSchema } from '../zod/getInventorySchema' /** @@ -13,8 +13,8 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getPetById.ts index aacafef77..ae2bf7db4 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetByIdSchema' /** @@ -13,8 +13,8 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/placeOrder.ts index 17d73dae2..a184c8097 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrderSchema' /** @@ -13,8 +13,8 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/uploadFile.ts index 4933c1401..35ccd738b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/uploadFile.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { uploadFileResponseSchema } from '../zod/uploadFileSchema' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/clients/updatePet.ts index c8b4a7c7c..9a1ffdbf6 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/clients/updatePet.ts @@ -3,15 +3,15 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../types/UpdatePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * {@link /pets/:pet_id} */ -export function updatePet(options: Options): Promise> { +export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/addPet.ts index 7e5366344..b23f13436 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' /** @@ -13,8 +13,8 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/deletePet.ts index 3d3119966..28ebb6b60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetSchema' /** @@ -13,8 +13,8 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/findPetsByStatus.ts index 2d39d3b70..b72b584bc 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../zod/findPetsByStatusSchema' /** @@ -13,8 +13,8 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getInventory.ts index f4ed2eda7..c8641d728 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getInventoryResponseSchema } from '../zod/getInventorySchema' /** @@ -13,8 +13,8 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getPetById.ts index aacafef77..ae2bf7db4 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetByIdSchema' /** @@ -13,8 +13,8 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/placeOrder.ts index 17d73dae2..a184c8097 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrderSchema' /** @@ -13,8 +13,8 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/uploadFile.ts index 4933c1401..35ccd738b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/uploadFile.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { uploadFileResponseSchema } from '../zod/uploadFileSchema' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/clients/updatePet.ts index c8b4a7c7c..9a1ffdbf6 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/clients/updatePet.ts @@ -3,15 +3,15 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../types/UpdatePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * {@link /pets/:pet_id} */ -export function updatePet(options: Options): Promise> { +export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/addPet.ts index 7e5366344..b23f13436 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' /** @@ -13,8 +13,8 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/deletePet.ts index 3d3119966..28ebb6b60 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetSchema' /** @@ -13,8 +13,8 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/findPetsByStatus.ts index 2d39d3b70..b72b584bc 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../zod/findPetsByStatusSchema' /** @@ -13,8 +13,8 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getInventory.ts index f4ed2eda7..c8641d728 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getInventoryResponseSchema } from '../zod/getInventorySchema' /** @@ -13,8 +13,8 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getPetById.ts index aacafef77..ae2bf7db4 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetByIdSchema' /** @@ -13,8 +13,8 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/placeOrder.ts index 17d73dae2..a184c8097 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrderSchema' /** @@ -13,8 +13,8 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/uploadFile.ts index 4933c1401..35ccd738b 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/uploadFile.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' import { uploadFileResponseSchema } from '../zod/uploadFileSchema' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts index d928c18f3..bc1594660 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts @@ -84,6 +84,34 @@ export type RequestResult +/** + * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an + * error variant's `data: undefined` can never widen it. + */ +export type UnwrapResult = Extract['data'] + +/** + * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` + * resolves to the bare success body, or rejects with `error` for a result that carried one + * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). + */ +export type Unwrappable = Promise & { unwrap: () => Promise> } + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result + * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap + * (`await getPetById(...).unwrap()`). + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as UnwrapResult + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/addPet.ts index 038e01e98..405aef6c7 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/addPet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../types/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store * @summary Add a new pet to the store * {@link /pet} */ -export function addPet(options: Options): Promise> { +export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/deletePet.ts index 2dba7ae21..465cb186c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/deletePet.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../types/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet * @summary Deletes a pet * {@link /pet/:petId} */ -export function deletePet(options: Options): Promise> { +export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/findPetsByStatus.ts index c6309f1e6..188f7d37a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/findPetsByStatus.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../types/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings * @summary Finds Pets by status * {@link /pet/findByStatus} */ -export function findPetsByStatus(options: Options = {}): Promise> { +export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getInventory.ts index dd8f690d1..a27010532 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getInventory.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../types/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities * @summary Returns pet inventories by status * {@link /store/inventory} */ -export function getInventory(options: Options = {}): Promise> { +export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getPetById.ts index d8f3570c3..22a08cf60 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getPetById.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../types/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet * @summary Find pet by ID * {@link /pet/:petId} */ -export function getPetById(options: Options): Promise> { +export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/placeOrder.ts index 2ec2f2839..2fd356056 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/placeOrder.ts @@ -3,17 +3,17 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../types/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store * @summary Place an order for a pet * {@link /store/order} */ -export function placeOrder(options: Options): Promise> { +export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/uploadFile.ts index 77a4938ef..7df4aba6b 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/uploadFile.ts @@ -3,16 +3,16 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../types/UploadFile' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image * {@link /pet/:petId/uploadImage} */ -export function uploadFile(options: Options): Promise> { +export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> } From d68ef060c9576fd76b305995d8f24b54a8c050d7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 20:43:56 +0000 Subject: [PATCH 2/9] fix(plugin-axios,plugin-fetch): cast to RequestResult before wrapping in withUnwrap CI caught this on this repo's own examples/axios: an operation with no documented 2xx response (deletePet, 400 only) failed to typecheck. withUnwrap(request(callConfig)) inferred its generic from the client's own CallResult type, so the outer `as Unwrappable>` cast carried two incompatible `.then` overloads and TypeScript rejected it as too narrow a conversion. Casting the call to RequestResult first, then wrapping, keeps withUnwrap's generic inferred as RequestResult directly, matching what the code did before this feature and avoiding the second cast entirely. Reproduced the exact failure in isolation, confirmed the fix, then verified end-to-end with a real `pnpm generate` against a built plugin-axios (this sandbox has no prebuilt dist, so pnpm generate otherwise fails to resolve the plugin). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN --- .../client/src/builders/returnStatement.test.ts | 4 ++-- .../client/src/builders/returnStatement.ts | 17 +++++++++++------ .../__snapshots__/addPetMultiStatus/addPet.ts | 2 +- .../addPetMultiStatusWithZod/addPet.ts | 6 +++--- .../deletePetNoContent/deletePet.ts | 2 +- .../findPetsByTags/findPetsByTags.ts | 2 +- .../__snapshots__/getPetById/getPetById.ts | 2 +- .../getPetByIdWithSecurity/getPetById.ts | 6 ++++-- .../__snapshots__/getProject/getProject.ts | 2 +- .../listPetsWithStyles/listPetsStyled.ts | 4 ++-- .../__snapshots__/sdkClass/petClient.ts | 4 ++-- .../__snapshots__/sdkClass/projectClient.ts | 2 +- .../__snapshots__/sdkClass/storeClient.ts | 2 +- .../__snapshots__/sdkClassWithName/petClient.ts | 4 ++-- .../sdkClassWithName/projectClient.ts | 2 +- .../sdkClassWithName/storeClient.ts | 2 +- .../__snapshots__/sdkSingle/petStore.ts | 8 ++++---- .../__snapshots__/addPetMultiStatus/addPet.ts | 2 +- .../addPetMultiStatusWithZod/addPet.ts | 6 +++--- .../__snapshots__/addPetWithSecurity/addPet.ts | 6 +++--- .../deletePetNoContent/deletePet.ts | 2 +- .../findPetsByTags/findPetsByTags.ts | 2 +- .../findPetsByTags.ts | 8 +++++--- .../__snapshots__/getPetById/getPetById.ts | 2 +- .../getPetByIdWithMultipleSchemes/getPetById.ts | 6 ++++-- .../__snapshots__/getProject/getProject.ts | 2 +- .../listPetsWithStyles/listPetsStyled.ts | 4 ++-- .../__snapshots__/sdkClass/petClient.ts | 4 ++-- .../__snapshots__/sdkClass/projectClient.ts | 2 +- .../__snapshots__/sdkClass/storeClient.ts | 2 +- .../__snapshots__/sdkClassWithName/petClient.ts | 4 ++-- .../sdkClassWithName/projectClient.ts | 2 +- .../sdkClassWithName/storeClient.ts | 2 +- .../sdkClassWithSecurity/petStore.ts | 12 +++++++----- .../__snapshots__/sdkSingle/petStore.ts | 8 ++++---- .../uploadFileMultipart/uploadFile.ts | 8 +++++--- .../pluginAxios/default/clients/addPet.ts | 2 +- .../pluginAxios/default/clients/deletePet.ts | 2 +- .../default/clients/findPetsByStatus.ts | 2 +- .../pluginAxios/default/clients/getInventory.ts | 2 +- .../pluginAxios/default/clients/getPetById.ts | 2 +- .../pluginAxios/default/clients/placeOrder.ts | 2 +- .../pluginAxios/default/clients/uploadFile.ts | 2 +- .../paramsCasing/clients/updatePet.ts | 2 +- .../pluginAxios/sdkClass/clients/petClient.ts | 10 +++++----- .../pluginAxios/sdkClass/clients/storeClient.ts | 4 ++-- .../sdkClassWithName/clients/petClient.ts | 10 +++++----- .../sdkClassWithName/clients/storeClient.ts | 4 ++-- .../pluginAxios/sdkSingle/clients/petStore.ts | 14 +++++++------- .../pluginAxios/zodTypes/clients/addPet.ts | 2 +- .../pluginAxios/zodTypes/clients/deletePet.ts | 2 +- .../zodTypes/clients/findPetsByStatus.ts | 2 +- .../zodTypes/clients/getInventory.ts | 2 +- .../pluginAxios/zodTypes/clients/getPetById.ts | 2 +- .../pluginAxios/zodTypes/clients/placeOrder.ts | 2 +- .../pluginAxios/zodTypes/clients/uploadFile.ts | 2 +- .../pluginFetch/default/clients/addPet.ts | 2 +- .../pluginFetch/default/clients/deletePet.ts | 2 +- .../default/clients/findPetsByStatus.ts | 2 +- .../pluginFetch/default/clients/getInventory.ts | 2 +- .../pluginFetch/default/clients/getPetById.ts | 2 +- .../pluginFetch/default/clients/placeOrder.ts | 2 +- .../pluginFetch/default/clients/uploadFile.ts | 2 +- .../paramsCasing/clients/updatePet.ts | 2 +- .../pluginFetch/sdkClass/clients/petClient.ts | 10 +++++----- .../pluginFetch/sdkClass/clients/storeClient.ts | 4 ++-- .../sdkClassWithName/clients/petClient.ts | 10 +++++----- .../sdkClassWithName/clients/storeClient.ts | 4 ++-- .../pluginFetch/sdkSingle/clients/petStore.ts | 14 +++++++------- .../pluginFetch/zodTypes/clients/addPet.ts | 2 +- .../pluginFetch/zodTypes/clients/deletePet.ts | 2 +- .../zodTypes/clients/findPetsByStatus.ts | 2 +- .../zodTypes/clients/getInventory.ts | 2 +- .../pluginFetch/zodTypes/clients/getPetById.ts | 2 +- .../pluginFetch/zodTypes/clients/placeOrder.ts | 2 +- .../pluginFetch/zodTypes/clients/uploadFile.ts | 2 +- .../zodTypesSdk/clients/petClient.ts | 10 +++++----- .../zodTypesSdk/clients/storeClient.ts | 4 ++-- .../excludeByOperationId/clients/addPet.ts | 2 +- .../excludeByOperationId/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../clients/getInventory.ts | 2 +- .../excludeByOperationId/clients/getPetById.ts | 2 +- .../excludeByOperationId/clients/placeOrder.ts | 2 +- .../excludeByOperationId/clients/uploadFile.ts | 2 +- .../pluginMcp/groupByTag/clients/addPet.ts | 2 +- .../pluginMcp/groupByTag/clients/deletePet.ts | 2 +- .../groupByTag/clients/findPetsByStatus.ts | 2 +- .../groupByTag/clients/getInventory.ts | 2 +- .../pluginMcp/groupByTag/clients/getPetById.ts | 2 +- .../pluginMcp/groupByTag/clients/placeOrder.ts | 2 +- .../pluginMcp/groupByTag/clients/uploadFile.ts | 2 +- .../pluginMcp/includeByTag/clients/addPet.ts | 2 +- .../pluginMcp/includeByTag/clients/deletePet.ts | 2 +- .../includeByTag/clients/findPetsByStatus.ts | 2 +- .../includeByTag/clients/getInventory.ts | 2 +- .../includeByTag/clients/getPetById.ts | 2 +- .../includeByTag/clients/placeOrder.ts | 2 +- .../includeByTag/clients/uploadFile.ts | 2 +- .../pluginMcp/paramsCasing/clients/updatePet.ts | 2 +- .../pluginMcp/petStore/clients/addPet.ts | 2 +- .../pluginMcp/petStore/clients/deletePet.ts | 2 +- .../petStore/clients/findPetsByStatus.ts | 2 +- .../pluginMcp/petStore/clients/getInventory.ts | 2 +- .../pluginMcp/petStore/clients/getPetById.ts | 2 +- .../pluginMcp/petStore/clients/placeOrder.ts | 2 +- .../pluginMcp/petStore/clients/uploadFile.ts | 2 +- .../withClientPlugin/clients/addPet.ts | 2 +- .../withClientPlugin/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../withClientPlugin/clients/getInventory.ts | 2 +- .../withClientPlugin/clients/getPetById.ts | 2 +- .../withClientPlugin/clients/placeOrder.ts | 2 +- .../withClientPlugin/clients/uploadFile.ts | 2 +- .../excludeByOperationId/clients/addPet.ts | 2 +- .../excludeByOperationId/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../clients/getInventory.ts | 2 +- .../excludeByOperationId/clients/getPetById.ts | 2 +- .../excludeByOperationId/clients/placeOrder.ts | 2 +- .../excludeByOperationId/clients/uploadFile.ts | 2 +- .../groupByTag/clients/addPet.ts | 2 +- .../groupByTag/clients/deletePet.ts | 2 +- .../groupByTag/clients/findPetsByStatus.ts | 2 +- .../groupByTag/clients/getInventory.ts | 2 +- .../groupByTag/clients/getPetById.ts | 2 +- .../groupByTag/clients/placeOrder.ts | 2 +- .../groupByTag/clients/uploadFile.ts | 2 +- .../includeByTag/clients/addPet.ts | 2 +- .../includeByTag/clients/deletePet.ts | 2 +- .../includeByTag/clients/findPetsByStatus.ts | 2 +- .../includeByTag/clients/getInventory.ts | 2 +- .../includeByTag/clients/getPetById.ts | 2 +- .../includeByTag/clients/placeOrder.ts | 2 +- .../includeByTag/clients/uploadFile.ts | 2 +- .../pluginReactQuery/infinite/clients/addPet.ts | 2 +- .../infinite/clients/deletePet.ts | 2 +- .../infinite/clients/findPetsByStatus.ts | 2 +- .../infinite/clients/getInventory.ts | 2 +- .../infinite/clients/getPetById.ts | 2 +- .../infinite/clients/placeOrder.ts | 2 +- .../infinite/clients/uploadFile.ts | 2 +- .../mutationDisabled/clients/addPet.ts | 2 +- .../mutationDisabled/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../mutationDisabled/clients/getInventory.ts | 2 +- .../mutationDisabled/clients/getPetById.ts | 2 +- .../mutationDisabled/clients/placeOrder.ts | 2 +- .../mutationDisabled/clients/uploadFile.ts | 2 +- .../paramsCasing/clients/updatePet.ts | 2 +- .../parserZod/clients/addPet.ts | 2 +- .../parserZod/clients/deletePet.ts | 2 +- .../parserZod/clients/findPetsByStatus.ts | 2 +- .../parserZod/clients/getInventory.ts | 2 +- .../parserZod/clients/getPetById.ts | 2 +- .../parserZod/clients/placeOrder.ts | 2 +- .../parserZod/clients/uploadFile.ts | 2 +- .../pluginReactQuery/petStore/clients/addPet.ts | 2 +- .../petStore/clients/deletePet.ts | 2 +- .../petStore/clients/findPetsByStatus.ts | 2 +- .../petStore/clients/getInventory.ts | 2 +- .../petStore/clients/getPetById.ts | 2 +- .../petStore/clients/placeOrder.ts | 2 +- .../petStore/clients/uploadFile.ts | 2 +- .../queryMethods/clients/addPet.ts | 2 +- .../queryMethods/clients/deletePet.ts | 2 +- .../queryMethods/clients/findPetsByStatus.ts | 2 +- .../queryMethods/clients/getInventory.ts | 2 +- .../queryMethods/clients/getPetById.ts | 2 +- .../queryMethods/clients/placeOrder.ts | 2 +- .../queryMethods/clients/uploadFile.ts | 2 +- .../pluginReactQuery/suspense/clients/addPet.ts | 2 +- .../suspense/clients/deletePet.ts | 2 +- .../suspense/clients/findPetsByStatus.ts | 2 +- .../suspense/clients/getInventory.ts | 2 +- .../suspense/clients/getPetById.ts | 2 +- .../suspense/clients/placeOrder.ts | 2 +- .../suspense/clients/uploadFile.ts | 2 +- .../withClientPlugin/clients/addPet.ts | 2 +- .../withClientPlugin/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../withClientPlugin/clients/getInventory.ts | 2 +- .../withClientPlugin/clients/getPetById.ts | 2 +- .../withClientPlugin/clients/placeOrder.ts | 2 +- .../withClientPlugin/clients/uploadFile.ts | 2 +- .../excludeByOperationId/clients/addPet.ts | 2 +- .../excludeByOperationId/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../clients/getInventory.ts | 2 +- .../excludeByOperationId/clients/getPetById.ts | 2 +- .../excludeByOperationId/clients/placeOrder.ts | 2 +- .../excludeByOperationId/clients/uploadFile.ts | 2 +- .../pluginSwr/groupByTag/clients/addPet.ts | 2 +- .../pluginSwr/groupByTag/clients/deletePet.ts | 2 +- .../groupByTag/clients/findPetsByStatus.ts | 2 +- .../groupByTag/clients/getInventory.ts | 2 +- .../pluginSwr/groupByTag/clients/getPetById.ts | 2 +- .../pluginSwr/groupByTag/clients/placeOrder.ts | 2 +- .../pluginSwr/groupByTag/clients/uploadFile.ts | 2 +- .../pluginSwr/includeByTag/clients/addPet.ts | 2 +- .../pluginSwr/includeByTag/clients/deletePet.ts | 2 +- .../includeByTag/clients/findPetsByStatus.ts | 2 +- .../includeByTag/clients/getInventory.ts | 2 +- .../includeByTag/clients/getPetById.ts | 2 +- .../includeByTag/clients/placeOrder.ts | 2 +- .../includeByTag/clients/uploadFile.ts | 2 +- .../mutationDisabled/clients/addPet.ts | 2 +- .../mutationDisabled/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../mutationDisabled/clients/getInventory.ts | 2 +- .../mutationDisabled/clients/getPetById.ts | 2 +- .../mutationDisabled/clients/placeOrder.ts | 2 +- .../mutationDisabled/clients/uploadFile.ts | 2 +- .../pluginSwr/paramsCasing/clients/updatePet.ts | 2 +- .../pluginSwr/parserZod/clients/addPet.ts | 2 +- .../pluginSwr/parserZod/clients/deletePet.ts | 2 +- .../parserZod/clients/findPetsByStatus.ts | 2 +- .../pluginSwr/parserZod/clients/getInventory.ts | 2 +- .../pluginSwr/parserZod/clients/getPetById.ts | 2 +- .../pluginSwr/parserZod/clients/placeOrder.ts | 2 +- .../pluginSwr/parserZod/clients/uploadFile.ts | 2 +- .../pluginSwr/petStore/clients/addPet.ts | 2 +- .../pluginSwr/petStore/clients/deletePet.ts | 2 +- .../petStore/clients/findPetsByStatus.ts | 2 +- .../pluginSwr/petStore/clients/getInventory.ts | 2 +- .../pluginSwr/petStore/clients/getPetById.ts | 2 +- .../pluginSwr/petStore/clients/placeOrder.ts | 2 +- .../pluginSwr/petStore/clients/uploadFile.ts | 2 +- .../pluginSwr/queryDisabled/clients/addPet.ts | 2 +- .../queryDisabled/clients/deletePet.ts | 2 +- .../queryDisabled/clients/findPetsByStatus.ts | 2 +- .../queryDisabled/clients/getInventory.ts | 2 +- .../queryDisabled/clients/getPetById.ts | 2 +- .../queryDisabled/clients/placeOrder.ts | 2 +- .../queryDisabled/clients/uploadFile.ts | 2 +- .../pluginSwr/queryMethods/clients/addPet.ts | 2 +- .../pluginSwr/queryMethods/clients/deletePet.ts | 2 +- .../queryMethods/clients/findPetsByStatus.ts | 2 +- .../queryMethods/clients/getInventory.ts | 2 +- .../queryMethods/clients/getPetById.ts | 2 +- .../queryMethods/clients/placeOrder.ts | 2 +- .../queryMethods/clients/uploadFile.ts | 2 +- .../withClientPlugin/clients/addPet.ts | 2 +- .../withClientPlugin/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../withClientPlugin/clients/getInventory.ts | 2 +- .../withClientPlugin/clients/getPetById.ts | 2 +- .../withClientPlugin/clients/placeOrder.ts | 2 +- .../withClientPlugin/clients/uploadFile.ts | 2 +- .../excludeByOperationId/clients/addPet.ts | 2 +- .../excludeByOperationId/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../clients/getInventory.ts | 2 +- .../excludeByOperationId/clients/getPetById.ts | 2 +- .../excludeByOperationId/clients/placeOrder.ts | 2 +- .../excludeByOperationId/clients/uploadFile.ts | 2 +- .../pluginVueQuery/groupByTag/clients/addPet.ts | 2 +- .../groupByTag/clients/deletePet.ts | 2 +- .../groupByTag/clients/findPetsByStatus.ts | 2 +- .../groupByTag/clients/getInventory.ts | 2 +- .../groupByTag/clients/getPetById.ts | 2 +- .../groupByTag/clients/placeOrder.ts | 2 +- .../groupByTag/clients/uploadFile.ts | 2 +- .../includeByTag/clients/addPet.ts | 2 +- .../includeByTag/clients/deletePet.ts | 2 +- .../includeByTag/clients/findPetsByStatus.ts | 2 +- .../includeByTag/clients/getInventory.ts | 2 +- .../includeByTag/clients/getPetById.ts | 2 +- .../includeByTag/clients/placeOrder.ts | 2 +- .../includeByTag/clients/uploadFile.ts | 2 +- .../pluginVueQuery/infinite/clients/addPet.ts | 2 +- .../infinite/clients/deletePet.ts | 2 +- .../infinite/clients/findPetsByStatus.ts | 2 +- .../infinite/clients/getInventory.ts | 2 +- .../infinite/clients/getPetById.ts | 2 +- .../infinite/clients/placeOrder.ts | 2 +- .../infinite/clients/uploadFile.ts | 2 +- .../mutationDisabled/clients/addPet.ts | 2 +- .../mutationDisabled/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../mutationDisabled/clients/getInventory.ts | 2 +- .../mutationDisabled/clients/getPetById.ts | 2 +- .../mutationDisabled/clients/placeOrder.ts | 2 +- .../mutationDisabled/clients/uploadFile.ts | 2 +- .../paramsCasing/clients/updatePet.ts | 2 +- .../pluginVueQuery/parserZod/clients/addPet.ts | 2 +- .../parserZod/clients/deletePet.ts | 2 +- .../parserZod/clients/findPetsByStatus.ts | 2 +- .../parserZod/clients/getInventory.ts | 2 +- .../parserZod/clients/getPetById.ts | 2 +- .../parserZod/clients/placeOrder.ts | 2 +- .../parserZod/clients/uploadFile.ts | 2 +- .../pluginVueQuery/petStore/clients/addPet.ts | 2 +- .../petStore/clients/deletePet.ts | 2 +- .../petStore/clients/findPetsByStatus.ts | 2 +- .../petStore/clients/getInventory.ts | 2 +- .../petStore/clients/getPetById.ts | 2 +- .../petStore/clients/placeOrder.ts | 2 +- .../petStore/clients/uploadFile.ts | 2 +- .../withClientPlugin/clients/addPet.ts | 2 +- .../withClientPlugin/clients/deletePet.ts | 2 +- .../clients/findPetsByStatus.ts | 2 +- .../withClientPlugin/clients/getInventory.ts | 2 +- .../withClientPlugin/clients/getPetById.ts | 2 +- .../withClientPlugin/clients/placeOrder.ts | 2 +- .../withClientPlugin/clients/uploadFile.ts | 2 +- 306 files changed, 392 insertions(+), 377 deletions(-) diff --git a/internals/client/src/builders/returnStatement.test.ts b/internals/client/src/builders/returnStatement.test.ts index c187454ca..89a21ac21 100644 --- a/internals/client/src/builders/returnStatement.test.ts +++ b/internals/client/src/builders/returnStatement.test.ts @@ -12,10 +12,10 @@ const node = ast.factory.createOperation({ }) describe('buildReturnStatement', () => { - test('wraps the call in withUnwrap and casts to the operation Unwrappable', () => { + test('casts to RequestResult first, then wraps the call in withUnwrap', () => { const callConfig = "{ method: 'POST', url: '/pet', ...config }" expect(buildReturnStatement({ node, types: resolverTs, callConfig })).toBe( - "return withUnwrap(request({ method: 'POST', url: '/pet', ...config })) as Unwrappable>", + "return withUnwrap(request({ method: 'POST', url: '/pet', ...config }) as Promise>)", ) }) }) diff --git a/internals/client/src/builders/returnStatement.ts b/internals/client/src/builders/returnStatement.ts index f59400dcb..f5382745d 100644 --- a/internals/client/src/builders/returnStatement.ts +++ b/internals/client/src/builders/returnStatement.ts @@ -1,16 +1,21 @@ import type { ast } from 'kubb/kit' import type { OperationTypeNames } from '../resolveOperationTypes.ts' -import { buildResultType } from './generics.ts' +import { buildRequestResultGenerics } from './generics.ts' /** * Builds the return statement of a generated operation function. The runtime call already resolves - * to `{ data, error, request, response }`; the generated code wraps that promise with `withUnwrap` - * so the caller can `await` it directly or call `.unwrap()` for the bare success body, then casts - * the result to the operation's `Unwrappable>`. + * to `{ data, error, request, response }`; the generated code casts that result to the operation's + * `RequestResult` first (as it always did), then wraps it with `withUnwrap` so the caller can + * `await` it directly or call `.unwrap()` for the bare success body. + * + * Casting the raw call and only then wrapping keeps `withUnwrap`'s generic inferred as + * `RequestResult`, not the runtime's own internal result type: an `Unwrappable` cast straight to + * `Unwrappable` carries a `.then` overload pinned to `A`, and that two-generic swap is too narrow + * for `as` to allow, even where `A` and `B` alone would satisfy it. * * @example - * `return withUnwrap(request({ method: 'POST', url: '/pet', ...config })) as Unwrappable>` + * `return withUnwrap(request({ method: 'POST', url: '/pet', ...config }) as Promise>)` */ export function buildReturnStatement({ node, types, callConfig }: { node: ast.OperationNode; types: OperationTypeNames; callConfig: string }): string { - return `return withUnwrap(request(${callConfig})) as ${buildResultType({ node, types })}` + return `return withUnwrap(request(${callConfig}) as Promise>)` } diff --git a/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatus/addPet.ts b/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatus/addPet.ts index a7ea99afa..5c0782280 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatus/addPet.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatus/addPet.ts @@ -12,5 +12,5 @@ export function addPet( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', ...config }) as Promise>) } diff --git a/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts b/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts index d2af06c37..e3896f335 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts @@ -13,7 +13,7 @@ export function addPet( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', validator: { response: AddPetResponse }, ...config })) as Unwrappable< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet', validator: { response: AddPetResponse }, ...config }) as Promise>, + ) } diff --git a/packages/plugin-axios/src/generators/__snapshots__/deletePetNoContent/deletePet.ts b/packages/plugin-axios/src/generators/__snapshots__/deletePetNoContent/deletePet.ts index bb6c0ce5e..091e8543c 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/deletePetNoContent/deletePet.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/deletePetNoContent/deletePet.ts @@ -12,5 +12,5 @@ export function deletePet( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } diff --git a/packages/plugin-axios/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts b/packages/plugin-axios/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts index ab984857f..9cc2198f1 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts @@ -12,5 +12,5 @@ export function findPetsByTags( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByTags', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByTags', ...config }) as Promise>) } diff --git a/packages/plugin-axios/src/generators/__snapshots__/getPetById/getPetById.ts b/packages/plugin-axios/src/generators/__snapshots__/getPetById/getPetById.ts index 5db400e5d..81bae0783 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/getPetById/getPetById.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/getPetById/getPetById.ts @@ -12,5 +12,5 @@ export function getPetById( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise>) } diff --git a/packages/plugin-axios/src/generators/__snapshots__/getPetByIdWithSecurity/getPetById.ts b/packages/plugin-axios/src/generators/__snapshots__/getPetByIdWithSecurity/getPetById.ts index 81cb173de..a56ab7525 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/getPetByIdWithSecurity/getPetById.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/getPetByIdWithSecurity/getPetById.ts @@ -13,6 +13,8 @@ export function getPetById( const { client: request = client, ...config } = options return withUnwrap( - request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }), - ) as Unwrappable> + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/packages/plugin-axios/src/generators/__snapshots__/getProject/getProject.ts b/packages/plugin-axios/src/generators/__snapshots__/getProject/getProject.ts index e5489beb6..5738129e3 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/getProject/getProject.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/getProject/getProject.ts @@ -12,5 +12,5 @@ export function getProject( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } diff --git a/packages/plugin-axios/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts b/packages/plugin-axios/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts index e9efb1c8a..6c8c494a2 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts @@ -18,6 +18,6 @@ export function listPetsStyled( url: '/pets/{petId}', styles: { path: { petId: { style: 'matrix', explode: true } }, query: { tags: { style: 'pipeDelimited', explode: false } } }, ...config, - }), - ) as Unwrappable> + }) as Promise>, + ) } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/petClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/petClient.ts index 9dc693850..7a1318bf1 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/petClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/petClient.ts @@ -20,7 +20,7 @@ export class PetClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -31,6 +31,6 @@ export class PetClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/projectClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/projectClient.ts index 345af6331..68173b89e 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/projectClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/projectClient.ts @@ -19,6 +19,6 @@ export class ProjectClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/storeClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/storeClient.ts index 4993cf2b7..aaa66f613 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClass/storeClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClass/storeClient.ts @@ -19,6 +19,6 @@ export class StoreClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config }) as Promise>) } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/petClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/petClient.ts index 9dc693850..7a1318bf1 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/petClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/petClient.ts @@ -20,7 +20,7 @@ export class PetClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -31,6 +31,6 @@ export class PetClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/projectClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/projectClient.ts index 345af6331..68173b89e 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/projectClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/projectClient.ts @@ -19,6 +19,6 @@ export class ProjectClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/storeClient.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/storeClient.ts index 4993cf2b7..aaa66f613 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/storeClient.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkClassWithName/storeClient.ts @@ -19,6 +19,6 @@ export class StoreClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config }) as Promise>) } } diff --git a/packages/plugin-axios/src/generators/__snapshots__/sdkSingle/petStore.ts b/packages/plugin-axios/src/generators/__snapshots__/sdkSingle/petStore.ts index e453d47d9..dcbe184f5 100644 --- a/packages/plugin-axios/src/generators/__snapshots__/sdkSingle/petStore.ts +++ b/packages/plugin-axios/src/generators/__snapshots__/sdkSingle/petStore.ts @@ -22,7 +22,7 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -33,7 +33,7 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -44,7 +44,7 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config }) as Promise>) } /** @@ -55,6 +55,6 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatus/addPet.ts b/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatus/addPet.ts index a7ea99afa..5c0782280 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatus/addPet.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatus/addPet.ts @@ -12,5 +12,5 @@ export function addPet( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', ...config }) as Promise>) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts b/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts index d2af06c37..e3896f335 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/addPetMultiStatusWithZod/addPet.ts @@ -13,7 +13,7 @@ export function addPet( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', validator: { response: AddPetResponse }, ...config })) as Unwrappable< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet', validator: { response: AddPetResponse }, ...config }) as Promise>, + ) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/addPetWithSecurity/addPet.ts b/packages/plugin-fetch/src/generators/__snapshots__/addPetWithSecurity/addPet.ts index dc3f468ed..173260630 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/addPetWithSecurity/addPet.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/addPetWithSecurity/addPet.ts @@ -12,7 +12,7 @@ export function addPet( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/deletePetNoContent/deletePet.ts b/packages/plugin-fetch/src/generators/__snapshots__/deletePetNoContent/deletePet.ts index bb6c0ce5e..091e8543c 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/deletePetNoContent/deletePet.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/deletePetNoContent/deletePet.ts @@ -12,5 +12,5 @@ export function deletePet( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts b/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts index ab984857f..9cc2198f1 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTags/findPetsByTags.ts @@ -12,5 +12,5 @@ export function findPetsByTags( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByTags', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByTags', ...config }) as Promise>) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTagsWithGlobalSecurity/findPetsByTags.ts b/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTagsWithGlobalSecurity/findPetsByTags.ts index 24b0deded..398a970a8 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTagsWithGlobalSecurity/findPetsByTags.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/findPetsByTagsWithGlobalSecurity/findPetsByTags.ts @@ -12,7 +12,9 @@ export function findPetsByTags( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'http', scheme: 'bearer' }], ...config })) as Unwrappable< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'http', scheme: 'bearer' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/getPetById/getPetById.ts b/packages/plugin-fetch/src/generators/__snapshots__/getPetById/getPetById.ts index 5db400e5d..81bae0783 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/getPetById/getPetById.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/getPetById/getPetById.ts @@ -12,5 +12,5 @@ export function getPetById( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise>) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/getPetByIdWithMultipleSchemes/getPetById.ts b/packages/plugin-fetch/src/generators/__snapshots__/getPetByIdWithMultipleSchemes/getPetById.ts index 81cb173de..a56ab7525 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/getPetByIdWithMultipleSchemes/getPetById.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/getPetByIdWithMultipleSchemes/getPetById.ts @@ -13,6 +13,8 @@ export function getPetById( const { client: request = client, ...config } = options return withUnwrap( - request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }), - ) as Unwrappable> + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/getProject/getProject.ts b/packages/plugin-fetch/src/generators/__snapshots__/getProject/getProject.ts index e5489beb6..5738129e3 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/getProject/getProject.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/getProject/getProject.ts @@ -12,5 +12,5 @@ export function getProject( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts b/packages/plugin-fetch/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts index e9efb1c8a..6c8c494a2 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/listPetsWithStyles/listPetsStyled.ts @@ -18,6 +18,6 @@ export function listPetsStyled( url: '/pets/{petId}', styles: { path: { petId: { style: 'matrix', explode: true } }, query: { tags: { style: 'pipeDelimited', explode: false } } }, ...config, - }), - ) as Unwrappable> + }) as Promise>, + ) } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/petClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/petClient.ts index 9dc693850..7a1318bf1 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/petClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/petClient.ts @@ -20,7 +20,7 @@ export class PetClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -31,6 +31,6 @@ export class PetClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/projectClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/projectClient.ts index 345af6331..68173b89e 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/projectClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/projectClient.ts @@ -19,6 +19,6 @@ export class ProjectClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/storeClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/storeClient.ts index 4993cf2b7..aaa66f613 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/storeClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClass/storeClient.ts @@ -19,6 +19,6 @@ export class StoreClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/petClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/petClient.ts index 9dc693850..7a1318bf1 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/petClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/petClient.ts @@ -20,7 +20,7 @@ export class PetClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -31,6 +31,6 @@ export class PetClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/projectClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/projectClient.ts index 345af6331..68173b89e 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/projectClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/projectClient.ts @@ -19,6 +19,6 @@ export class ProjectClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/storeClient.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/storeClient.ts index 4993cf2b7..aaa66f613 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/storeClient.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithName/storeClient.ts @@ -19,6 +19,6 @@ export class StoreClient { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithSecurity/petStore.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithSecurity/petStore.ts index 2fafe6c8d..18a4e34ce 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithSecurity/petStore.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkClassWithSecurity/petStore.ts @@ -23,8 +23,10 @@ export class PetStore { const { client: request = this.client, ...config } = options return withUnwrap( - request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }), - ) as Unwrappable> + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'oauth2' }, { type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } /** @@ -35,7 +37,7 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -46,7 +48,7 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config }) as Promise>) } /** @@ -57,6 +59,6 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/sdkSingle/petStore.ts b/packages/plugin-fetch/src/generators/__snapshots__/sdkSingle/petStore.ts index e453d47d9..dcbe184f5 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/sdkSingle/petStore.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/sdkSingle/petStore.ts @@ -22,7 +22,7 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -33,7 +33,7 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', ...config }) as Promise>) } /** @@ -44,7 +44,7 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', ...config }) as Promise>) } /** @@ -55,6 +55,6 @@ export class PetStore { ): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/projects/{project_id}', ...config }) as Promise>) } } diff --git a/packages/plugin-fetch/src/generators/__snapshots__/uploadFileMultipart/uploadFile.ts b/packages/plugin-fetch/src/generators/__snapshots__/uploadFileMultipart/uploadFile.ts index 1c7adffd9..11ba6bbad 100644 --- a/packages/plugin-fetch/src/generators/__snapshots__/uploadFileMultipart/uploadFile.ts +++ b/packages/plugin-fetch/src/generators/__snapshots__/uploadFileMultipart/uploadFile.ts @@ -12,7 +12,9 @@ export function uploadFile( ): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', contentType: { request: 'multipart/form-data' }, ...config })) as Unwrappable< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}/uploadImage', contentType: { request: 'multipart/form-data' }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/clients/updatePet.ts index 9a1ffdbf6..8fab7946f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/clients/updatePet.ts @@ -13,5 +13,5 @@ import { client, withUnwrap } from '../.kubb/client' export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/petClient.ts index 4d7cc3e0f..869252682 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/petClient.ts @@ -26,7 +26,7 @@ export class PetClient { public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -37,7 +37,7 @@ export class PetClient { public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -48,7 +48,7 @@ export class PetClient { public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } /** @@ -59,7 +59,7 @@ export class PetClient { public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -69,6 +69,6 @@ export class PetClient { public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/storeClient.ts index f647fb5a9..c51022005 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/clients/storeClient.ts @@ -23,7 +23,7 @@ export class StoreClient { public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } /** @@ -34,6 +34,6 @@ export class StoreClient { public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/petClient.ts index 4d7cc3e0f..869252682 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/petClient.ts @@ -26,7 +26,7 @@ export class PetClient { public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -37,7 +37,7 @@ export class PetClient { public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -48,7 +48,7 @@ export class PetClient { public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } /** @@ -59,7 +59,7 @@ export class PetClient { public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -69,6 +69,6 @@ export class PetClient { public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/storeClient.ts index f647fb5a9..c51022005 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/clients/storeClient.ts @@ -23,7 +23,7 @@ export class StoreClient { public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } /** @@ -34,6 +34,6 @@ export class StoreClient { public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/clients/petStore.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/clients/petStore.ts index 8fab984a5..eb6ecc02c 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/clients/petStore.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/clients/petStore.ts @@ -28,7 +28,7 @@ export class PetStore { public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -39,7 +39,7 @@ export class PetStore { public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -50,7 +50,7 @@ export class PetStore { public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } /** @@ -61,7 +61,7 @@ export class PetStore { public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -71,7 +71,7 @@ export class PetStore { public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -82,7 +82,7 @@ export class PetStore { public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } /** @@ -93,6 +93,6 @@ export class PetStore { public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/addPet.ts index c1ed606e3..397c9cc0c 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/addPet.ts @@ -16,5 +16,5 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/deletePet.ts index ee540afe9..71e8cae66 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/deletePet.ts @@ -16,5 +16,5 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/findPetsByStatus.ts index e7a914e57..ee1cf3c80 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/findPetsByStatus.ts @@ -16,5 +16,5 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getInventory.ts index 37f35c03d..2fdc44f8d 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getInventory.ts @@ -16,5 +16,5 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getPetById.ts index 40625a0b4..fab89a848 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/getPetById.ts @@ -16,5 +16,5 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/placeOrder.ts index d840043ca..1025f08e9 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/placeOrder.ts @@ -16,5 +16,5 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/uploadFile.ts index 8f5c0401f..3d9c5e420 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/clients/uploadFile.ts @@ -15,5 +15,5 @@ import { uploadFileResponseSchema } from '../zod/uploadFileSchema' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/clients/updatePet.ts index 9a1ffdbf6..8fab7946f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/clients/updatePet.ts @@ -13,5 +13,5 @@ import { client, withUnwrap } from '../.kubb/client' export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/petClient.ts index 4d7cc3e0f..869252682 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/petClient.ts @@ -26,7 +26,7 @@ export class PetClient { public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -37,7 +37,7 @@ export class PetClient { public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -48,7 +48,7 @@ export class PetClient { public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } /** @@ -59,7 +59,7 @@ export class PetClient { public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -69,6 +69,6 @@ export class PetClient { public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/storeClient.ts index f647fb5a9..c51022005 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/clients/storeClient.ts @@ -23,7 +23,7 @@ export class StoreClient { public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } /** @@ -34,6 +34,6 @@ export class StoreClient { public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/petClient.ts index 4d7cc3e0f..869252682 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/petClient.ts @@ -26,7 +26,7 @@ export class PetClient { public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -37,7 +37,7 @@ export class PetClient { public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -48,7 +48,7 @@ export class PetClient { public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } /** @@ -59,7 +59,7 @@ export class PetClient { public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -69,6 +69,6 @@ export class PetClient { public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/storeClient.ts index f647fb5a9..c51022005 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/clients/storeClient.ts @@ -23,7 +23,7 @@ export class StoreClient { public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } /** @@ -34,6 +34,6 @@ export class StoreClient { public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/clients/petStore.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/clients/petStore.ts index 8fab984a5..eb6ecc02c 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/clients/petStore.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/clients/petStore.ts @@ -28,7 +28,7 @@ export class PetStore { public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -39,7 +39,7 @@ export class PetStore { public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -50,7 +50,7 @@ export class PetStore { public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } /** @@ -61,7 +61,7 @@ export class PetStore { public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -71,7 +71,7 @@ export class PetStore { public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise>) } /** @@ -82,7 +82,7 @@ export class PetStore { public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } /** @@ -93,6 +93,6 @@ export class PetStore { public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/addPet.ts index c1ed606e3..397c9cc0c 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/addPet.ts @@ -16,5 +16,5 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/deletePet.ts index ee540afe9..71e8cae66 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/deletePet.ts @@ -16,5 +16,5 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/findPetsByStatus.ts index e7a914e57..ee1cf3c80 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/findPetsByStatus.ts @@ -16,5 +16,5 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getInventory.ts index 37f35c03d..2fdc44f8d 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getInventory.ts @@ -16,5 +16,5 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getPetById.ts index 40625a0b4..fab89a848 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/getPetById.ts @@ -16,5 +16,5 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/placeOrder.ts index d840043ca..1025f08e9 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/placeOrder.ts @@ -16,5 +16,5 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/uploadFile.ts index 8f5c0401f..3d9c5e420 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/clients/uploadFile.ts @@ -15,5 +15,5 @@ import { uploadFileResponseSchema } from '../zod/uploadFileSchema' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/petClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/petClient.ts index ad22132e1..ef2560df0 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/petClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/petClient.ts @@ -31,7 +31,7 @@ export class PetClient { public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema }, ...config }) as Promise>) } /** @@ -42,7 +42,7 @@ export class PetClient { public findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], validator: { response: findPetsByStatusResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], validator: { response: findPetsByStatusResponseSchema }, ...config }) as Promise>) } /** @@ -53,7 +53,7 @@ export class PetClient { public getPetById(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema }, ...config }) as Promise>) } /** @@ -64,7 +64,7 @@ export class PetClient { public deletePet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema }, ...config }) as Promise>) } /** @@ -74,6 +74,6 @@ export class PetClient { public uploadFile(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/storeClient.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/storeClient.ts index 3ecac617c..ef8c4891d 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/storeClient.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/clients/storeClient.ts @@ -25,7 +25,7 @@ export class StoreClient { public getInventory(options: Options = {}): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise>) } /** @@ -36,6 +36,6 @@ export class StoreClient { public placeOrder(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema }, ...config }) as Promise>) } } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/clients/updatePet.ts index 9a1ffdbf6..8fab7946f 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/clients/updatePet.ts @@ -13,5 +13,5 @@ import { client, withUnwrap } from '../.kubb/client' export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/clients/updatePet.ts index 9a1ffdbf6..8fab7946f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/clients/updatePet.ts @@ -13,5 +13,5 @@ import { client, withUnwrap } from '../.kubb/client' export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/addPet.ts index b23f13436..179bf621e 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/addPet.ts @@ -16,5 +16,5 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/deletePet.ts index 28ebb6b60..e1a6d8774 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/deletePet.ts @@ -16,5 +16,5 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/findPetsByStatus.ts index b72b584bc..b37a025b5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/findPetsByStatus.ts @@ -16,5 +16,5 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getInventory.ts index c8641d728..af8922f7d 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getInventory.ts @@ -16,5 +16,5 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getPetById.ts index ae2bf7db4..70ad99207 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/getPetById.ts @@ -16,5 +16,5 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/placeOrder.ts index a184c8097..e1ae15784 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/placeOrder.ts @@ -16,5 +16,5 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/uploadFile.ts index 35ccd738b..de69d9c74 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/clients/uploadFile.ts @@ -15,5 +15,5 @@ import { uploadFileResponseSchema } from '../zod/uploadFileSchema' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/clients/updatePet.ts index 9a1ffdbf6..8fab7946f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/clients/updatePet.ts @@ -13,5 +13,5 @@ import { client, withUnwrap } from '../.kubb/client' export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/addPet.ts index b23f13436..179bf621e 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/addPet.ts @@ -16,5 +16,5 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/deletePet.ts index 28ebb6b60..e1a6d8774 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/deletePet.ts @@ -16,5 +16,5 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/findPetsByStatus.ts index b72b584bc..b37a025b5 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/findPetsByStatus.ts @@ -16,5 +16,5 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getInventory.ts index c8641d728..af8922f7d 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getInventory.ts @@ -16,5 +16,5 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getPetById.ts index ae2bf7db4..70ad99207 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/getPetById.ts @@ -16,5 +16,5 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/placeOrder.ts index a184c8097..e1ae15784 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/placeOrder.ts @@ -16,5 +16,5 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/uploadFile.ts index 35ccd738b..de69d9c74 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/clients/uploadFile.ts @@ -15,5 +15,5 @@ import { uploadFileResponseSchema } from '../zod/uploadFileSchema' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/clients/updatePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/clients/updatePet.ts index 9a1ffdbf6..8fab7946f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/clients/updatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/clients/updatePet.ts @@ -13,5 +13,5 @@ import { client, withUnwrap } from '../.kubb/client' export function updatePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pets/{pet_id}', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/addPet.ts index b23f13436..179bf621e 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/addPet.ts @@ -16,5 +16,5 @@ import { addPetResponseSchema, addPetErrorSchema } from '../zod/addPetSchema' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], validator: { response: addPetResponseSchema, error: addPetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/deletePet.ts index 28ebb6b60..e1a6d8774 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/deletePet.ts @@ -16,5 +16,5 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../zod/deletePetS export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/findPetsByStatus.ts index b72b584bc..b37a025b5 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/findPetsByStatus.ts @@ -16,5 +16,5 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getInventory.ts index c8641d728..af8922f7d 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getInventory.ts @@ -16,5 +16,5 @@ import { getInventoryResponseSchema } from '../zod/getInventorySchema' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], validator: { response: getInventoryResponseSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getPetById.ts index ae2bf7db4..70ad99207 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/getPetById.ts @@ -16,5 +16,5 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../zod/getPetBy export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/placeOrder.ts index a184c8097..e1ae15784 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/placeOrder.ts @@ -16,5 +16,5 @@ import { placeOrderResponseSchema, placeOrderErrorSchema } from '../zod/placeOrd export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', validator: { response: placeOrderResponseSchema, error: placeOrderErrorSchema }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/uploadFile.ts index 35ccd738b..de69d9c74 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/clients/uploadFile.ts @@ -15,5 +15,5 @@ import { uploadFileResponseSchema } from '../zod/uploadFileSchema' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], validator: { response: uploadFileResponseSchema }, contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/addPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/addPet.ts index 405aef6c7..82de77de2 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/addPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/addPet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function addPet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/deletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/deletePet.ts index 465cb186c..079067b15 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/deletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/deletePet.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function deletePet(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/findPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/findPetsByStatus.ts index 188f7d37a..d04cecf7a 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/findPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/findPetsByStatus.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function findPetsByStatus(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], styles: { query: { status: { explode: true } } }, ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getInventory.ts index a27010532..8b7b3ad62 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getInventory.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getInventory(options: Options = {}): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getPetById.ts index 22a08cf60..13e4bb40c 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/getPetById.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function getPetById(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config })) as Unwrappable> + return withUnwrap(request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/placeOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/placeOrder.ts index 2fd356056..9b72c7a19 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/placeOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/placeOrder.ts @@ -15,5 +15,5 @@ import { client, withUnwrap } from '../.kubb/client' export function placeOrder(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/store/order', ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/uploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/uploadFile.ts index 7df4aba6b..33aa10f78 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/uploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/clients/uploadFile.ts @@ -14,5 +14,5 @@ import { client, withUnwrap } from '../.kubb/client' export function uploadFile(options: Options): Unwrappable> { const { client: request = client, ...config } = options - return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config })) as Unwrappable> + return withUnwrap(request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], contentType: { request: 'application/octet-stream' }, ...config }) as Promise>) } From a79631d39c064630fff8a4580e74ede3ba6ec560 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 20:47:29 +0000 Subject: [PATCH 3/9] docs: trim the unwrap() changeset to a plain, minimal note Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN --- .changeset/client-unwrap-method.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.changeset/client-unwrap-method.md b/.changeset/client-unwrap-method.md index 992aa1e77..0024ef93f 100644 --- a/.changeset/client-unwrap-method.md +++ b/.changeset/client-unwrap-method.md @@ -3,11 +3,6 @@ '@kubb/plugin-fetch': minor --- -Every generated call now resolves to a promise with an extra `unwrap()` method, Redux-Toolkit-style: -`unwrap()` resolves to the bare success body, or rejects with `error` for a result that carried one. -`await getPetById(...)` still resolves to the full `{ status, data, error, contentType, request, response }` -result as before, so this is additive. - -```ts -const pet = await getPetById({ path: { petId: 1 } }).unwrap() -``` +Every generated call now resolves to a promise with an extra `unwrap()` method: it resolves to the +bare success body, or rejects with `error` for a call that didn't throw. `await getPetById(...)` +still returns the full result as before, so this is additive. From bf5fa266cd59b4e05936d6289f92908a3fa479aa Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 05:36:24 +0000 Subject: [PATCH 4/9] test: simplify withUnwrap tests to plain unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /simplify: withUnwrap is a pure function over a promise, so most of its tests don't need the axios/fetch client mocking machinery. Call it directly with a resolved/rejected promise instead. The one case that genuinely exercised the client (rejection propagation) is simplified to a plain rejected promise, since that's standard Promise behavior withUnwrap doesn't special-case. Also reviewed the diff for reuse, efficiency, and altitude issues (three of four /simplify agents hit a rate limit and had to be redone by hand): no other findings. A suggested "UnwrapResult duplicates SuccessOf" reuse finding was a false positive — they operate on different type shapes (the OpenAPI responses record vs. the resolved RequestResult union) and can't share an implementation without coupling withUnwrap's generic to spec-shape information it doesn't need. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN --- packages/plugin-axios/templates/axios.test.ts | 25 ++++++++----------- packages/plugin-fetch/templates/fetch.test.ts | 21 ++++++---------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/packages/plugin-axios/templates/axios.test.ts b/packages/plugin-axios/templates/axios.test.ts index a7d289e09..dce0c1197 100644 --- a/packages/plugin-axios/templates/axios.test.ts +++ b/packages/plugin-axios/templates/axios.test.ts @@ -718,30 +718,25 @@ describe('getUrl', () => { describe('withUnwrap', () => { test('unwrap() resolves to the success data', async () => { - const { instance } = fakeAxios({ data: { id: 1 }, status: 200 }) - const client = createClientCore({ transport: instance }) - const result = await withUnwrap(client({ method: 'GET', url: '/pet/1' }) as Promise).unwrap() + const result = await withUnwrap(Promise.resolve({ data: { id: 1 }, error: undefined })).unwrap() expect(result).toStrictEqual({ id: 1 }) }) test('unwrap() rejects with error for a non-throwing error result', async () => { - const { instance } = fakeAxios({ data: { message: 'not found' }, status: 404 }) - const client = createClientCore({ transport: instance, validateStatus: () => true }) - await expect(withUnwrap(client({ method: 'GET', url: '/pet/999' }) as Promise).unwrap()).rejects.toStrictEqual({ message: 'not found' }) + await expect(withUnwrap(Promise.resolve({ data: undefined, error: { message: 'not found' } })).unwrap()).rejects.toStrictEqual({ + message: 'not found', + }) }) test('the wrapped promise still resolves to the full result when awaited directly', async () => { - const { instance } = fakeAxios({ data: { id: 1 }, status: 200 }) - const client = createClientCore({ transport: instance }) - const result = await withUnwrap(client({ method: 'GET', url: '/pet/1' }) as Promise) - expect(result.status).toBe(200) - expect(result.data).toStrictEqual({ id: 1 }) + const full = { data: { id: 1 }, error: undefined } + const result = await withUnwrap(Promise.resolve(full)) + expect(result).toBe(full) }) - test('a throwing call rejects before unwrap() has a chance to run', async () => { - const { instance } = fakeAxios({ data: { message: 'not found' }, status: 404 }) - const client = createClientCore({ transport: instance }) - await expect(withUnwrap(client({ method: 'GET', url: '/pet/999' }) as Promise).unwrap()).rejects.toBeInstanceOf(ResponseError) + test('a rejected call propagates the rejection unchanged', async () => { + const error = new ResponseError({ data: { message: 'not found' }, status: 404, statusText: 'Not Found', request: {}, response: {} }) + await expect(withUnwrap(Promise.reject(error)).unwrap()).rejects.toBe(error) }) }) diff --git a/packages/plugin-fetch/templates/fetch.test.ts b/packages/plugin-fetch/templates/fetch.test.ts index cba8407c3..1f364c42b 100644 --- a/packages/plugin-fetch/templates/fetch.test.ts +++ b/packages/plugin-fetch/templates/fetch.test.ts @@ -652,28 +652,23 @@ describe('getUrl', () => { describe('withUnwrap', () => { test('unwrap() resolves to the success data', async () => { - const { client } = createClient({ data: { id: 1 }, status: 200 }) - const result = await withUnwrap(client({ method: 'GET', url: '/pet/1' }) as Promise>).unwrap() + const result = await withUnwrap(Promise.resolve({ data: { id: 1 }, error: undefined })).unwrap() expect(result).toStrictEqual({ id: 1 }) }) test('unwrap() rejects with error for a non-throwing error result', async () => { - const { client } = createClient({ data: { message: 'invalid' }, status: 405 }) - await expect( - withUnwrap(client({ method: 'POST', url: '/pet', throwOnError: false }) as Promise>).unwrap(), - ).rejects.toStrictEqual({ message: 'invalid' }) + await expect(withUnwrap(Promise.resolve({ data: undefined, error: { message: 'invalid' } })).unwrap()).rejects.toStrictEqual({ message: 'invalid' }) }) test('the wrapped promise still resolves to the full result when awaited directly', async () => { - const { client } = createClient({ data: { id: 1 }, status: 200 }) - const result = await withUnwrap(client({ method: 'GET', url: '/pet/1' }) as Promise>) - expect(result.status).toBe(200) - expect(result.data).toStrictEqual({ id: 1 }) + const full = { data: { id: 1 }, error: undefined } + const result = await withUnwrap(Promise.resolve(full)) + expect(result).toBe(full) }) - test('a throwing call rejects before unwrap() has a chance to run', async () => { - const { client } = createClient({ data: { message: 'invalid' }, status: 405 }) - await expect(withUnwrap(client({ method: 'POST', url: '/pet' }) as Promise>).unwrap()).rejects.toBeInstanceOf(ResponseError) + test('a rejected call propagates the rejection unchanged', async () => { + const error = new ResponseError({ data: { message: 'invalid' }, status: 405, statusText: 'Method Not Allowed', request: 'REQ', response: 'RES' }) + await expect(withUnwrap(Promise.reject(error)).unwrap()).rejects.toBe(error) }) }) From e84111dd4276f1b69b41940429d771b3836d5788 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Wed, 2 Sep 2026 12:56:36 +0200 Subject: [PATCH 5/9] refactor: inline single-use unwrap helpers and tidy docs --- .changeset/client-unwrap-method.md | 12 ++++-- .../client/src/builders/generics.test.ts | 8 +--- internals/client/src/builders/generics.ts | 12 ------ .../client/src/builders/returnStatement.ts | 14 +++---- internals/client/src/builders/sdkMethod.ts | 5 ++- internals/client/src/builders/signature.ts | 4 +- internals/client/src/components/Operation.tsx | 5 ++- .../client/src/generators/clientGenerator.tsx | 5 ++- packages/plugin-axios/templates/axios.test.ts | 6 --- packages/plugin-axios/templates/axios.ts | 38 ++++++++++------- packages/plugin-fetch/templates/fetch.test.ts | 6 --- packages/plugin-fetch/templates/fetch.ts | 42 +++++++++++-------- .../pluginAxios/default/.kubb/client.ts | 38 ++++++++++------- .../pluginAxios/paramsCasing/.kubb/client.ts | 38 ++++++++++------- .../pluginAxios/sdkClass/.kubb/client.ts | 38 ++++++++++------- .../sdkClassWithName/.kubb/client.ts | 38 ++++++++++------- .../pluginAxios/sdkSingle/.kubb/client.ts | 38 ++++++++++------- .../pluginAxios/zodTypes/.kubb/client.ts | 38 ++++++++++------- .../pluginFetch/default/.kubb/client.ts | 42 +++++++++++-------- .../pluginFetch/paramsCasing/.kubb/client.ts | 42 +++++++++++-------- .../pluginFetch/sdkClass/.kubb/client.ts | 42 +++++++++++-------- .../sdkClassWithName/.kubb/client.ts | 42 +++++++++++-------- .../pluginFetch/sdkSingle/.kubb/client.ts | 42 +++++++++++-------- .../pluginFetch/zodTypes/.kubb/client.ts | 42 +++++++++++-------- .../pluginFetch/zodTypesSdk/.kubb/client.ts | 42 +++++++++++-------- .../excludeByOperationId/.kubb/client.ts | 38 ++++++++++------- .../pluginMcp/groupByTag/.kubb/client.ts | 38 ++++++++++------- .../pluginMcp/includeByTag/.kubb/client.ts | 38 ++++++++++------- .../pluginMcp/paramsCasing/.kubb/client.ts | 38 ++++++++++------- .../pluginMcp/petStore/.kubb/client.ts | 38 ++++++++++------- .../withClientPlugin/.kubb/client.ts | 38 ++++++++++------- .../excludeByOperationId/.kubb/client.ts | 38 ++++++++++------- .../groupByTag/.kubb/client.ts | 38 ++++++++++------- .../includeByTag/.kubb/client.ts | 38 ++++++++++------- .../pluginReactQuery/infinite/.kubb/client.ts | 38 ++++++++++------- .../mutationDisabled/.kubb/client.ts | 38 ++++++++++------- .../paramsCasing/.kubb/client.ts | 38 ++++++++++------- .../parserZod/.kubb/client.ts | 38 ++++++++++------- .../pluginReactQuery/petStore/.kubb/client.ts | 38 ++++++++++------- .../queryMethods/.kubb/client.ts | 38 ++++++++++------- .../pluginReactQuery/suspense/.kubb/client.ts | 38 ++++++++++------- .../withClientPlugin/.kubb/client.ts | 38 ++++++++++------- .../excludeByOperationId/.kubb/client.ts | 38 ++++++++++------- .../pluginSwr/groupByTag/.kubb/client.ts | 38 ++++++++++------- .../pluginSwr/includeByTag/.kubb/client.ts | 38 ++++++++++------- .../mutationDisabled/.kubb/client.ts | 38 ++++++++++------- .../pluginSwr/paramsCasing/.kubb/client.ts | 38 ++++++++++------- .../pluginSwr/parserZod/.kubb/client.ts | 38 ++++++++++------- .../pluginSwr/petStore/.kubb/client.ts | 38 ++++++++++------- .../pluginSwr/queryDisabled/.kubb/client.ts | 38 ++++++++++------- .../pluginSwr/queryMethods/.kubb/client.ts | 38 ++++++++++------- .../withClientPlugin/.kubb/client.ts | 38 ++++++++++------- .../excludeByOperationId/.kubb/client.ts | 38 ++++++++++------- .../pluginVueQuery/groupByTag/.kubb/client.ts | 38 ++++++++++------- .../includeByTag/.kubb/client.ts | 38 ++++++++++------- .../pluginVueQuery/infinite/.kubb/client.ts | 38 ++++++++++------- .../mutationDisabled/.kubb/client.ts | 38 ++++++++++------- .../paramsCasing/.kubb/client.ts | 38 ++++++++++------- .../pluginVueQuery/parserZod/.kubb/client.ts | 38 ++++++++++------- .../pluginVueQuery/petStore/.kubb/client.ts | 38 ++++++++++------- .../withClientPlugin/.kubb/client.ts | 38 ++++++++++------- 61 files changed, 1217 insertions(+), 830 deletions(-) diff --git a/.changeset/client-unwrap-method.md b/.changeset/client-unwrap-method.md index 0024ef93f..24c7ab248 100644 --- a/.changeset/client-unwrap-method.md +++ b/.changeset/client-unwrap-method.md @@ -3,6 +3,12 @@ '@kubb/plugin-fetch': minor --- -Every generated call now resolves to a promise with an extra `unwrap()` method: it resolves to the -bare success body, or rejects with `error` for a call that didn't throw. `await getPetById(...)` -still returns the full result as before, so this is additive. +Generated calls now return a promise with an extra `unwrap()` method. Calling it gives you the bare +success body, or rejects with `error` when the call was made with `throwOnError: false`. + +```ts +const { data, error } = await getPetById({ path: { petId: 1 } }) +const pet = await getPetById({ path: { petId: 1 } }).unwrap() +``` + +Awaiting the call directly still gives the full result, so nothing existing changes. diff --git a/internals/client/src/builders/generics.test.ts b/internals/client/src/builders/generics.test.ts index a337d14af..6f55ad37e 100644 --- a/internals/client/src/builders/generics.test.ts +++ b/internals/client/src/builders/generics.test.ts @@ -1,7 +1,7 @@ import { ast } from 'kubb/kit' import { resolverTs } from '@kubb/plugin-ts' import { describe, expect, test } from 'vitest' -import { buildRequestResultGenerics, buildResultType } from './generics.ts' +import { buildRequestResultGenerics } from './generics.ts' const node = ast.factory.createOperation({ operationId: 'getPetById', @@ -17,9 +17,3 @@ describe('buildRequestResultGenerics', () => { expect(buildRequestResultGenerics({ node, types: resolverTs })).toBe('GetPetByIdResponses, ThrowOnError') }) }) - -describe('buildResultType', () => { - test('wraps RequestResult in Unwrappable', () => { - expect(buildResultType({ node, types: resolverTs })).toBe('Unwrappable>') - }) -}) diff --git a/internals/client/src/builders/generics.ts b/internals/client/src/builders/generics.ts index 0d68081fa..451b61f7c 100644 --- a/internals/client/src/builders/generics.ts +++ b/internals/client/src/builders/generics.ts @@ -12,15 +12,3 @@ import type { OperationTypeNames } from '../resolveOperationTypes.ts' export function buildRequestResultGenerics({ node, types }: { node: ast.OperationNode; types: OperationTypeNames }): string { return `${types.response.responses(node)}, ThrowOnError` } - -/** - * Builds the result type name an operation's function signature and return statement use: the - * runtime's `Unwrappable`, wrapping `RequestResult` so the resolved call also carries an - * RTK-style `unwrap()` method. - * - * @example - * `buildResultType({ node, types }) // 'Unwrappable>'` - */ -export function buildResultType({ node, types }: { node: ast.OperationNode; types: OperationTypeNames }): string { - return `Unwrappable>` -} diff --git a/internals/client/src/builders/returnStatement.ts b/internals/client/src/builders/returnStatement.ts index f5382745d..2f7687831 100644 --- a/internals/client/src/builders/returnStatement.ts +++ b/internals/client/src/builders/returnStatement.ts @@ -4,14 +4,14 @@ import { buildRequestResultGenerics } from './generics.ts' /** * Builds the return statement of a generated operation function. The runtime call already resolves - * to `{ data, error, request, response }`; the generated code casts that result to the operation's - * `RequestResult` first (as it always did), then wraps it with `withUnwrap` so the caller can - * `await` it directly or call `.unwrap()` for the bare success body. + * to `{ data, error, request, response }`. The generated code casts that result to the operation's + * `RequestResult`, then wraps it with `withUnwrap`, so the caller can `await` it directly or call + * `.unwrap()` for the bare success body. * - * Casting the raw call and only then wrapping keeps `withUnwrap`'s generic inferred as - * `RequestResult`, not the runtime's own internal result type: an `Unwrappable` cast straight to - * `Unwrappable` carries a `.then` overload pinned to `A`, and that two-generic swap is too narrow - * for `as` to allow, even where `A` and `B` alone would satisfy it. + * Cast first, wrap second. That order keeps `withUnwrap`'s generic inferred as `RequestResult` + * instead of the runtime's own internal result type. Casting an `Unwrappable` straight to + * `Unwrappable` does not work: the `.then` overload stays pinned to `A`, and `as` rejects that + * two-generic swap even where `A` and `B` on their own would satisfy it. * * @example * `return withUnwrap(request({ method: 'POST', url: '/pet', ...config }) as Promise>)` diff --git a/internals/client/src/builders/sdkMethod.ts b/internals/client/src/builders/sdkMethod.ts index 95ec2221d..aba529e28 100644 --- a/internals/client/src/builders/sdkMethod.ts +++ b/internals/client/src/builders/sdkMethod.ts @@ -47,8 +47,9 @@ function buildCallConfig({ /** * Builds a single instance method for a generated SDK class. The body forwards the single grouped * `options` object to the instance's own client (`this.client`, built once in the constructor) and - * returns the `Unwrappable`. A per-call `options.client` still overrides the instance client, so - * one operation can be routed to a different environment without a new instance. + * returns the `Unwrappable`. A per-call `options.client` still overrides the + * instance client, so one operation can be routed to a different environment without a new + * instance. */ export function buildSdkMethod({ node, diff --git a/internals/client/src/builders/signature.ts b/internals/client/src/builders/signature.ts index 0f8d0a8ac..d9c77a00b 100644 --- a/internals/client/src/builders/signature.ts +++ b/internals/client/src/builders/signature.ts @@ -2,7 +2,7 @@ import type { ast } from 'kubb/kit' import { getRequestGroupOptionality } from '@internals/shared' import { createFunctionParameter, createFunctionParameters, functionPrinter } from '@kubb/plugin-ts' import type { OperationTypeNames } from '../resolveOperationTypes.ts' -import { buildResultType } from './generics.ts' +import { buildRequestResultGenerics } from './generics.ts' const declarationPrinter = functionPrinter({ mode: 'declaration' }) @@ -46,7 +46,7 @@ export function buildGroupedOptionsSignature({ node, types }: { node: ast.Operat return { paramsSignature, - returnType: buildResultType({ node, types }), + returnType: `Unwrappable>`, generics: ['ThrowOnError extends boolean = true'], } } diff --git a/internals/client/src/components/Operation.tsx b/internals/client/src/components/Operation.tsx index 45f59f318..86c498d9d 100644 --- a/internals/client/src/components/Operation.tsx +++ b/internals/client/src/components/Operation.tsx @@ -44,8 +44,9 @@ type Props = { /** * Renders one client operation: the grouped `Request` type and the function that forwards a - * single `options` object to the resolved client and returns the `Unwrappable`. The type, signature, - * and call config are built with the AST factory, and only the jsx-renderer emits the source. + * single `options` object to the resolved client and returns the `Unwrappable`. The + * type, signature, and call config are built with the AST factory, and only the jsx-renderer emits + * the source. */ export function Operation({ name, node, types, zodResolver, validator, security, isExportable = true, isIndexable = true }: Props): KubbReactNode { if (!ast.isHttpOperationNode(node)) return null diff --git a/internals/client/src/generators/clientGenerator.tsx b/internals/client/src/generators/clientGenerator.tsx index 3b0271012..2b46e626e 100644 --- a/internals/client/src/generators/clientGenerator.tsx +++ b/internals/client/src/generators/clientGenerator.tsx @@ -14,8 +14,9 @@ import type { ContractClientFactory } from '../types.ts' * Builds the built-in per-operation generator shared by the client plugins (`@kubb/plugin-fetch`, * `@kubb/plugin-axios`). Emits one async function per OpenAPI operation using the shared * `Operation` component: a grouped `Request` type and a function that forwards a single - * `options` object to the bundled `client` and returns the `Unwrappable`. Only the generator - * `name` differs between plugins; every other resolution, import, and rendering step is identical. + * `options` object to the bundled `client` and returns the `Unwrappable`. Only the + * generator `name` differs between plugins. Every other resolution, import, and rendering step is + * identical. */ export function createClientGenerator(name: string): Generator { return defineGenerator({ diff --git a/packages/plugin-axios/templates/axios.test.ts b/packages/plugin-axios/templates/axios.test.ts index dce0c1197..1bf430224 100644 --- a/packages/plugin-axios/templates/axios.test.ts +++ b/packages/plugin-axios/templates/axios.test.ts @@ -728,12 +728,6 @@ describe('withUnwrap', () => { }) }) - test('the wrapped promise still resolves to the full result when awaited directly', async () => { - const full = { data: { id: 1 }, error: undefined } - const result = await withUnwrap(Promise.resolve(full)) - expect(result).toBe(full) - }) - test('a rejected call propagates the rejection unchanged', async () => { const error = new ResponseError({ data: { message: 'not found' }, status: 404, statusText: 'Not Found', request: {}, response: {} }) await expect(withUnwrap(Promise.reject(error)).unwrap()).rejects.toBe(error) diff --git a/packages/plugin-axios/templates/axios.ts b/packages/plugin-axios/templates/axios.ts index bc1594660..bc9ab52f3 100644 --- a/packages/plugin-axios/templates/axios.ts +++ b/packages/plugin-axios/templates/axios.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/packages/plugin-fetch/templates/fetch.test.ts b/packages/plugin-fetch/templates/fetch.test.ts index 1f364c42b..2dbff01ae 100644 --- a/packages/plugin-fetch/templates/fetch.test.ts +++ b/packages/plugin-fetch/templates/fetch.test.ts @@ -660,12 +660,6 @@ describe('withUnwrap', () => { await expect(withUnwrap(Promise.resolve({ data: undefined, error: { message: 'invalid' } })).unwrap()).rejects.toStrictEqual({ message: 'invalid' }) }) - test('the wrapped promise still resolves to the full result when awaited directly', async () => { - const full = { data: { id: 1 }, error: undefined } - const result = await withUnwrap(Promise.resolve(full)) - expect(result).toBe(full) - }) - test('a rejected call propagates the rejection unchanged', async () => { const error = new ResponseError({ data: { message: 'invalid' }, status: 405, statusText: 'Method Not Allowed', request: 'REQ', response: 'RES' }) await expect(withUnwrap(Promise.reject(error)).unwrap()).rejects.toBe(error) diff --git a/packages/plugin-fetch/templates/fetch.ts b/packages/plugin-fetch/templates/fetch.ts index 064cff868..52b3b743f 100644 --- a/packages/plugin-fetch/templates/fetch.ts +++ b/packages/plugin-fetch/templates/fetch.ts @@ -83,29 +83,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } - -/** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts index 064cff868..52b3b743f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts @@ -83,29 +83,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } - -/** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts index 064cff868..52b3b743f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts @@ -83,29 +83,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } - -/** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts index 064cff868..52b3b743f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts @@ -83,29 +83,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } - -/** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts index 064cff868..52b3b743f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts @@ -83,29 +83,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } - -/** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts index 064cff868..52b3b743f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts @@ -83,29 +83,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } - -/** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts index 064cff868..52b3b743f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts @@ -83,29 +83,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } - -/** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts index 064cff868..52b3b743f 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts @@ -83,29 +83,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } - -/** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts index bc1594660..bc9ab52f3 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts @@ -85,29 +85,37 @@ export type RequestResult /** - * The success body of a `RequestResult`, picked out by its `error: undefined` discriminant so an - * error variant's `data: undefined` can never widen it. - */ -export type UnwrapResult = Extract['data'] - -/** - * A `RequestResult` promise with an extra `unwrap()` method, Redux-Toolkit-style: `unwrap()` - * resolves to the bare success body, or rejects with `error` for a result that carried one - * (only reachable with `throwOnError: false`, since the throwing path never resolves an error). - */ -export type Unwrappable = Promise & { unwrap: () => Promise> } + * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. + * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried + * one. Only `throwOnError: false` can reach that rejection, because the throwing path never + * resolves an error in the first place. + * + * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's + * `data: undefined` can never widen it. + * + * @example + * `Unwrappable>` + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} /** - * Attaches `unwrap()` to a call's result promise. Generated operations call this so every result - * doubles as a plain promise (`await getPetById(...)`) and an RTK-style unwrap - * (`await getPetById(...).unwrap()`). + * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, + * so the same value works as a plain promise and as an unwrap. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` */ export function withUnwrap(promise: Promise): Unwrappable { const unwrappable = promise as Unwrappable unwrappable.unwrap = () => promise.then((result) => { if (result.error !== undefined) throw result.error - return result.data as UnwrapResult + return result.data as Extract['data'] }) return unwrappable } From 53cf00b4c73c1f3a01f5c8963d8f0feca12d5a1b Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Wed, 2 Sep 2026 13:24:38 +0200 Subject: [PATCH 6/9] docs: simplify unwrap() jsdoc in the fetch and axios templates --- packages/plugin-axios/templates/axios.ts | 14 ++------------ packages/plugin-fetch/templates/fetch.ts | 14 ++------------ .../pluginAxios/default/.kubb/client.ts | 14 ++------------ .../pluginAxios/paramsCasing/.kubb/client.ts | 14 ++------------ .../pluginAxios/sdkClass/.kubb/client.ts | 14 ++------------ .../pluginAxios/sdkClassWithName/.kubb/client.ts | 14 ++------------ .../pluginAxios/sdkSingle/.kubb/client.ts | 14 ++------------ .../pluginAxios/zodTypes/.kubb/client.ts | 14 ++------------ .../pluginFetch/default/.kubb/client.ts | 14 ++------------ .../pluginFetch/paramsCasing/.kubb/client.ts | 14 ++------------ .../pluginFetch/sdkClass/.kubb/client.ts | 14 ++------------ .../pluginFetch/sdkClassWithName/.kubb/client.ts | 14 ++------------ .../pluginFetch/sdkSingle/.kubb/client.ts | 14 ++------------ .../pluginFetch/zodTypes/.kubb/client.ts | 14 ++------------ .../pluginFetch/zodTypesSdk/.kubb/client.ts | 14 ++------------ .../pluginMcp/excludeByOperationId/.kubb/client.ts | 14 ++------------ .../pluginMcp/groupByTag/.kubb/client.ts | 14 ++------------ .../pluginMcp/includeByTag/.kubb/client.ts | 14 ++------------ .../pluginMcp/paramsCasing/.kubb/client.ts | 14 ++------------ .../pluginMcp/petStore/.kubb/client.ts | 14 ++------------ .../pluginMcp/withClientPlugin/.kubb/client.ts | 14 ++------------ .../excludeByOperationId/.kubb/client.ts | 14 ++------------ .../pluginReactQuery/groupByTag/.kubb/client.ts | 14 ++------------ .../pluginReactQuery/includeByTag/.kubb/client.ts | 14 ++------------ .../pluginReactQuery/infinite/.kubb/client.ts | 14 ++------------ .../mutationDisabled/.kubb/client.ts | 14 ++------------ .../pluginReactQuery/paramsCasing/.kubb/client.ts | 14 ++------------ .../pluginReactQuery/parserZod/.kubb/client.ts | 14 ++------------ .../pluginReactQuery/petStore/.kubb/client.ts | 14 ++------------ .../pluginReactQuery/queryMethods/.kubb/client.ts | 14 ++------------ .../pluginReactQuery/suspense/.kubb/client.ts | 14 ++------------ .../withClientPlugin/.kubb/client.ts | 14 ++------------ .../pluginSwr/excludeByOperationId/.kubb/client.ts | 14 ++------------ .../pluginSwr/groupByTag/.kubb/client.ts | 14 ++------------ .../pluginSwr/includeByTag/.kubb/client.ts | 14 ++------------ .../pluginSwr/mutationDisabled/.kubb/client.ts | 14 ++------------ .../pluginSwr/paramsCasing/.kubb/client.ts | 14 ++------------ .../pluginSwr/parserZod/.kubb/client.ts | 14 ++------------ .../pluginSwr/petStore/.kubb/client.ts | 14 ++------------ .../pluginSwr/queryDisabled/.kubb/client.ts | 14 ++------------ .../pluginSwr/queryMethods/.kubb/client.ts | 14 ++------------ .../pluginSwr/withClientPlugin/.kubb/client.ts | 14 ++------------ .../excludeByOperationId/.kubb/client.ts | 14 ++------------ .../pluginVueQuery/groupByTag/.kubb/client.ts | 14 ++------------ .../pluginVueQuery/includeByTag/.kubb/client.ts | 14 ++------------ .../pluginVueQuery/infinite/.kubb/client.ts | 14 ++------------ .../mutationDisabled/.kubb/client.ts | 14 ++------------ .../pluginVueQuery/paramsCasing/.kubb/client.ts | 14 ++------------ .../pluginVueQuery/parserZod/.kubb/client.ts | 14 ++------------ .../pluginVueQuery/petStore/.kubb/client.ts | 14 ++------------ .../withClientPlugin/.kubb/client.ts | 14 ++------------ 51 files changed, 102 insertions(+), 612 deletions(-) diff --git a/packages/plugin-axios/templates/axios.ts b/packages/plugin-axios/templates/axios.ts index bc9ab52f3..9ccace88f 100644 --- a/packages/plugin-axios/templates/axios.ts +++ b/packages/plugin-axios/templates/axios.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/packages/plugin-fetch/templates/fetch.ts b/packages/plugin-fetch/templates/fetch.ts index 52b3b743f..ea6223eff 100644 --- a/packages/plugin-fetch/templates/fetch.ts +++ b/packages/plugin-fetch/templates/fetch.ts @@ -83,24 +83,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/default/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/paramsCasing/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClass/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkClassWithName/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/sdkSingle/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginAxios/zodTypes/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts index 52b3b743f..ea6223eff 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/default/.kubb/client.ts @@ -83,24 +83,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts index 52b3b743f..ea6223eff 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/paramsCasing/.kubb/client.ts @@ -83,24 +83,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts index 52b3b743f..ea6223eff 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClass/.kubb/client.ts @@ -83,24 +83,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts index 52b3b743f..ea6223eff 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkClassWithName/.kubb/client.ts @@ -83,24 +83,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts index 52b3b743f..ea6223eff 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/sdkSingle/.kubb/client.ts @@ -83,24 +83,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts index 52b3b743f..ea6223eff 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypes/.kubb/client.ts @@ -83,24 +83,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts index 52b3b743f..ea6223eff 100644 --- a/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginFetch/zodTypesSdk/.kubb/client.ts @@ -83,24 +83,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/excludeByOperationId/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/groupByTag/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/includeByTag/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/paramsCasing/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/petStore/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginMcp/withClientPlugin/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts index bc9ab52f3..9ccace88f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/.kubb/client.ts @@ -85,24 +85,14 @@ export type RequestResult /** - * A `RequestResult` promise with an extra `unwrap()` method, the way Redux Toolkit does it. - * `unwrap()` resolves to the bare success body, or rejects with `error` when the result carried - * one. Only `throwOnError: false` can reach that rejection, because the throwing path never - * resolves an error in the first place. - * - * `Extract` picks the success body by the `error: undefined` discriminant, so an error variant's - * `data: undefined` can never widen it. - * - * @example - * `Unwrappable>` + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. */ export type Unwrappable = Promise & { unwrap: () => Promise['data']> } /** - * Attaches `unwrap()` to a call's result promise. Generated operations wrap every result with this, - * so the same value works as a plain promise and as an unwrap. + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. * * @example Full result * `const { data, error } = await getPetById({ path: { petId: 1 } })` From f158d75f98fb93bb4b1d21b6ab449e39d65bdd18 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 2 Sep 2026 14:31:15 +0200 Subject: [PATCH 7/9] chore(examples): update generated files (#823) --- examples/advanced/src/gen/.kubb/client.ts | 26 +++++++ .../gen/clients/axios/petService/addFiles.ts | 8 +- .../gen/clients/axios/petService/addPet.ts | 22 +++--- .../gen/clients/axios/petService/deletePet.ts | 22 +++--- .../axios/petService/findPetsByStatus.ts | 22 +++--- .../axios/petService/findPetsByTags.ts | 24 +++--- .../clients/axios/petService/getPetById.ts | 22 +++--- .../gen/clients/axios/petService/updatePet.ts | 22 +++--- .../axios/petService/updatePetWithForm.ts | 22 +++--- .../clients/axios/petService/uploadFile.ts | 22 +++--- .../clients/axios/petsService/createPets.ts | 17 ++-- examples/axios/src/gen/.kubb/client.ts | 26 +++++++ examples/axios/src/gen/clients/pet/addPet.ts | 10 ++- .../axios/src/gen/clients/pet/deletePet.ts | 12 +-- .../src/gen/clients/pet/findPetsByStatus.ts | 22 +++--- .../src/gen/clients/pet/findPetsByTags.ts | 18 ++--- .../axios/src/gen/clients/pet/getPetById.ts | 17 ++-- .../axios/src/gen/clients/pet/updatePet.ts | 10 ++- .../src/gen/clients/pet/updatePetWithForm.ts | 14 ++-- .../axios/src/gen/clients/pet/uploadFile.ts | 14 ++-- .../src/gen/clients/store/deleteOrder.ts | 8 +- .../src/gen/clients/store/getInventory.ts | 14 ++-- .../src/gen/clients/store/getOrderById.ts | 8 +- .../axios/src/gen/clients/store/placeOrder.ts | 8 +- .../src/gen/clients/store/placeOrderPatch.ts | 8 +- .../axios/src/gen/clients/user/createUser.ts | 8 +- .../clients/user/createUsersWithListInput.ts | 10 ++- .../axios/src/gen/clients/user/deleteUser.ts | 8 +- .../src/gen/clients/user/getUserByName.ts | 8 +- .../axios/src/gen/clients/user/loginUser.ts | 8 +- .../axios/src/gen/clients/user/logoutUser.ts | 8 +- .../axios/src/gen/clients/user/updateUser.ts | 8 +- examples/fetch/src/gen/.kubb/client.ts | 26 +++++++ examples/fetch/src/gen/clients/pet/addPet.ts | 10 ++- .../fetch/src/gen/clients/pet/deletePet.ts | 12 +-- .../src/gen/clients/pet/findPetsByStatus.ts | 22 +++--- .../src/gen/clients/pet/findPetsByTags.ts | 18 ++--- .../fetch/src/gen/clients/pet/getPetById.ts | 17 ++-- .../fetch/src/gen/clients/pet/updatePet.ts | 10 ++- .../src/gen/clients/pet/updatePetWithForm.ts | 14 ++-- .../fetch/src/gen/clients/pet/uploadFile.ts | 14 ++-- .../src/gen/clients/store/deleteOrder.ts | 8 +- .../src/gen/clients/store/getInventory.ts | 14 ++-- .../src/gen/clients/store/getOrderById.ts | 8 +- .../fetch/src/gen/clients/store/placeOrder.ts | 8 +- .../src/gen/clients/store/placeOrderPatch.ts | 8 +- .../fetch/src/gen/clients/user/createUser.ts | 8 +- .../clients/user/createUsersWithListInput.ts | 10 ++- .../fetch/src/gen/clients/user/deleteUser.ts | 8 +- .../src/gen/clients/user/getUserByName.ts | 8 +- .../fetch/src/gen/clients/user/loginUser.ts | 8 +- .../fetch/src/gen/clients/user/logoutUser.ts | 8 +- .../fetch/src/gen/clients/user/updateUser.ts | 8 +- examples/mcp/src/gen/.kubb/client.ts | 26 +++++++ examples/mcp/src/gen/clients/addFiles.ts | 8 +- examples/mcp/src/gen/clients/addPet.ts | 10 ++- examples/mcp/src/gen/clients/createPets.ts | 8 +- examples/mcp/src/gen/clients/deleteOrder.ts | 8 +- examples/mcp/src/gen/clients/deletePet.ts | 12 +-- .../mcp/src/gen/clients/findPetsByStatus.ts | 14 ++-- .../mcp/src/gen/clients/findPetsByTags.ts | 18 ++--- examples/mcp/src/gen/clients/getInventory.ts | 14 ++-- examples/mcp/src/gen/clients/getOrderById.ts | 8 +- examples/mcp/src/gen/clients/getPetById.ts | 17 ++-- examples/mcp/src/gen/clients/placeOrder.ts | 8 +- .../mcp/src/gen/clients/placeOrderPatch.ts | 8 +- examples/mcp/src/gen/clients/updatePet.ts | 10 ++- .../mcp/src/gen/clients/updatePetWithForm.ts | 14 ++-- examples/react-query/src/gen/.kubb/client.ts | 26 +++++++ .../react-query/src/gen/clients/pet/addPet.ts | 10 ++- .../src/gen/clients/pet/deletePet.ts | 12 +-- .../src/gen/clients/pet/findPetsByStatus.ts | 22 +++--- .../src/gen/clients/pet/findPetsByTags.ts | 18 ++--- .../src/gen/clients/pet/getPetById.ts | 17 ++-- .../src/gen/clients/pet/updatePet.ts | 10 ++- .../src/gen/clients/pet/updatePetWithForm.ts | 14 ++-- .../src/gen/clients/pet/uploadFile.ts | 14 ++-- .../src/gen/clients/store/deleteOrder.ts | 8 +- .../src/gen/clients/store/getInventory.ts | 14 ++-- .../src/gen/clients/store/getOrderById.ts | 8 +- .../src/gen/clients/store/placeOrder.ts | 8 +- .../src/gen/clients/store/placeOrderPatch.ts | 8 +- .../src/gen/clients/user/createUser.ts | 8 +- .../clients/user/createUsersWithListInput.ts | 10 ++- .../src/gen/clients/user/deleteUser.ts | 8 +- .../src/gen/clients/user/getUserByName.ts | 8 +- .../src/gen/clients/user/loginUser.ts | 8 +- .../src/gen/clients/user/logoutUser.ts | 8 +- .../src/gen/clients/user/updateUser.ts | 8 +- examples/sdk/src/gen/.kubb/client.ts | 26 +++++++ examples/sdk/src/gen/sdk/pet/pet.ts | 77 +++++++++++-------- examples/sdk/src/gen/sdk/store/store.ts | 30 ++++---- .../simple-single/src/gen/.kubb/client.ts | 26 +++++++ .../simple-single/src/gen/clients/addPet.ts | 10 ++- .../src/gen/clients/deleteOrder.ts | 8 +- .../src/gen/clients/deletePet.ts | 12 +-- .../src/gen/clients/findPetsByStatus.ts | 22 +++--- .../src/gen/clients/findPetsByTags.ts | 18 ++--- .../src/gen/clients/getInventory.ts | 14 ++-- .../src/gen/clients/getOrderById.ts | 8 +- .../src/gen/clients/getPetById.ts | 17 ++-- .../src/gen/clients/placeOrder.ts | 8 +- .../src/gen/clients/placeOrderPatch.ts | 8 +- .../src/gen/clients/updatePet.ts | 10 ++- .../src/gen/clients/updatePetWithForm.ts | 14 ++-- .../src/gen/clients/uploadFile.ts | 22 +++--- examples/swr/src/gen/.kubb/client.ts | 26 +++++++ examples/swr/src/gen/clients/pet/addPet.ts | 10 ++- examples/swr/src/gen/clients/pet/deletePet.ts | 12 +-- .../src/gen/clients/pet/findPetsByStatus.ts | 22 +++--- .../swr/src/gen/clients/pet/findPetsByTags.ts | 18 ++--- .../swr/src/gen/clients/pet/getPetById.ts | 17 ++-- examples/swr/src/gen/clients/pet/updatePet.ts | 10 ++- .../src/gen/clients/pet/updatePetWithForm.ts | 14 ++-- .../swr/src/gen/clients/pet/uploadFile.ts | 14 ++-- .../swr/src/gen/clients/store/deleteOrder.ts | 8 +- .../swr/src/gen/clients/store/getInventory.ts | 14 ++-- .../swr/src/gen/clients/store/getOrderById.ts | 8 +- .../swr/src/gen/clients/store/placeOrder.ts | 8 +- .../src/gen/clients/store/placeOrderPatch.ts | 8 +- .../swr/src/gen/clients/user/createUser.ts | 8 +- .../clients/user/createUsersWithListInput.ts | 10 ++- .../swr/src/gen/clients/user/deleteUser.ts | 8 +- .../swr/src/gen/clients/user/getUserByName.ts | 8 +- .../swr/src/gen/clients/user/loginUser.ts | 8 +- .../swr/src/gen/clients/user/logoutUser.ts | 8 +- .../swr/src/gen/clients/user/updateUser.ts | 8 +- examples/vue-query/src/gen/.kubb/client.ts | 26 +++++++ .../vue-query/src/gen/clients/pet/addPet.ts | 10 ++- .../src/gen/clients/pet/deletePet.ts | 12 +-- .../src/gen/clients/pet/findPetsByStatus.ts | 22 +++--- .../src/gen/clients/pet/findPetsByTags.ts | 18 ++--- .../src/gen/clients/pet/getPetById.ts | 17 ++-- .../src/gen/clients/pet/updatePet.ts | 10 ++- .../src/gen/clients/pet/updatePetWithForm.ts | 14 ++-- .../src/gen/clients/pet/uploadFile.ts | 14 ++-- .../src/gen/clients/store/deleteOrder.ts | 8 +- .../src/gen/clients/store/getInventory.ts | 14 ++-- .../src/gen/clients/store/getOrderById.ts | 8 +- .../src/gen/clients/store/placeOrder.ts | 8 +- .../src/gen/clients/store/placeOrderPatch.ts | 8 +- .../src/gen/clients/user/createUser.ts | 8 +- .../clients/user/createUsersWithListInput.ts | 10 ++- .../src/gen/clients/user/deleteUser.ts | 8 +- .../src/gen/clients/user/getUserByName.ts | 8 +- .../src/gen/clients/user/loginUser.ts | 8 +- .../src/gen/clients/user/logoutUser.ts | 8 +- .../src/gen/clients/user/updateUser.ts | 8 +- 148 files changed, 1155 insertions(+), 822 deletions(-) diff --git a/examples/advanced/src/gen/.kubb/client.ts b/examples/advanced/src/gen/.kubb/client.ts index 72bedcf64..cb9cb6470 100644 --- a/examples/advanced/src/gen/.kubb/client.ts +++ b/examples/advanced/src/gen/.kubb/client.ts @@ -84,6 +84,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/advanced/src/gen/clients/axios/petService/addFiles.ts b/examples/advanced/src/gen/clients/axios/petService/addFiles.ts index 46c56c7c1..31de976f7 100644 --- a/examples/advanced/src/gen/clients/axios/petService/addFiles.ts +++ b/examples/advanced/src/gen/clients/axios/petService/addFiles.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { AddFilesOptions, AddFilesResponses } from '../../../models/ts/pet/AddFiles' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' /** * @description Place a new file in the store @@ -9,8 +9,8 @@ import { client } from '../../../.kubb/client' */ export function addFiles( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/files', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/files', ...config }) as Promise>) } diff --git a/examples/advanced/src/gen/clients/axios/petService/addPet.ts b/examples/advanced/src/gen/clients/axios/petService/addPet.ts index b434cfb41..e72908e8c 100644 --- a/examples/advanced/src/gen/clients/axios/petService/addPet.ts +++ b/examples/advanced/src/gen/clients/axios/petService/addPet.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../../../models/ts/pet/AddPet' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' import { addPetResponseSchema, addPetErrorSchema } from '../../../zod/pet/addPetSchema' /** @@ -10,14 +10,16 @@ import { addPetResponseSchema, addPetErrorSchema } from '../../../zod/pet/addPet */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'POST', - url: '/pet', - security: [{ type: 'oauth2' }], - validator: { response: addPetResponseSchema, error: addPetErrorSchema }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'POST', + url: '/pet', + security: [{ type: 'oauth2' }], + validator: { response: addPetResponseSchema, error: addPetErrorSchema }, + ...config, + }) as Promise>, + ) } diff --git a/examples/advanced/src/gen/clients/axios/petService/deletePet.ts b/examples/advanced/src/gen/clients/axios/petService/deletePet.ts index 6661b56cc..3b43fbe5f 100644 --- a/examples/advanced/src/gen/clients/axios/petService/deletePet.ts +++ b/examples/advanced/src/gen/clients/axios/petService/deletePet.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../../../models/ts/pet/DeletePet' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' import { deletePetResponseSchema, deletePetErrorSchema } from '../../../zod/pet/deletePetSchema' /** @@ -10,14 +10,16 @@ import { deletePetResponseSchema, deletePetErrorSchema } from '../../../zod/pet/ */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'DELETE', - url: '/pet/{petId}:search', - security: [{ type: 'oauth2' }], - validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'DELETE', + url: '/pet/{petId}:search', + security: [{ type: 'oauth2' }], + validator: { response: deletePetResponseSchema, error: deletePetErrorSchema }, + ...config, + }) as Promise>, + ) } diff --git a/examples/advanced/src/gen/clients/axios/petService/findPetsByStatus.ts b/examples/advanced/src/gen/clients/axios/petService/findPetsByStatus.ts index 620dbf972..9ea2dd6a8 100644 --- a/examples/advanced/src/gen/clients/axios/petService/findPetsByStatus.ts +++ b/examples/advanced/src/gen/clients/axios/petService/findPetsByStatus.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../../../models/ts/pet/FindPetsByStatus' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../../../zod/pet/findPetsByStatusSchema' /** @@ -10,14 +10,16 @@ import { findPetsByStatusResponseSchema, findPetsByStatusErrorSchema } from '../ */ export function findPetsByStatus( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByStatus/{step_id}', - security: [{ type: 'oauth2' }], - validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/findByStatus/{step_id}', + security: [{ type: 'oauth2' }], + validator: { response: findPetsByStatusResponseSchema, error: findPetsByStatusErrorSchema }, + ...config, + }) as Promise>, + ) } diff --git a/examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts b/examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts index 61d92758f..ee7242ca4 100644 --- a/examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts +++ b/examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from '../../../models/ts/pet/FindPetsByTags' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' import { findPetsByTagsResponseSchema, findPetsByTagsErrorSchema } from '../../../zod/pet/findPetsByTagsSchema' /** @@ -10,15 +10,17 @@ import { findPetsByTagsResponseSchema, findPetsByTagsErrorSchema } from '../../. */ export function findPetsByTags( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByTags', - security: [{ type: 'oauth2' }], - styles: { query: { tags: { explode: true } } }, - validator: { response: findPetsByTagsResponseSchema, error: findPetsByTagsErrorSchema }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/findByTags', + security: [{ type: 'oauth2' }], + styles: { query: { tags: { explode: true } } }, + validator: { response: findPetsByTagsResponseSchema, error: findPetsByTagsErrorSchema }, + ...config, + }) as Promise>, + ) } diff --git a/examples/advanced/src/gen/clients/axios/petService/getPetById.ts b/examples/advanced/src/gen/clients/axios/petService/getPetById.ts index 2fc916be0..8904f6486 100644 --- a/examples/advanced/src/gen/clients/axios/petService/getPetById.ts +++ b/examples/advanced/src/gen/clients/axios/petService/getPetById.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../../../models/ts/pet/GetPetById' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../../../zod/pet/getPetByIdSchema' /** @@ -10,14 +10,16 @@ import { getPetByIdResponseSchema, getPetByIdErrorSchema } from '../../../zod/pe */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}:search', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/{petId}:search', + security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], + validator: { response: getPetByIdResponseSchema, error: getPetByIdErrorSchema }, + ...config, + }) as Promise>, + ) } diff --git a/examples/advanced/src/gen/clients/axios/petService/updatePet.ts b/examples/advanced/src/gen/clients/axios/petService/updatePet.ts index 7a15569f8..de286c676 100644 --- a/examples/advanced/src/gen/clients/axios/petService/updatePet.ts +++ b/examples/advanced/src/gen/clients/axios/petService/updatePet.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../../../models/ts/pet/UpdatePet' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' import { updatePetResponseSchema, updatePetErrorSchema } from '../../../zod/pet/updatePetSchema' /** @@ -10,14 +10,16 @@ import { updatePetResponseSchema, updatePetErrorSchema } from '../../../zod/pet/ */ export function updatePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'PUT', - url: '/pet', - security: [{ type: 'oauth2' }], - validator: { response: updatePetResponseSchema, error: updatePetErrorSchema }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'PUT', + url: '/pet', + security: [{ type: 'oauth2' }], + validator: { response: updatePetResponseSchema, error: updatePetErrorSchema }, + ...config, + }) as Promise>, + ) } diff --git a/examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts b/examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts index f7b71e1cd..3638ec754 100644 --- a/examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts +++ b/examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../../../models/ts/pet/UpdatePetWithForm' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' import { updatePetWithFormResponseSchema, updatePetWithFormErrorSchema } from '../../../zod/pet/updatePetWithFormSchema' /** @@ -9,14 +9,16 @@ import { updatePetWithFormResponseSchema, updatePetWithFormErrorSchema } from '. */ export function updatePetWithForm( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'POST', - url: '/pet/{petId}:search', - security: [{ type: 'oauth2' }], - validator: { response: updatePetWithFormResponseSchema, error: updatePetWithFormErrorSchema }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'POST', + url: '/pet/{petId}:search', + security: [{ type: 'oauth2' }], + validator: { response: updatePetWithFormResponseSchema, error: updatePetWithFormErrorSchema }, + ...config, + }) as Promise>, + ) } diff --git a/examples/advanced/src/gen/clients/axios/petService/uploadFile.ts b/examples/advanced/src/gen/clients/axios/petService/uploadFile.ts index 19097e39c..0739b656a 100644 --- a/examples/advanced/src/gen/clients/axios/petService/uploadFile.ts +++ b/examples/advanced/src/gen/clients/axios/petService/uploadFile.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../../../models/ts/pet/UploadFile' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' /** * @summary uploads an image @@ -8,14 +8,16 @@ import { client } from '../../../.kubb/client' */ export function uploadFile( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'POST', - url: '/pet/{petId}/uploadImage', - security: [{ type: 'oauth2' }], - contentType: { request: 'application/octet-stream' }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'POST', + url: '/pet/{petId}/uploadImage', + security: [{ type: 'oauth2' }], + contentType: { request: 'application/octet-stream' }, + ...config, + }) as Promise>, + ) } diff --git a/examples/advanced/src/gen/clients/axios/petsService/createPets.ts b/examples/advanced/src/gen/clients/axios/petsService/createPets.ts index 972e97865..aa822557c 100644 --- a/examples/advanced/src/gen/clients/axios/petsService/createPets.ts +++ b/examples/advanced/src/gen/clients/axios/petsService/createPets.ts @@ -1,6 +1,6 @@ -import type { Options, RequestResult } from '../../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../../.kubb/client' import type { CreatePetsOptions, CreatePetsResponses } from '../../../models/ts/pets/CreatePets' -import { client } from '../../../.kubb/client' +import { client, withUnwrap } from '../../../.kubb/client' import { createPetsResponseSchema, createPetsErrorSchema } from '../../../zod/pets/createPetsSchema' /** @@ -9,13 +9,12 @@ import { createPetsResponseSchema, createPetsErrorSchema } from '../../../zod/pe */ export function createPets( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'POST', - url: '/pets/{uuid}', - validator: { response: createPetsResponseSchema, error: createPetsErrorSchema }, - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pets/{uuid}', validator: { response: createPetsResponseSchema, error: createPetsErrorSchema }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/axios/src/gen/.kubb/client.ts b/examples/axios/src/gen/.kubb/client.ts index d928c18f3..9ccace88f 100644 --- a/examples/axios/src/gen/.kubb/client.ts +++ b/examples/axios/src/gen/.kubb/client.ts @@ -84,6 +84,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/axios/src/gen/clients/pet/addPet.ts b/examples/axios/src/gen/clients/pet/addPet.ts index 952e15db2..3628776a0 100644 --- a/examples/axios/src/gen/clients/pet/addPet.ts +++ b/examples/axios/src/gen/clients/pet/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../../models/pet/AddPet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Add a new pet to the store @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/axios/src/gen/clients/pet/deletePet.ts b/examples/axios/src/gen/clients/pet/deletePet.ts index 24725dc26..8fe616c13 100644 --- a/examples/axios/src/gen/clients/pet/deletePet.ts +++ b/examples/axios/src/gen/clients/pet/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../../models/pet/DeletePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description delete a pet @@ -14,10 +14,10 @@ import { client } from '../../.kubb/client' */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/axios/src/gen/clients/pet/findPetsByStatus.ts b/examples/axios/src/gen/clients/pet/findPetsByStatus.ts index 306835cef..78c47179c 100644 --- a/examples/axios/src/gen/clients/pet/findPetsByStatus.ts +++ b/examples/axios/src/gen/clients/pet/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../../models/pet/FindPetsByStatus' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings @@ -14,14 +14,16 @@ import { client } from '../../.kubb/client' */ export function findPetsByStatus( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByStatus', - security: [{ type: 'oauth2' }], - styles: { query: { status: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/findByStatus', + security: [{ type: 'oauth2' }], + styles: { query: { status: { explode: true } } }, + ...config, + }) as Promise>, + ) } diff --git a/examples/axios/src/gen/clients/pet/findPetsByTags.ts b/examples/axios/src/gen/clients/pet/findPetsByTags.ts index b7227971b..e4b9b5f55 100644 --- a/examples/axios/src/gen/clients/pet/findPetsByTags.ts +++ b/examples/axios/src/gen/clients/pet/findPetsByTags.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from '../../models/pet/FindPetsByTags' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -14,14 +14,12 @@ import { client } from '../../.kubb/client' */ export function findPetsByTags( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByTags', - security: [{ type: 'oauth2' }], - styles: { query: { tags: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], styles: { query: { tags: { explode: true } } }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/axios/src/gen/clients/pet/getPetById.ts b/examples/axios/src/gen/clients/pet/getPetById.ts index 771e59ee1..81e309e82 100644 --- a/examples/axios/src/gen/clients/pet/getPetById.ts +++ b/examples/axios/src/gen/clients/pet/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../../models/pet/GetPetById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a single pet @@ -14,13 +14,12 @@ import { client } from '../../.kubb/client' */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/axios/src/gen/clients/pet/updatePet.ts b/examples/axios/src/gen/clients/pet/updatePet.ts index 7a287a9fe..f662fd79f 100644 --- a/examples/axios/src/gen/clients/pet/updatePet.ts +++ b/examples/axios/src/gen/clients/pet/updatePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../../models/pet/UpdatePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Update an existing pet by Id @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function updatePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/axios/src/gen/clients/pet/updatePetWithForm.ts b/examples/axios/src/gen/clients/pet/updatePetWithForm.ts index f36371438..1db98bc49 100644 --- a/examples/axios/src/gen/clients/pet/updatePetWithForm.ts +++ b/examples/axios/src/gen/clients/pet/updatePetWithForm.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../../models/pet/UpdatePetWithForm' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Updates a pet in the store with form data @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function updatePetWithForm( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/axios/src/gen/clients/pet/uploadFile.ts b/examples/axios/src/gen/clients/pet/uploadFile.ts index 65e79b47b..92ce7c699 100644 --- a/examples/axios/src/gen/clients/pet/uploadFile.ts +++ b/examples/axios/src/gen/clients/pet/uploadFile.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../../models/pet/UploadFile' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary uploads an image @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function uploadFile( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/axios/src/gen/clients/store/deleteOrder.ts b/examples/axios/src/gen/clients/store/deleteOrder.ts index 74eec3514..689cbaa9a 100644 --- a/examples/axios/src/gen/clients/store/deleteOrder.ts +++ b/examples/axios/src/gen/clients/store/deleteOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteOrderOptions, DeleteOrderResponses } from '../../models/store/DeleteOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/store/getInventory.ts b/examples/axios/src/gen/clients/store/getInventory.ts index f011e8dde..d44938f8e 100644 --- a/examples/axios/src/gen/clients/store/getInventory.ts +++ b/examples/axios/src/gen/clients/store/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../../models/store/GetInventory' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a map of status codes to quantities @@ -14,10 +14,12 @@ import { client } from '../../.kubb/client' */ export function getInventory( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/axios/src/gen/clients/store/getOrderById.ts b/examples/axios/src/gen/clients/store/getOrderById.ts index 91aa5bd78..a3ce96a72 100644 --- a/examples/axios/src/gen/clients/store/getOrderById.ts +++ b/examples/axios/src/gen/clients/store/getOrderById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetOrderByIdOptions, GetOrderByIdResponses } from '../../models/store/GetOrderById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function getOrderById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/store/placeOrder.ts b/examples/axios/src/gen/clients/store/placeOrder.ts index 8c1d56394..3a3da9192 100644 --- a/examples/axios/src/gen/clients/store/placeOrder.ts +++ b/examples/axios/src/gen/clients/store/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../../models/store/PlaceOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/store/placeOrderPatch.ts b/examples/axios/src/gen/clients/store/placeOrderPatch.ts index 0772af4f7..692337b25 100644 --- a/examples/axios/src/gen/clients/store/placeOrderPatch.ts +++ b/examples/axios/src/gen/clients/store/placeOrderPatch.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderPatchOptions, PlaceOrderPatchResponses } from '../../models/store/PlaceOrderPatch' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store with patch @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrderPatch( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PATCH', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'PATCH', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/user/createUser.ts b/examples/axios/src/gen/clients/user/createUser.ts index af5bbc3e7..d9c8c13bc 100644 --- a/examples/axios/src/gen/clients/user/createUser.ts +++ b/examples/axios/src/gen/clients/user/createUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUserOptions, CreateUserResponses } from '../../models/user/CreateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function createUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/user', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/user/createUsersWithListInput.ts b/examples/axios/src/gen/clients/user/createUsersWithListInput.ts index b69d5d908..1e6a9e2ac 100644 --- a/examples/axios/src/gen/clients/user/createUsersWithListInput.ts +++ b/examples/axios/src/gen/clients/user/createUsersWithListInput.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUsersWithListInputOptions, CreateUsersWithListInputResponses } from '../../models/user/CreateUsersWithListInput' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Creates list of users with given input array @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function createUsersWithListInput( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise>, + ) } diff --git a/examples/axios/src/gen/clients/user/deleteUser.ts b/examples/axios/src/gen/clients/user/deleteUser.ts index dff00a13e..8dda91163 100644 --- a/examples/axios/src/gen/clients/user/deleteUser.ts +++ b/examples/axios/src/gen/clients/user/deleteUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteUserOptions, DeleteUserResponses } from '../../models/user/DeleteUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/user/getUserByName.ts b/examples/axios/src/gen/clients/user/getUserByName.ts index 4db3b9d4d..2e0afe704 100644 --- a/examples/axios/src/gen/clients/user/getUserByName.ts +++ b/examples/axios/src/gen/clients/user/getUserByName.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetUserByNameOptions, GetUserByNameResponses } from '../../models/user/GetUserByName' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Get user by user name @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function getUserByName( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/user/loginUser.ts b/examples/axios/src/gen/clients/user/loginUser.ts index b619b4b9b..4a46c2208 100644 --- a/examples/axios/src/gen/clients/user/loginUser.ts +++ b/examples/axios/src/gen/clients/user/loginUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LoginUserOptions, LoginUserResponses } from '../../models/user/LoginUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs user into the system @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function loginUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/login', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/login', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/user/logoutUser.ts b/examples/axios/src/gen/clients/user/logoutUser.ts index e41276de9..a5c939fbb 100644 --- a/examples/axios/src/gen/clients/user/logoutUser.ts +++ b/examples/axios/src/gen/clients/user/logoutUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LogoutUserOptions, LogoutUserResponses } from '../../models/user/LogoutUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs out current logged in user session @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function logoutUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/logout', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/logout', ...config }) as Promise>) } diff --git a/examples/axios/src/gen/clients/user/updateUser.ts b/examples/axios/src/gen/clients/user/updateUser.ts index ce0faef1f..b6c6e7de1 100644 --- a/examples/axios/src/gen/clients/user/updateUser.ts +++ b/examples/axios/src/gen/clients/user/updateUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdateUserOptions, UpdateUserResponses } from '../../models/user/UpdateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function updateUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/.kubb/client.ts b/examples/fetch/src/gen/.kubb/client.ts index f80182aca..ea6223eff 100644 --- a/examples/fetch/src/gen/.kubb/client.ts +++ b/examples/fetch/src/gen/.kubb/client.ts @@ -82,6 +82,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/fetch/src/gen/clients/pet/addPet.ts b/examples/fetch/src/gen/clients/pet/addPet.ts index 952e15db2..3628776a0 100644 --- a/examples/fetch/src/gen/clients/pet/addPet.ts +++ b/examples/fetch/src/gen/clients/pet/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../../models/pet/AddPet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Add a new pet to the store @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/fetch/src/gen/clients/pet/deletePet.ts b/examples/fetch/src/gen/clients/pet/deletePet.ts index 24725dc26..8fe616c13 100644 --- a/examples/fetch/src/gen/clients/pet/deletePet.ts +++ b/examples/fetch/src/gen/clients/pet/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../../models/pet/DeletePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description delete a pet @@ -14,10 +14,10 @@ import { client } from '../../.kubb/client' */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/fetch/src/gen/clients/pet/findPetsByStatus.ts b/examples/fetch/src/gen/clients/pet/findPetsByStatus.ts index 306835cef..78c47179c 100644 --- a/examples/fetch/src/gen/clients/pet/findPetsByStatus.ts +++ b/examples/fetch/src/gen/clients/pet/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../../models/pet/FindPetsByStatus' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings @@ -14,14 +14,16 @@ import { client } from '../../.kubb/client' */ export function findPetsByStatus( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByStatus', - security: [{ type: 'oauth2' }], - styles: { query: { status: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/findByStatus', + security: [{ type: 'oauth2' }], + styles: { query: { status: { explode: true } } }, + ...config, + }) as Promise>, + ) } diff --git a/examples/fetch/src/gen/clients/pet/findPetsByTags.ts b/examples/fetch/src/gen/clients/pet/findPetsByTags.ts index b7227971b..e4b9b5f55 100644 --- a/examples/fetch/src/gen/clients/pet/findPetsByTags.ts +++ b/examples/fetch/src/gen/clients/pet/findPetsByTags.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from '../../models/pet/FindPetsByTags' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -14,14 +14,12 @@ import { client } from '../../.kubb/client' */ export function findPetsByTags( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByTags', - security: [{ type: 'oauth2' }], - styles: { query: { tags: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], styles: { query: { tags: { explode: true } } }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/fetch/src/gen/clients/pet/getPetById.ts b/examples/fetch/src/gen/clients/pet/getPetById.ts index 771e59ee1..81e309e82 100644 --- a/examples/fetch/src/gen/clients/pet/getPetById.ts +++ b/examples/fetch/src/gen/clients/pet/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../../models/pet/GetPetById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a single pet @@ -14,13 +14,12 @@ import { client } from '../../.kubb/client' */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/fetch/src/gen/clients/pet/updatePet.ts b/examples/fetch/src/gen/clients/pet/updatePet.ts index 7a287a9fe..f662fd79f 100644 --- a/examples/fetch/src/gen/clients/pet/updatePet.ts +++ b/examples/fetch/src/gen/clients/pet/updatePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../../models/pet/UpdatePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Update an existing pet by Id @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function updatePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/fetch/src/gen/clients/pet/updatePetWithForm.ts b/examples/fetch/src/gen/clients/pet/updatePetWithForm.ts index f36371438..1db98bc49 100644 --- a/examples/fetch/src/gen/clients/pet/updatePetWithForm.ts +++ b/examples/fetch/src/gen/clients/pet/updatePetWithForm.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../../models/pet/UpdatePetWithForm' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Updates a pet in the store with form data @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function updatePetWithForm( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/fetch/src/gen/clients/pet/uploadFile.ts b/examples/fetch/src/gen/clients/pet/uploadFile.ts index 65e79b47b..92ce7c699 100644 --- a/examples/fetch/src/gen/clients/pet/uploadFile.ts +++ b/examples/fetch/src/gen/clients/pet/uploadFile.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../../models/pet/UploadFile' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary uploads an image @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function uploadFile( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/fetch/src/gen/clients/store/deleteOrder.ts b/examples/fetch/src/gen/clients/store/deleteOrder.ts index 74eec3514..689cbaa9a 100644 --- a/examples/fetch/src/gen/clients/store/deleteOrder.ts +++ b/examples/fetch/src/gen/clients/store/deleteOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteOrderOptions, DeleteOrderResponses } from '../../models/store/DeleteOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/store/getInventory.ts b/examples/fetch/src/gen/clients/store/getInventory.ts index f011e8dde..d44938f8e 100644 --- a/examples/fetch/src/gen/clients/store/getInventory.ts +++ b/examples/fetch/src/gen/clients/store/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../../models/store/GetInventory' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a map of status codes to quantities @@ -14,10 +14,12 @@ import { client } from '../../.kubb/client' */ export function getInventory( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/fetch/src/gen/clients/store/getOrderById.ts b/examples/fetch/src/gen/clients/store/getOrderById.ts index 91aa5bd78..a3ce96a72 100644 --- a/examples/fetch/src/gen/clients/store/getOrderById.ts +++ b/examples/fetch/src/gen/clients/store/getOrderById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetOrderByIdOptions, GetOrderByIdResponses } from '../../models/store/GetOrderById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function getOrderById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/store/placeOrder.ts b/examples/fetch/src/gen/clients/store/placeOrder.ts index 8c1d56394..3a3da9192 100644 --- a/examples/fetch/src/gen/clients/store/placeOrder.ts +++ b/examples/fetch/src/gen/clients/store/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../../models/store/PlaceOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/store/placeOrderPatch.ts b/examples/fetch/src/gen/clients/store/placeOrderPatch.ts index 0772af4f7..692337b25 100644 --- a/examples/fetch/src/gen/clients/store/placeOrderPatch.ts +++ b/examples/fetch/src/gen/clients/store/placeOrderPatch.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderPatchOptions, PlaceOrderPatchResponses } from '../../models/store/PlaceOrderPatch' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store with patch @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrderPatch( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PATCH', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'PATCH', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/user/createUser.ts b/examples/fetch/src/gen/clients/user/createUser.ts index af5bbc3e7..d9c8c13bc 100644 --- a/examples/fetch/src/gen/clients/user/createUser.ts +++ b/examples/fetch/src/gen/clients/user/createUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUserOptions, CreateUserResponses } from '../../models/user/CreateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function createUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/user', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/user/createUsersWithListInput.ts b/examples/fetch/src/gen/clients/user/createUsersWithListInput.ts index b69d5d908..1e6a9e2ac 100644 --- a/examples/fetch/src/gen/clients/user/createUsersWithListInput.ts +++ b/examples/fetch/src/gen/clients/user/createUsersWithListInput.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUsersWithListInputOptions, CreateUsersWithListInputResponses } from '../../models/user/CreateUsersWithListInput' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Creates list of users with given input array @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function createUsersWithListInput( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise>, + ) } diff --git a/examples/fetch/src/gen/clients/user/deleteUser.ts b/examples/fetch/src/gen/clients/user/deleteUser.ts index dff00a13e..8dda91163 100644 --- a/examples/fetch/src/gen/clients/user/deleteUser.ts +++ b/examples/fetch/src/gen/clients/user/deleteUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteUserOptions, DeleteUserResponses } from '../../models/user/DeleteUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/user/getUserByName.ts b/examples/fetch/src/gen/clients/user/getUserByName.ts index 4db3b9d4d..2e0afe704 100644 --- a/examples/fetch/src/gen/clients/user/getUserByName.ts +++ b/examples/fetch/src/gen/clients/user/getUserByName.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetUserByNameOptions, GetUserByNameResponses } from '../../models/user/GetUserByName' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Get user by user name @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function getUserByName( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/user/loginUser.ts b/examples/fetch/src/gen/clients/user/loginUser.ts index b619b4b9b..4a46c2208 100644 --- a/examples/fetch/src/gen/clients/user/loginUser.ts +++ b/examples/fetch/src/gen/clients/user/loginUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LoginUserOptions, LoginUserResponses } from '../../models/user/LoginUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs user into the system @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function loginUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/login', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/login', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/user/logoutUser.ts b/examples/fetch/src/gen/clients/user/logoutUser.ts index e41276de9..a5c939fbb 100644 --- a/examples/fetch/src/gen/clients/user/logoutUser.ts +++ b/examples/fetch/src/gen/clients/user/logoutUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LogoutUserOptions, LogoutUserResponses } from '../../models/user/LogoutUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs out current logged in user session @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function logoutUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/logout', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/logout', ...config }) as Promise>) } diff --git a/examples/fetch/src/gen/clients/user/updateUser.ts b/examples/fetch/src/gen/clients/user/updateUser.ts index ce0faef1f..b6c6e7de1 100644 --- a/examples/fetch/src/gen/clients/user/updateUser.ts +++ b/examples/fetch/src/gen/clients/user/updateUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdateUserOptions, UpdateUserResponses } from '../../models/user/UpdateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function updateUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/mcp/src/gen/.kubb/client.ts b/examples/mcp/src/gen/.kubb/client.ts index ff65e0b9d..fba2f3f25 100644 --- a/examples/mcp/src/gen/.kubb/client.ts +++ b/examples/mcp/src/gen/.kubb/client.ts @@ -84,6 +84,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/mcp/src/gen/clients/addFiles.ts b/examples/mcp/src/gen/clients/addFiles.ts index 9574992c0..011ed283c 100644 --- a/examples/mcp/src/gen/clients/addFiles.ts +++ b/examples/mcp/src/gen/clients/addFiles.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddFilesOptions, AddFilesResponses } from '../models/ts/AddFiles' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new file in the store @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function addFiles( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/files', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pet/files', ...config }) as Promise>) } diff --git a/examples/mcp/src/gen/clients/addPet.ts b/examples/mcp/src/gen/clients/addPet.ts index 844da0911..9a0496cf5 100644 --- a/examples/mcp/src/gen/clients/addPet.ts +++ b/examples/mcp/src/gen/clients/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../models/ts/AddPet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store @@ -14,8 +14,10 @@ import { client } from '../.kubb/client' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/mcp/src/gen/clients/createPets.ts b/examples/mcp/src/gen/clients/createPets.ts index b42432659..40884cc56 100644 --- a/examples/mcp/src/gen/clients/createPets.ts +++ b/examples/mcp/src/gen/clients/createPets.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { CreatePetsOptions, CreatePetsResponses } from '../models/ts/CreatePets' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary Create a pet @@ -13,8 +13,8 @@ import { client } from '../.kubb/client' */ export function createPets( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pets/{uuid}', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/pets/{uuid}', ...config }) as Promise>) } diff --git a/examples/mcp/src/gen/clients/deleteOrder.ts b/examples/mcp/src/gen/clients/deleteOrder.ts index 2abd6ff35..db9b7c999 100644 --- a/examples/mcp/src/gen/clients/deleteOrder.ts +++ b/examples/mcp/src/gen/clients/deleteOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeleteOrderOptions, DeleteOrderResponses } from '../models/ts/DeleteOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function deleteOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/mcp/src/gen/clients/deletePet.ts b/examples/mcp/src/gen/clients/deletePet.ts index 08c7066d6..c16f63230 100644 --- a/examples/mcp/src/gen/clients/deletePet.ts +++ b/examples/mcp/src/gen/clients/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../models/ts/DeletePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet @@ -14,10 +14,10 @@ import { client } from '../.kubb/client' */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/mcp/src/gen/clients/findPetsByStatus.ts b/examples/mcp/src/gen/clients/findPetsByStatus.ts index d52b61fc5..03a2e6cb7 100644 --- a/examples/mcp/src/gen/clients/findPetsByStatus.ts +++ b/examples/mcp/src/gen/clients/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../models/ts/FindPetsByStatus' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings @@ -14,10 +14,12 @@ import { client } from '../.kubb/client' */ export function findPetsByStatus( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus/{step_id}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/pet/findByStatus/{step_id}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/mcp/src/gen/clients/findPetsByTags.ts b/examples/mcp/src/gen/clients/findPetsByTags.ts index 3c9dce11b..ff34b628b 100644 --- a/examples/mcp/src/gen/clients/findPetsByTags.ts +++ b/examples/mcp/src/gen/clients/findPetsByTags.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from '../models/ts/FindPetsByTags' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -14,14 +14,12 @@ import { client } from '../.kubb/client' */ export function findPetsByTags( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByTags', - security: [{ type: 'oauth2' }], - styles: { query: { tags: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], styles: { query: { tags: { explode: true } } }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/mcp/src/gen/clients/getInventory.ts b/examples/mcp/src/gen/clients/getInventory.ts index 59db43bc6..15b384ed9 100644 --- a/examples/mcp/src/gen/clients/getInventory.ts +++ b/examples/mcp/src/gen/clients/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../models/ts/GetInventory' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities @@ -14,10 +14,12 @@ import { client } from '../.kubb/client' */ export function getInventory( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/mcp/src/gen/clients/getOrderById.ts b/examples/mcp/src/gen/clients/getOrderById.ts index 514a59bed..0a9dac45a 100644 --- a/examples/mcp/src/gen/clients/getOrderById.ts +++ b/examples/mcp/src/gen/clients/getOrderById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetOrderByIdOptions, GetOrderByIdResponses } from '../models/ts/GetOrderById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function getOrderById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/mcp/src/gen/clients/getPetById.ts b/examples/mcp/src/gen/clients/getPetById.ts index d05d6b0c7..18e629de1 100644 --- a/examples/mcp/src/gen/clients/getPetById.ts +++ b/examples/mcp/src/gen/clients/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../models/ts/GetPetById' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet @@ -14,13 +14,12 @@ import { client } from '../.kubb/client' */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/mcp/src/gen/clients/placeOrder.ts b/examples/mcp/src/gen/clients/placeOrder.ts index 3e40bda53..7879b1b42 100644 --- a/examples/mcp/src/gen/clients/placeOrder.ts +++ b/examples/mcp/src/gen/clients/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../models/ts/PlaceOrder' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function placeOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/mcp/src/gen/clients/placeOrderPatch.ts b/examples/mcp/src/gen/clients/placeOrderPatch.ts index 8a4df3573..16b68f959 100644 --- a/examples/mcp/src/gen/clients/placeOrderPatch.ts +++ b/examples/mcp/src/gen/clients/placeOrderPatch.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderPatchOptions, PlaceOrderPatchResponses } from '../models/ts/PlaceOrderPatch' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store with patch @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function placeOrderPatch( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PATCH', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'PATCH', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/mcp/src/gen/clients/updatePet.ts b/examples/mcp/src/gen/clients/updatePet.ts index 6020c27bd..9a347a403 100644 --- a/examples/mcp/src/gen/clients/updatePet.ts +++ b/examples/mcp/src/gen/clients/updatePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../models/ts/UpdatePet' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Update an existing pet by Id @@ -14,8 +14,10 @@ import { client } from '../.kubb/client' */ export function updatePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/mcp/src/gen/clients/updatePetWithForm.ts b/examples/mcp/src/gen/clients/updatePetWithForm.ts index 5e20e3cb6..cde83a933 100644 --- a/examples/mcp/src/gen/clients/updatePetWithForm.ts +++ b/examples/mcp/src/gen/clients/updatePetWithForm.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../models/ts/UpdatePetWithForm' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary Updates a pet in the store with form data @@ -13,10 +13,12 @@ import { client } from '../.kubb/client' */ export function updatePetWithForm( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/react-query/src/gen/.kubb/client.ts b/examples/react-query/src/gen/.kubb/client.ts index f80182aca..ea6223eff 100644 --- a/examples/react-query/src/gen/.kubb/client.ts +++ b/examples/react-query/src/gen/.kubb/client.ts @@ -82,6 +82,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/react-query/src/gen/clients/pet/addPet.ts b/examples/react-query/src/gen/clients/pet/addPet.ts index 952e15db2..3628776a0 100644 --- a/examples/react-query/src/gen/clients/pet/addPet.ts +++ b/examples/react-query/src/gen/clients/pet/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../../models/pet/AddPet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Add a new pet to the store @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/react-query/src/gen/clients/pet/deletePet.ts b/examples/react-query/src/gen/clients/pet/deletePet.ts index 24725dc26..8fe616c13 100644 --- a/examples/react-query/src/gen/clients/pet/deletePet.ts +++ b/examples/react-query/src/gen/clients/pet/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../../models/pet/DeletePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description delete a pet @@ -14,10 +14,10 @@ import { client } from '../../.kubb/client' */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/react-query/src/gen/clients/pet/findPetsByStatus.ts b/examples/react-query/src/gen/clients/pet/findPetsByStatus.ts index 306835cef..78c47179c 100644 --- a/examples/react-query/src/gen/clients/pet/findPetsByStatus.ts +++ b/examples/react-query/src/gen/clients/pet/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../../models/pet/FindPetsByStatus' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings @@ -14,14 +14,16 @@ import { client } from '../../.kubb/client' */ export function findPetsByStatus( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByStatus', - security: [{ type: 'oauth2' }], - styles: { query: { status: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/findByStatus', + security: [{ type: 'oauth2' }], + styles: { query: { status: { explode: true } } }, + ...config, + }) as Promise>, + ) } diff --git a/examples/react-query/src/gen/clients/pet/findPetsByTags.ts b/examples/react-query/src/gen/clients/pet/findPetsByTags.ts index b7227971b..e4b9b5f55 100644 --- a/examples/react-query/src/gen/clients/pet/findPetsByTags.ts +++ b/examples/react-query/src/gen/clients/pet/findPetsByTags.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from '../../models/pet/FindPetsByTags' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -14,14 +14,12 @@ import { client } from '../../.kubb/client' */ export function findPetsByTags( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByTags', - security: [{ type: 'oauth2' }], - styles: { query: { tags: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], styles: { query: { tags: { explode: true } } }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/react-query/src/gen/clients/pet/getPetById.ts b/examples/react-query/src/gen/clients/pet/getPetById.ts index 771e59ee1..81e309e82 100644 --- a/examples/react-query/src/gen/clients/pet/getPetById.ts +++ b/examples/react-query/src/gen/clients/pet/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../../models/pet/GetPetById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a single pet @@ -14,13 +14,12 @@ import { client } from '../../.kubb/client' */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/react-query/src/gen/clients/pet/updatePet.ts b/examples/react-query/src/gen/clients/pet/updatePet.ts index 7a287a9fe..f662fd79f 100644 --- a/examples/react-query/src/gen/clients/pet/updatePet.ts +++ b/examples/react-query/src/gen/clients/pet/updatePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../../models/pet/UpdatePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Update an existing pet by Id @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function updatePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/react-query/src/gen/clients/pet/updatePetWithForm.ts b/examples/react-query/src/gen/clients/pet/updatePetWithForm.ts index f36371438..1db98bc49 100644 --- a/examples/react-query/src/gen/clients/pet/updatePetWithForm.ts +++ b/examples/react-query/src/gen/clients/pet/updatePetWithForm.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../../models/pet/UpdatePetWithForm' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Updates a pet in the store with form data @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function updatePetWithForm( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/react-query/src/gen/clients/pet/uploadFile.ts b/examples/react-query/src/gen/clients/pet/uploadFile.ts index 65e79b47b..92ce7c699 100644 --- a/examples/react-query/src/gen/clients/pet/uploadFile.ts +++ b/examples/react-query/src/gen/clients/pet/uploadFile.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../../models/pet/UploadFile' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary uploads an image @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function uploadFile( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/react-query/src/gen/clients/store/deleteOrder.ts b/examples/react-query/src/gen/clients/store/deleteOrder.ts index 74eec3514..689cbaa9a 100644 --- a/examples/react-query/src/gen/clients/store/deleteOrder.ts +++ b/examples/react-query/src/gen/clients/store/deleteOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteOrderOptions, DeleteOrderResponses } from '../../models/store/DeleteOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/store/getInventory.ts b/examples/react-query/src/gen/clients/store/getInventory.ts index f011e8dde..d44938f8e 100644 --- a/examples/react-query/src/gen/clients/store/getInventory.ts +++ b/examples/react-query/src/gen/clients/store/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../../models/store/GetInventory' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a map of status codes to quantities @@ -14,10 +14,12 @@ import { client } from '../../.kubb/client' */ export function getInventory( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/react-query/src/gen/clients/store/getOrderById.ts b/examples/react-query/src/gen/clients/store/getOrderById.ts index 91aa5bd78..a3ce96a72 100644 --- a/examples/react-query/src/gen/clients/store/getOrderById.ts +++ b/examples/react-query/src/gen/clients/store/getOrderById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetOrderByIdOptions, GetOrderByIdResponses } from '../../models/store/GetOrderById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function getOrderById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/store/placeOrder.ts b/examples/react-query/src/gen/clients/store/placeOrder.ts index 8c1d56394..3a3da9192 100644 --- a/examples/react-query/src/gen/clients/store/placeOrder.ts +++ b/examples/react-query/src/gen/clients/store/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../../models/store/PlaceOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/store/placeOrderPatch.ts b/examples/react-query/src/gen/clients/store/placeOrderPatch.ts index 0772af4f7..692337b25 100644 --- a/examples/react-query/src/gen/clients/store/placeOrderPatch.ts +++ b/examples/react-query/src/gen/clients/store/placeOrderPatch.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderPatchOptions, PlaceOrderPatchResponses } from '../../models/store/PlaceOrderPatch' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store with patch @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrderPatch( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PATCH', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'PATCH', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/user/createUser.ts b/examples/react-query/src/gen/clients/user/createUser.ts index af5bbc3e7..d9c8c13bc 100644 --- a/examples/react-query/src/gen/clients/user/createUser.ts +++ b/examples/react-query/src/gen/clients/user/createUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUserOptions, CreateUserResponses } from '../../models/user/CreateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function createUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/user', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/user/createUsersWithListInput.ts b/examples/react-query/src/gen/clients/user/createUsersWithListInput.ts index b69d5d908..1e6a9e2ac 100644 --- a/examples/react-query/src/gen/clients/user/createUsersWithListInput.ts +++ b/examples/react-query/src/gen/clients/user/createUsersWithListInput.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUsersWithListInputOptions, CreateUsersWithListInputResponses } from '../../models/user/CreateUsersWithListInput' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Creates list of users with given input array @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function createUsersWithListInput( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise>, + ) } diff --git a/examples/react-query/src/gen/clients/user/deleteUser.ts b/examples/react-query/src/gen/clients/user/deleteUser.ts index dff00a13e..8dda91163 100644 --- a/examples/react-query/src/gen/clients/user/deleteUser.ts +++ b/examples/react-query/src/gen/clients/user/deleteUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteUserOptions, DeleteUserResponses } from '../../models/user/DeleteUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/user/getUserByName.ts b/examples/react-query/src/gen/clients/user/getUserByName.ts index 4db3b9d4d..2e0afe704 100644 --- a/examples/react-query/src/gen/clients/user/getUserByName.ts +++ b/examples/react-query/src/gen/clients/user/getUserByName.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetUserByNameOptions, GetUserByNameResponses } from '../../models/user/GetUserByName' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Get user by user name @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function getUserByName( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/user/loginUser.ts b/examples/react-query/src/gen/clients/user/loginUser.ts index b619b4b9b..4a46c2208 100644 --- a/examples/react-query/src/gen/clients/user/loginUser.ts +++ b/examples/react-query/src/gen/clients/user/loginUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LoginUserOptions, LoginUserResponses } from '../../models/user/LoginUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs user into the system @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function loginUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/login', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/login', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/user/logoutUser.ts b/examples/react-query/src/gen/clients/user/logoutUser.ts index e41276de9..a5c939fbb 100644 --- a/examples/react-query/src/gen/clients/user/logoutUser.ts +++ b/examples/react-query/src/gen/clients/user/logoutUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LogoutUserOptions, LogoutUserResponses } from '../../models/user/LogoutUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs out current logged in user session @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function logoutUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/logout', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/logout', ...config }) as Promise>) } diff --git a/examples/react-query/src/gen/clients/user/updateUser.ts b/examples/react-query/src/gen/clients/user/updateUser.ts index ce0faef1f..b6c6e7de1 100644 --- a/examples/react-query/src/gen/clients/user/updateUser.ts +++ b/examples/react-query/src/gen/clients/user/updateUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdateUserOptions, UpdateUserResponses } from '../../models/user/UpdateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function updateUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/sdk/src/gen/.kubb/client.ts b/examples/sdk/src/gen/.kubb/client.ts index f80182aca..ea6223eff 100644 --- a/examples/sdk/src/gen/.kubb/client.ts +++ b/examples/sdk/src/gen/.kubb/client.ts @@ -82,6 +82,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/sdk/src/gen/sdk/pet/pet.ts b/examples/sdk/src/gen/sdk/pet/pet.ts index e3ef0e684..b41c07e8a 100644 --- a/examples/sdk/src/gen/sdk/pet/pet.ts +++ b/examples/sdk/src/gen/sdk/pet/pet.ts @@ -3,7 +3,7 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../../models/pet/AddPet' import type { DeletePetOptions, DeletePetResponses } from '../../models/pet/DeletePet' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../../models/pet/FindPetsByStatus' @@ -12,7 +12,7 @@ import type { GetPetByIdOptions, GetPetByIdResponses } from '../../models/pet/Ge import type { UpdatePetOptions, UpdatePetResponses } from '../../models/pet/UpdatePet' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../../models/pet/UpdatePetWithForm' import type { UploadFileOptions, UploadFileResponses } from '../../models/pet/UploadFile' -import { createClient } from '../../.kubb/client' +import { createClient, withUnwrap } from '../../.kubb/client' export class pet { private readonly client: ClientInstance @@ -28,10 +28,12 @@ export class pet { */ public updatePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } /** @@ -39,10 +41,12 @@ export class pet { * @summary Add a new pet to the store * {@link /pet} */ - public addPet(options: Options): Promise> { + public addPet(options: Options): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } /** @@ -52,12 +56,14 @@ export class pet { */ public findPetsByStatus( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/pet/findByStatus', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } /** @@ -67,12 +73,14 @@ export class pet { */ public findPetsByTags( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } /** @@ -82,15 +90,14 @@ export class pet { */ public getPetById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } /** @@ -99,12 +106,14 @@ export class pet { */ public updatePetWithForm( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } /** @@ -114,12 +123,12 @@ export class pet { */ public deletePet( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } /** @@ -128,11 +137,13 @@ export class pet { */ public uploadFile( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } } diff --git a/examples/sdk/src/gen/sdk/store/store.ts b/examples/sdk/src/gen/sdk/store/store.ts index 6686f3a6d..15fd3ecda 100644 --- a/examples/sdk/src/gen/sdk/store/store.ts +++ b/examples/sdk/src/gen/sdk/store/store.ts @@ -3,13 +3,13 @@ * Do not edit manually. */ -import type { ClientConfig, ClientInstance, Options, RequestResult } from '../../.kubb/client' +import type { ClientConfig, ClientInstance, Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteOrderOptions, DeleteOrderResponses } from '../../models/store/DeleteOrder' import type { GetInventoryOptions, GetInventoryResponses } from '../../models/store/GetInventory' import type { GetOrderByIdOptions, GetOrderByIdResponses } from '../../models/store/GetOrderById' import type { PlaceOrderOptions, PlaceOrderResponses } from '../../models/store/PlaceOrder' import type { PlaceOrderPatchOptions, PlaceOrderPatchResponses } from '../../models/store/PlaceOrderPatch' -import { createClient } from '../../.kubb/client' +import { createClient, withUnwrap } from '../../.kubb/client' export class store { private readonly client: ClientInstance @@ -25,12 +25,14 @@ export class store { */ public getInventory( options: Options = {}, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } /** @@ -40,10 +42,10 @@ export class store { */ public placeOrder( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } /** @@ -53,10 +55,10 @@ export class store { */ public placeOrderPatch( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'PATCH', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'PATCH', url: '/store/order', ...config }) as Promise>) } /** @@ -66,10 +68,10 @@ export class store { */ public getOrderById( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise>) } /** @@ -79,9 +81,9 @@ export class store { */ public deleteOrder( options: Options, - ): Promise> { + ): Unwrappable> { const { client: request = this.client, ...config } = options - return request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise>) } } diff --git a/examples/simple-single/src/gen/.kubb/client.ts b/examples/simple-single/src/gen/.kubb/client.ts index f80182aca..ea6223eff 100644 --- a/examples/simple-single/src/gen/.kubb/client.ts +++ b/examples/simple-single/src/gen/.kubb/client.ts @@ -82,6 +82,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/simple-single/src/gen/clients/addPet.ts b/examples/simple-single/src/gen/clients/addPet.ts index c94fa5e36..5c86cf2c2 100644 --- a/examples/simple-single/src/gen/clients/addPet.ts +++ b/examples/simple-single/src/gen/clients/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Add a new pet to the store @@ -14,8 +14,10 @@ import { client } from '../.kubb/client' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/simple-single/src/gen/clients/deleteOrder.ts b/examples/simple-single/src/gen/clients/deleteOrder.ts index 28e685afa..18239d317 100644 --- a/examples/simple-single/src/gen/clients/deleteOrder.ts +++ b/examples/simple-single/src/gen/clients/deleteOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeleteOrderOptions, DeleteOrderResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function deleteOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/simple-single/src/gen/clients/deletePet.ts b/examples/simple-single/src/gen/clients/deletePet.ts index 673bfb395..6ffc70d69 100644 --- a/examples/simple-single/src/gen/clients/deletePet.ts +++ b/examples/simple-single/src/gen/clients/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description delete a pet @@ -14,10 +14,10 @@ import { client } from '../.kubb/client' */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/simple-single/src/gen/clients/findPetsByStatus.ts b/examples/simple-single/src/gen/clients/findPetsByStatus.ts index bcd9a9139..2120d9126 100644 --- a/examples/simple-single/src/gen/clients/findPetsByStatus.ts +++ b/examples/simple-single/src/gen/clients/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings @@ -14,14 +14,16 @@ import { client } from '../.kubb/client' */ export function findPetsByStatus( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByStatus', - security: [{ type: 'oauth2' }], - styles: { query: { status: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/findByStatus', + security: [{ type: 'oauth2' }], + styles: { query: { status: { explode: true } } }, + ...config, + }) as Promise>, + ) } diff --git a/examples/simple-single/src/gen/clients/findPetsByTags.ts b/examples/simple-single/src/gen/clients/findPetsByTags.ts index 748391fb9..55a0ea5fd 100644 --- a/examples/simple-single/src/gen/clients/findPetsByTags.ts +++ b/examples/simple-single/src/gen/clients/findPetsByTags.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -14,14 +14,12 @@ import { client } from '../.kubb/client' */ export function findPetsByTags( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByTags', - security: [{ type: 'oauth2' }], - styles: { query: { tags: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], styles: { query: { tags: { explode: true } } }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/simple-single/src/gen/clients/getInventory.ts b/examples/simple-single/src/gen/clients/getInventory.ts index 5b3ad5705..47d7d4048 100644 --- a/examples/simple-single/src/gen/clients/getInventory.ts +++ b/examples/simple-single/src/gen/clients/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a map of status codes to quantities @@ -14,10 +14,12 @@ import { client } from '../.kubb/client' */ export function getInventory( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/simple-single/src/gen/clients/getOrderById.ts b/examples/simple-single/src/gen/clients/getOrderById.ts index fd51b011e..b9e498ecf 100644 --- a/examples/simple-single/src/gen/clients/getOrderById.ts +++ b/examples/simple-single/src/gen/clients/getOrderById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetOrderByIdOptions, GetOrderByIdResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function getOrderById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/simple-single/src/gen/clients/getPetById.ts b/examples/simple-single/src/gen/clients/getPetById.ts index cec7858f5..0c8ae4d07 100644 --- a/examples/simple-single/src/gen/clients/getPetById.ts +++ b/examples/simple-single/src/gen/clients/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Returns a single pet @@ -14,13 +14,12 @@ import { client } from '../.kubb/client' */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/simple-single/src/gen/clients/placeOrder.ts b/examples/simple-single/src/gen/clients/placeOrder.ts index 2ee6d5818..24add1fff 100644 --- a/examples/simple-single/src/gen/clients/placeOrder.ts +++ b/examples/simple-single/src/gen/clients/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function placeOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/simple-single/src/gen/clients/placeOrderPatch.ts b/examples/simple-single/src/gen/clients/placeOrderPatch.ts index c678c1cd4..9c6da9f33 100644 --- a/examples/simple-single/src/gen/clients/placeOrderPatch.ts +++ b/examples/simple-single/src/gen/clients/placeOrderPatch.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { PlaceOrderPatchOptions, PlaceOrderPatchResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Place a new order in the store with patch @@ -14,8 +14,8 @@ import { client } from '../.kubb/client' */ export function placeOrderPatch( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PATCH', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'PATCH', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/simple-single/src/gen/clients/updatePet.ts b/examples/simple-single/src/gen/clients/updatePet.ts index dbd5b3731..e5f8638ac 100644 --- a/examples/simple-single/src/gen/clients/updatePet.ts +++ b/examples/simple-single/src/gen/clients/updatePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @description Update an existing pet by Id @@ -14,8 +14,10 @@ import { client } from '../.kubb/client' */ export function updatePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/simple-single/src/gen/clients/updatePetWithForm.ts b/examples/simple-single/src/gen/clients/updatePetWithForm.ts index 07af7e471..a98d15f06 100644 --- a/examples/simple-single/src/gen/clients/updatePetWithForm.ts +++ b/examples/simple-single/src/gen/clients/updatePetWithForm.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary Updates a pet in the store with form data @@ -13,10 +13,12 @@ import { client } from '../.kubb/client' */ export function updatePetWithForm( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/simple-single/src/gen/clients/uploadFile.ts b/examples/simple-single/src/gen/clients/uploadFile.ts index 31f23e9a5..d482003f9 100644 --- a/examples/simple-single/src/gen/clients/uploadFile.ts +++ b/examples/simple-single/src/gen/clients/uploadFile.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../models' -import { client } from '../.kubb/client' +import { client, withUnwrap } from '../.kubb/client' /** * @summary uploads an image @@ -13,14 +13,16 @@ import { client } from '../.kubb/client' */ export function uploadFile( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'POST', - url: '/pet/{petId}/uploadImage', - security: [{ type: 'oauth2' }], - contentType: { request: 'application/octet-stream' }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'POST', + url: '/pet/{petId}/uploadImage', + security: [{ type: 'oauth2' }], + contentType: { request: 'application/octet-stream' }, + ...config, + }) as Promise>, + ) } diff --git a/examples/swr/src/gen/.kubb/client.ts b/examples/swr/src/gen/.kubb/client.ts index f80182aca..ea6223eff 100644 --- a/examples/swr/src/gen/.kubb/client.ts +++ b/examples/swr/src/gen/.kubb/client.ts @@ -82,6 +82,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/swr/src/gen/clients/pet/addPet.ts b/examples/swr/src/gen/clients/pet/addPet.ts index 952e15db2..3628776a0 100644 --- a/examples/swr/src/gen/clients/pet/addPet.ts +++ b/examples/swr/src/gen/clients/pet/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../../models/pet/AddPet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Add a new pet to the store @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/swr/src/gen/clients/pet/deletePet.ts b/examples/swr/src/gen/clients/pet/deletePet.ts index 24725dc26..8fe616c13 100644 --- a/examples/swr/src/gen/clients/pet/deletePet.ts +++ b/examples/swr/src/gen/clients/pet/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../../models/pet/DeletePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description delete a pet @@ -14,10 +14,10 @@ import { client } from '../../.kubb/client' */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/swr/src/gen/clients/pet/findPetsByStatus.ts b/examples/swr/src/gen/clients/pet/findPetsByStatus.ts index 306835cef..78c47179c 100644 --- a/examples/swr/src/gen/clients/pet/findPetsByStatus.ts +++ b/examples/swr/src/gen/clients/pet/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../../models/pet/FindPetsByStatus' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings @@ -14,14 +14,16 @@ import { client } from '../../.kubb/client' */ export function findPetsByStatus( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByStatus', - security: [{ type: 'oauth2' }], - styles: { query: { status: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/findByStatus', + security: [{ type: 'oauth2' }], + styles: { query: { status: { explode: true } } }, + ...config, + }) as Promise>, + ) } diff --git a/examples/swr/src/gen/clients/pet/findPetsByTags.ts b/examples/swr/src/gen/clients/pet/findPetsByTags.ts index b7227971b..e4b9b5f55 100644 --- a/examples/swr/src/gen/clients/pet/findPetsByTags.ts +++ b/examples/swr/src/gen/clients/pet/findPetsByTags.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from '../../models/pet/FindPetsByTags' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -14,14 +14,12 @@ import { client } from '../../.kubb/client' */ export function findPetsByTags( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByTags', - security: [{ type: 'oauth2' }], - styles: { query: { tags: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], styles: { query: { tags: { explode: true } } }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/swr/src/gen/clients/pet/getPetById.ts b/examples/swr/src/gen/clients/pet/getPetById.ts index 771e59ee1..81e309e82 100644 --- a/examples/swr/src/gen/clients/pet/getPetById.ts +++ b/examples/swr/src/gen/clients/pet/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../../models/pet/GetPetById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a single pet @@ -14,13 +14,12 @@ import { client } from '../../.kubb/client' */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/swr/src/gen/clients/pet/updatePet.ts b/examples/swr/src/gen/clients/pet/updatePet.ts index 7a287a9fe..f662fd79f 100644 --- a/examples/swr/src/gen/clients/pet/updatePet.ts +++ b/examples/swr/src/gen/clients/pet/updatePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../../models/pet/UpdatePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Update an existing pet by Id @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function updatePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/swr/src/gen/clients/pet/updatePetWithForm.ts b/examples/swr/src/gen/clients/pet/updatePetWithForm.ts index f36371438..1db98bc49 100644 --- a/examples/swr/src/gen/clients/pet/updatePetWithForm.ts +++ b/examples/swr/src/gen/clients/pet/updatePetWithForm.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../../models/pet/UpdatePetWithForm' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Updates a pet in the store with form data @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function updatePetWithForm( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/swr/src/gen/clients/pet/uploadFile.ts b/examples/swr/src/gen/clients/pet/uploadFile.ts index 65e79b47b..92ce7c699 100644 --- a/examples/swr/src/gen/clients/pet/uploadFile.ts +++ b/examples/swr/src/gen/clients/pet/uploadFile.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../../models/pet/UploadFile' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary uploads an image @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function uploadFile( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/swr/src/gen/clients/store/deleteOrder.ts b/examples/swr/src/gen/clients/store/deleteOrder.ts index 74eec3514..689cbaa9a 100644 --- a/examples/swr/src/gen/clients/store/deleteOrder.ts +++ b/examples/swr/src/gen/clients/store/deleteOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteOrderOptions, DeleteOrderResponses } from '../../models/store/DeleteOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/store/getInventory.ts b/examples/swr/src/gen/clients/store/getInventory.ts index f011e8dde..d44938f8e 100644 --- a/examples/swr/src/gen/clients/store/getInventory.ts +++ b/examples/swr/src/gen/clients/store/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../../models/store/GetInventory' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a map of status codes to quantities @@ -14,10 +14,12 @@ import { client } from '../../.kubb/client' */ export function getInventory( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/swr/src/gen/clients/store/getOrderById.ts b/examples/swr/src/gen/clients/store/getOrderById.ts index 91aa5bd78..a3ce96a72 100644 --- a/examples/swr/src/gen/clients/store/getOrderById.ts +++ b/examples/swr/src/gen/clients/store/getOrderById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetOrderByIdOptions, GetOrderByIdResponses } from '../../models/store/GetOrderById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function getOrderById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/store/placeOrder.ts b/examples/swr/src/gen/clients/store/placeOrder.ts index 8c1d56394..3a3da9192 100644 --- a/examples/swr/src/gen/clients/store/placeOrder.ts +++ b/examples/swr/src/gen/clients/store/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../../models/store/PlaceOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/store/placeOrderPatch.ts b/examples/swr/src/gen/clients/store/placeOrderPatch.ts index 0772af4f7..692337b25 100644 --- a/examples/swr/src/gen/clients/store/placeOrderPatch.ts +++ b/examples/swr/src/gen/clients/store/placeOrderPatch.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderPatchOptions, PlaceOrderPatchResponses } from '../../models/store/PlaceOrderPatch' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store with patch @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrderPatch( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PATCH', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'PATCH', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/user/createUser.ts b/examples/swr/src/gen/clients/user/createUser.ts index af5bbc3e7..d9c8c13bc 100644 --- a/examples/swr/src/gen/clients/user/createUser.ts +++ b/examples/swr/src/gen/clients/user/createUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUserOptions, CreateUserResponses } from '../../models/user/CreateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function createUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/user', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/user/createUsersWithListInput.ts b/examples/swr/src/gen/clients/user/createUsersWithListInput.ts index b69d5d908..1e6a9e2ac 100644 --- a/examples/swr/src/gen/clients/user/createUsersWithListInput.ts +++ b/examples/swr/src/gen/clients/user/createUsersWithListInput.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUsersWithListInputOptions, CreateUsersWithListInputResponses } from '../../models/user/CreateUsersWithListInput' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Creates list of users with given input array @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function createUsersWithListInput( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise>, + ) } diff --git a/examples/swr/src/gen/clients/user/deleteUser.ts b/examples/swr/src/gen/clients/user/deleteUser.ts index dff00a13e..8dda91163 100644 --- a/examples/swr/src/gen/clients/user/deleteUser.ts +++ b/examples/swr/src/gen/clients/user/deleteUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteUserOptions, DeleteUserResponses } from '../../models/user/DeleteUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/user/getUserByName.ts b/examples/swr/src/gen/clients/user/getUserByName.ts index 4db3b9d4d..2e0afe704 100644 --- a/examples/swr/src/gen/clients/user/getUserByName.ts +++ b/examples/swr/src/gen/clients/user/getUserByName.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetUserByNameOptions, GetUserByNameResponses } from '../../models/user/GetUserByName' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Get user by user name @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function getUserByName( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/user/loginUser.ts b/examples/swr/src/gen/clients/user/loginUser.ts index b619b4b9b..4a46c2208 100644 --- a/examples/swr/src/gen/clients/user/loginUser.ts +++ b/examples/swr/src/gen/clients/user/loginUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LoginUserOptions, LoginUserResponses } from '../../models/user/LoginUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs user into the system @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function loginUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/login', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/login', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/user/logoutUser.ts b/examples/swr/src/gen/clients/user/logoutUser.ts index e41276de9..a5c939fbb 100644 --- a/examples/swr/src/gen/clients/user/logoutUser.ts +++ b/examples/swr/src/gen/clients/user/logoutUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LogoutUserOptions, LogoutUserResponses } from '../../models/user/LogoutUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs out current logged in user session @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function logoutUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/logout', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/logout', ...config }) as Promise>) } diff --git a/examples/swr/src/gen/clients/user/updateUser.ts b/examples/swr/src/gen/clients/user/updateUser.ts index ce0faef1f..b6c6e7de1 100644 --- a/examples/swr/src/gen/clients/user/updateUser.ts +++ b/examples/swr/src/gen/clients/user/updateUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdateUserOptions, UpdateUserResponses } from '../../models/user/UpdateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function updateUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/.kubb/client.ts b/examples/vue-query/src/gen/.kubb/client.ts index f80182aca..ea6223eff 100644 --- a/examples/vue-query/src/gen/.kubb/client.ts +++ b/examples/vue-query/src/gen/.kubb/client.ts @@ -82,6 +82,32 @@ export type RequestResult +/** + * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body. + */ +export type Unwrappable = Promise & { + unwrap: () => Promise['data']> +} + +/** + * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one. + * + * @example Full result + * `const { data, error } = await getPetById({ path: { petId: 1 } })` + * + * @example Success body only + * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()` + */ +export function withUnwrap(promise: Promise): Unwrappable { + const unwrappable = promise as Unwrappable + unwrappable.unwrap = () => + promise.then((result) => { + if (result.error !== undefined) throw result.error + return result.data as Extract['data'] + }) + return unwrappable +} + /** * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation. */ diff --git a/examples/vue-query/src/gen/clients/pet/addPet.ts b/examples/vue-query/src/gen/clients/pet/addPet.ts index 952e15db2..3628776a0 100644 --- a/examples/vue-query/src/gen/clients/pet/addPet.ts +++ b/examples/vue-query/src/gen/clients/pet/addPet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { AddPetOptions, AddPetResponses } from '../../models/pet/AddPet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Add a new pet to the store @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function addPet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/vue-query/src/gen/clients/pet/deletePet.ts b/examples/vue-query/src/gen/clients/pet/deletePet.ts index 24725dc26..8fe616c13 100644 --- a/examples/vue-query/src/gen/clients/pet/deletePet.ts +++ b/examples/vue-query/src/gen/clients/pet/deletePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeletePetOptions, DeletePetResponses } from '../../models/pet/DeletePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description delete a pet @@ -14,10 +14,10 @@ import { client } from '../../.kubb/client' */ export function deletePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'DELETE', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/vue-query/src/gen/clients/pet/findPetsByStatus.ts b/examples/vue-query/src/gen/clients/pet/findPetsByStatus.ts index 306835cef..78c47179c 100644 --- a/examples/vue-query/src/gen/clients/pet/findPetsByStatus.ts +++ b/examples/vue-query/src/gen/clients/pet/findPetsByStatus.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByStatusOptions, FindPetsByStatusResponses } from '../../models/pet/FindPetsByStatus' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple status values can be provided with comma separated strings @@ -14,14 +14,16 @@ import { client } from '../../.kubb/client' */ export function findPetsByStatus( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByStatus', - security: [{ type: 'oauth2' }], - styles: { query: { status: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ + method: 'GET', + url: '/pet/findByStatus', + security: [{ type: 'oauth2' }], + styles: { query: { status: { explode: true } } }, + ...config, + }) as Promise>, + ) } diff --git a/examples/vue-query/src/gen/clients/pet/findPetsByTags.ts b/examples/vue-query/src/gen/clients/pet/findPetsByTags.ts index b7227971b..e4b9b5f55 100644 --- a/examples/vue-query/src/gen/clients/pet/findPetsByTags.ts +++ b/examples/vue-query/src/gen/clients/pet/findPetsByTags.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { FindPetsByTagsOptions, FindPetsByTagsResponses } from '../../models/pet/FindPetsByTags' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -14,14 +14,12 @@ import { client } from '../../.kubb/client' */ export function findPetsByTags( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/findByTags', - security: [{ type: 'oauth2' }], - styles: { query: { tags: { explode: true } } }, - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/findByTags', security: [{ type: 'oauth2' }], styles: { query: { tags: { explode: true } } }, ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/vue-query/src/gen/clients/pet/getPetById.ts b/examples/vue-query/src/gen/clients/pet/getPetById.ts index 771e59ee1..81e309e82 100644 --- a/examples/vue-query/src/gen/clients/pet/getPetById.ts +++ b/examples/vue-query/src/gen/clients/pet/getPetById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetPetByIdOptions, GetPetByIdResponses } from '../../models/pet/GetPetById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a single pet @@ -14,13 +14,12 @@ import { client } from '../../.kubb/client' */ export function getPetById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ - method: 'GET', - url: '/pet/{petId}', - security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], - ...config, - }) as Promise> + return withUnwrap( + request({ method: 'GET', url: '/pet/{petId}', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }, { type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/vue-query/src/gen/clients/pet/updatePet.ts b/examples/vue-query/src/gen/clients/pet/updatePet.ts index 7a287a9fe..f662fd79f 100644 --- a/examples/vue-query/src/gen/clients/pet/updatePet.ts +++ b/examples/vue-query/src/gen/clients/pet/updatePet.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetOptions, UpdatePetResponses } from '../../models/pet/UpdatePet' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Update an existing pet by Id @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function updatePet( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise> + return withUnwrap( + request({ method: 'PUT', url: '/pet', security: [{ type: 'oauth2' }], ...config }) as Promise>, + ) } diff --git a/examples/vue-query/src/gen/clients/pet/updatePetWithForm.ts b/examples/vue-query/src/gen/clients/pet/updatePetWithForm.ts index f36371438..1db98bc49 100644 --- a/examples/vue-query/src/gen/clients/pet/updatePetWithForm.ts +++ b/examples/vue-query/src/gen/clients/pet/updatePetWithForm.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdatePetWithFormOptions, UpdatePetWithFormResponses } from '../../models/pet/UpdatePetWithForm' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Updates a pet in the store with form data @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function updatePetWithForm( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/vue-query/src/gen/clients/pet/uploadFile.ts b/examples/vue-query/src/gen/clients/pet/uploadFile.ts index 65e79b47b..92ce7c699 100644 --- a/examples/vue-query/src/gen/clients/pet/uploadFile.ts +++ b/examples/vue-query/src/gen/clients/pet/uploadFile.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UploadFileOptions, UploadFileResponses } from '../../models/pet/UploadFile' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary uploads an image @@ -13,10 +13,12 @@ import { client } from '../../.kubb/client' */ export function uploadFile( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'POST', url: '/pet/{petId}/uploadImage', security: [{ type: 'oauth2' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/vue-query/src/gen/clients/store/deleteOrder.ts b/examples/vue-query/src/gen/clients/store/deleteOrder.ts index 74eec3514..689cbaa9a 100644 --- a/examples/vue-query/src/gen/clients/store/deleteOrder.ts +++ b/examples/vue-query/src/gen/clients/store/deleteOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteOrderOptions, DeleteOrderResponses } from '../../models/store/DeleteOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/store/getInventory.ts b/examples/vue-query/src/gen/clients/store/getInventory.ts index f011e8dde..d44938f8e 100644 --- a/examples/vue-query/src/gen/clients/store/getInventory.ts +++ b/examples/vue-query/src/gen/clients/store/getInventory.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetInventoryOptions, GetInventoryResponses } from '../../models/store/GetInventory' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Returns a map of status codes to quantities @@ -14,10 +14,12 @@ import { client } from '../../.kubb/client' */ export function getInventory( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< - RequestResult - > + return withUnwrap( + request({ method: 'GET', url: '/store/inventory', security: [{ type: 'apiKey', name: 'api_key', in: 'header' }], ...config }) as Promise< + RequestResult + >, + ) } diff --git a/examples/vue-query/src/gen/clients/store/getOrderById.ts b/examples/vue-query/src/gen/clients/store/getOrderById.ts index 91aa5bd78..a3ce96a72 100644 --- a/examples/vue-query/src/gen/clients/store/getOrderById.ts +++ b/examples/vue-query/src/gen/clients/store/getOrderById.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetOrderByIdOptions, GetOrderByIdResponses } from '../../models/store/GetOrderById' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function getOrderById( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/store/order/{orderId}', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/store/placeOrder.ts b/examples/vue-query/src/gen/clients/store/placeOrder.ts index 8c1d56394..3a3da9192 100644 --- a/examples/vue-query/src/gen/clients/store/placeOrder.ts +++ b/examples/vue-query/src/gen/clients/store/placeOrder.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderOptions, PlaceOrderResponses } from '../../models/store/PlaceOrder' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrder( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/store/placeOrderPatch.ts b/examples/vue-query/src/gen/clients/store/placeOrderPatch.ts index 0772af4f7..692337b25 100644 --- a/examples/vue-query/src/gen/clients/store/placeOrderPatch.ts +++ b/examples/vue-query/src/gen/clients/store/placeOrderPatch.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { PlaceOrderPatchOptions, PlaceOrderPatchResponses } from '../../models/store/PlaceOrderPatch' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Place a new order in the store with patch @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function placeOrderPatch( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PATCH', url: '/store/order', ...config }) as Promise> + return withUnwrap(request({ method: 'PATCH', url: '/store/order', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/user/createUser.ts b/examples/vue-query/src/gen/clients/user/createUser.ts index af5bbc3e7..d9c8c13bc 100644 --- a/examples/vue-query/src/gen/clients/user/createUser.ts +++ b/examples/vue-query/src/gen/clients/user/createUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUserOptions, CreateUserResponses } from '../../models/user/CreateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function createUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user', ...config }) as Promise> + return withUnwrap(request({ method: 'POST', url: '/user', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/user/createUsersWithListInput.ts b/examples/vue-query/src/gen/clients/user/createUsersWithListInput.ts index b69d5d908..1e6a9e2ac 100644 --- a/examples/vue-query/src/gen/clients/user/createUsersWithListInput.ts +++ b/examples/vue-query/src/gen/clients/user/createUsersWithListInput.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { CreateUsersWithListInputOptions, CreateUsersWithListInputResponses } from '../../models/user/CreateUsersWithListInput' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description Creates list of users with given input array @@ -14,8 +14,10 @@ import { client } from '../../.kubb/client' */ export function createUsersWithListInput( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise> + return withUnwrap( + request({ method: 'POST', url: '/user/createWithList', ...config }) as Promise>, + ) } diff --git a/examples/vue-query/src/gen/clients/user/deleteUser.ts b/examples/vue-query/src/gen/clients/user/deleteUser.ts index dff00a13e..8dda91163 100644 --- a/examples/vue-query/src/gen/clients/user/deleteUser.ts +++ b/examples/vue-query/src/gen/clients/user/deleteUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { DeleteUserOptions, DeleteUserResponses } from '../../models/user/DeleteUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function deleteUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'DELETE', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/user/getUserByName.ts b/examples/vue-query/src/gen/clients/user/getUserByName.ts index 4db3b9d4d..2e0afe704 100644 --- a/examples/vue-query/src/gen/clients/user/getUserByName.ts +++ b/examples/vue-query/src/gen/clients/user/getUserByName.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { GetUserByNameOptions, GetUserByNameResponses } from '../../models/user/GetUserByName' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Get user by user name @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function getUserByName( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/{username}', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/user/loginUser.ts b/examples/vue-query/src/gen/clients/user/loginUser.ts index b619b4b9b..4a46c2208 100644 --- a/examples/vue-query/src/gen/clients/user/loginUser.ts +++ b/examples/vue-query/src/gen/clients/user/loginUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LoginUserOptions, LoginUserResponses } from '../../models/user/LoginUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs user into the system @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function loginUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/login', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/login', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/user/logoutUser.ts b/examples/vue-query/src/gen/clients/user/logoutUser.ts index e41276de9..a5c939fbb 100644 --- a/examples/vue-query/src/gen/clients/user/logoutUser.ts +++ b/examples/vue-query/src/gen/clients/user/logoutUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { LogoutUserOptions, LogoutUserResponses } from '../../models/user/LogoutUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @summary Logs out current logged in user session @@ -13,8 +13,8 @@ import { client } from '../../.kubb/client' */ export function logoutUser( options: Options = {}, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'GET', url: '/user/logout', ...config }) as Promise> + return withUnwrap(request({ method: 'GET', url: '/user/logout', ...config }) as Promise>) } diff --git a/examples/vue-query/src/gen/clients/user/updateUser.ts b/examples/vue-query/src/gen/clients/user/updateUser.ts index ce0faef1f..b6c6e7de1 100644 --- a/examples/vue-query/src/gen/clients/user/updateUser.ts +++ b/examples/vue-query/src/gen/clients/user/updateUser.ts @@ -3,9 +3,9 @@ * Do not edit manually. */ -import type { Options, RequestResult } from '../../.kubb/client' +import type { Options, Unwrappable, RequestResult } from '../../.kubb/client' import type { UpdateUserOptions, UpdateUserResponses } from '../../models/user/UpdateUser' -import { client } from '../../.kubb/client' +import { client, withUnwrap } from '../../.kubb/client' /** * @description This can only be done by the logged in user. @@ -14,8 +14,8 @@ import { client } from '../../.kubb/client' */ export function updateUser( options: Options, -): Promise> { +): Unwrappable> { const { client: request = client, ...config } = options - return request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise> + return withUnwrap(request({ method: 'PUT', url: '/user/{username}', ...config }) as Promise>) } From 918698ba16cfdb7e7bd64212ef0fe00e9787073f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 17:46:52 +0000 Subject: [PATCH 8/9] refactor(plugin-react-query,plugin-vue-query,plugin-swr): use unwrap() in generated hooks Query and mutation bodies destructured `{ data }` off the client call by hand. Every axios/fetch call already carries unwrap(), so the generated hooks call it directly instead, one line shorter and consistent with how a caller reaches for the bare success body outside a hook. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_012DSVW79h2FdFDkoWWr6PwN --- .changeset/client-unwrap-method.md | 6 ++++++ .../tanstack-query/src/components/InfiniteQueryOptions.tsx | 3 +-- .../plugin-react-query/src/components/MutationOptions.tsx | 3 +-- packages/plugin-react-query/src/components/QueryOptions.tsx | 3 +-- .../__snapshots__/clientPostImportPath/useFindPetsByTags.ts | 3 +-- .../clientPostImportPath/useFindPetsByTagsInfinite.ts | 3 +-- .../clientPostImportPath/useFindPetsByTagsSuspense.ts | 3 +-- .../useFindPetsByTagsSuspenseInfinite.ts | 3 +-- .../clientPostImportPath/useUpdatePetWithForm.ts | 3 +-- .../useCreateUsersWithListInput.ts | 3 +-- .../src/generators/__snapshots__/deletePet/useDeletePet.ts | 3 +-- .../findByStatusAllOptional/useFindPetsByStatus.ts | 3 +-- .../__snapshots__/findByTags/useFindPetsByTags.ts | 3 +-- .../__snapshots__/findByTags/useFindPetsByTagsInfinite.ts | 3 +-- .../__snapshots__/findByTags/useFindPetsByTagsSuspense.ts | 3 +-- .../findByTags/useFindPetsByTagsSuspenseInfinite.ts | 3 +-- .../findByTagsObject/useFindPetsByTagsInfinite.ts | 3 +-- .../findByTagsObject/useFindPetsByTagsSuspense.ts | 3 +-- .../findByTagsObject/useFindPetsByTagsSuspenseInfinite.ts | 3 +-- .../findByTagsTemplateString/useFindPetsByTags.ts | 3 +-- .../generators/__snapshots__/getPetById/useGetPetById.ts | 3 +-- .../getPetIdCamelCase/useGetPetByIdSuspense.ts | 3 +-- .../__snapshots__/headersOnly/useRetrieveMyProfile.ts | 3 +-- .../__snapshots__/multiContentType/useUploadFile.ts | 3 +-- .../__snapshots__/updatePetById/useUpdatePetWithForm.ts | 3 +-- packages/plugin-swr/src/components/Mutation.tsx | 3 +-- packages/plugin-swr/src/components/QueryOptions.tsx | 3 +-- .../src/generators/__snapshots__/createPet/useCreatePet.ts | 3 +-- .../src/generators/__snapshots__/deletePet/useDeletePet.ts | 3 +-- .../findByStatusAllOptional/useFindPetsByStatus.ts | 3 +-- .../__snapshots__/findByTags/useFindPetsByTags.ts | 3 +-- .../__snapshots__/getAsMutation/useFindPetsByTags.ts | 3 +-- .../generators/__snapshots__/getPetById/useGetPetById.ts | 3 +-- .../__snapshots__/updatePetWithForm/useUpdatePetWithForm.ts | 3 +-- packages/plugin-vue-query/src/components/Mutation.tsx | 3 +-- packages/plugin-vue-query/src/components/QueryOptions.tsx | 3 +-- .../__snapshots__/findByTags/useFindPetsByTags.ts | 3 +-- .../findByTagsTemplateString/useFindPetsByTags.ts | 3 +-- .../findByTagsWithCustomQueryKey/useFindPetsByTags.ts | 3 +-- .../findInfiniteByTags/useFindPetsByTagsInfinite.ts | 3 +-- .../findInfiniteByTagsCursor/useFindPetsByTagsInfinite.ts | 3 +-- .../__snapshots__/postAsQuery/useUpdatePetWithForm.ts | 5 ++--- .../__snapshots__/updatePetById/useUpdatePetWithForm.ts | 3 +-- .../useUpdatePetWithForm.ts | 3 +-- .../excludeByOperationId/hooks/useFindPetsByStatus.ts | 3 +-- .../excludeByOperationId/hooks/useGetInventory.ts | 3 +-- .../excludeByOperationId/hooks/useGetPetById.ts | 3 +-- .../excludeByOperationId/hooks/usePlaceOrder.ts | 3 +-- .../excludeByOperationId/hooks/useUploadFile.ts | 3 +-- .../pluginReactQuery/groupByTag/hooks/pet/useAddPet.ts | 3 +-- .../pluginReactQuery/groupByTag/hooks/pet/useDeletePet.ts | 3 +-- .../groupByTag/hooks/pet/useFindPetsByStatus.ts | 3 +-- .../pluginReactQuery/groupByTag/hooks/pet/useGetPetById.ts | 3 +-- .../pluginReactQuery/groupByTag/hooks/pet/useUploadFile.ts | 3 +-- .../groupByTag/hooks/store/useGetInventory.ts | 3 +-- .../groupByTag/hooks/store/usePlaceOrder.ts | 3 +-- .../pluginReactQuery/includeByTag/hooks/useAddPet.ts | 3 +-- .../pluginReactQuery/includeByTag/hooks/useDeletePet.ts | 3 +-- .../includeByTag/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginReactQuery/includeByTag/hooks/useGetPetById.ts | 3 +-- .../pluginReactQuery/includeByTag/hooks/useUploadFile.ts | 3 +-- .../pluginReactQuery/infinite/hooks/useAddPet.ts | 3 +-- .../pluginReactQuery/infinite/hooks/useDeletePet.ts | 3 +-- .../pluginReactQuery/infinite/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginReactQuery/infinite/hooks/useGetInventory.ts | 3 +-- .../pluginReactQuery/infinite/hooks/useGetPetById.ts | 3 +-- .../pluginReactQuery/infinite/hooks/usePlaceOrder.ts | 3 +-- .../pluginReactQuery/infinite/hooks/useUploadFile.ts | 3 +-- .../mutationDisabled/hooks/useFindPetsByStatus.ts | 3 +-- .../mutationDisabled/hooks/useGetInventory.ts | 3 +-- .../mutationDisabled/hooks/useGetPetById.ts | 3 +-- .../pluginReactQuery/paramsCasing/hooks/useUpdatePet.ts | 3 +-- .../pluginReactQuery/parserZod/hooks/useAddPet.ts | 3 +-- .../pluginReactQuery/parserZod/hooks/useDeletePet.ts | 3 +-- .../pluginReactQuery/parserZod/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginReactQuery/parserZod/hooks/useGetInventory.ts | 3 +-- .../pluginReactQuery/parserZod/hooks/useGetPetById.ts | 3 +-- .../pluginReactQuery/parserZod/hooks/usePlaceOrder.ts | 3 +-- .../pluginReactQuery/parserZod/hooks/useUploadFile.ts | 3 +-- .../pluginReactQuery/petStore/hooks/useAddPet.ts | 3 +-- .../pluginReactQuery/petStore/hooks/useDeletePet.ts | 3 +-- .../pluginReactQuery/petStore/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginReactQuery/petStore/hooks/useGetInventory.ts | 3 +-- .../pluginReactQuery/petStore/hooks/useGetPetById.ts | 3 +-- .../pluginReactQuery/petStore/hooks/usePlaceOrder.ts | 3 +-- .../pluginReactQuery/petStore/hooks/useUploadFile.ts | 3 +-- .../pluginReactQuery/queryMethods/hooks/useAddPet.ts | 3 +-- .../pluginReactQuery/queryMethods/hooks/useDeletePet.ts | 3 +-- .../queryMethods/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginReactQuery/queryMethods/hooks/useGetInventory.ts | 3 +-- .../pluginReactQuery/queryMethods/hooks/useGetPetById.ts | 3 +-- .../pluginReactQuery/queryMethods/hooks/usePlaceOrder.ts | 3 +-- .../pluginReactQuery/queryMethods/hooks/useUploadFile.ts | 3 +-- .../pluginReactQuery/suspense/hooks/useAddPet.ts | 3 +-- .../pluginReactQuery/suspense/hooks/useDeletePet.ts | 3 +-- .../pluginReactQuery/suspense/hooks/useFindPetsByStatus.ts | 3 +-- .../suspense/hooks/useFindPetsByStatusSuspense.ts | 3 +-- .../pluginReactQuery/suspense/hooks/useGetInventory.ts | 3 +-- .../suspense/hooks/useGetInventorySuspense.ts | 3 +-- .../pluginReactQuery/suspense/hooks/useGetPetById.ts | 3 +-- .../suspense/hooks/useGetPetByIdSuspense.ts | 3 +-- .../pluginReactQuery/suspense/hooks/usePlaceOrder.ts | 3 +-- .../pluginReactQuery/suspense/hooks/useUploadFile.ts | 3 +-- .../pluginReactQuery/withClientPlugin/hooks/useAddPet.ts | 3 +-- .../pluginReactQuery/withClientPlugin/hooks/useDeletePet.ts | 3 +-- .../withClientPlugin/hooks/useFindPetsByStatus.ts | 3 +-- .../withClientPlugin/hooks/useGetInventory.ts | 3 +-- .../withClientPlugin/hooks/useGetPetById.ts | 3 +-- .../withClientPlugin/hooks/usePlaceOrder.ts | 3 +-- .../withClientPlugin/hooks/useUploadFile.ts | 3 +-- .../excludeByOperationId/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/excludeByOperationId/hooks/useGetInventory.ts | 3 +-- .../pluginSwr/excludeByOperationId/hooks/useGetPetById.ts | 3 +-- .../pluginSwr/excludeByOperationId/hooks/usePlaceOrder.ts | 3 +-- .../pluginSwr/excludeByOperationId/hooks/useUploadFile.ts | 3 +-- .../pluginSwr/groupByTag/hooks/pet/useAddPet.ts | 3 +-- .../pluginSwr/groupByTag/hooks/pet/useDeletePet.ts | 3 +-- .../pluginSwr/groupByTag/hooks/pet/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/groupByTag/hooks/pet/useGetPetById.ts | 3 +-- .../pluginSwr/groupByTag/hooks/pet/useUploadFile.ts | 3 +-- .../pluginSwr/groupByTag/hooks/store/useGetInventory.ts | 3 +-- .../pluginSwr/groupByTag/hooks/store/usePlaceOrder.ts | 3 +-- .../__snapshots__/pluginSwr/includeByTag/hooks/useAddPet.ts | 3 +-- .../pluginSwr/includeByTag/hooks/useDeletePet.ts | 3 +-- .../pluginSwr/includeByTag/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/includeByTag/hooks/useGetPetById.ts | 3 +-- .../pluginSwr/includeByTag/hooks/useUploadFile.ts | 3 +-- .../pluginSwr/mutationDisabled/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/mutationDisabled/hooks/useGetInventory.ts | 3 +-- .../pluginSwr/mutationDisabled/hooks/useGetPetById.ts | 3 +-- .../pluginSwr/paramsCasing/hooks/useUpdatePet.ts | 3 +-- .../__snapshots__/pluginSwr/parserZod/hooks/useAddPet.ts | 3 +-- .../__snapshots__/pluginSwr/parserZod/hooks/useDeletePet.ts | 3 +-- .../pluginSwr/parserZod/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/parserZod/hooks/useGetInventory.ts | 3 +-- .../pluginSwr/parserZod/hooks/useGetPetById.ts | 3 +-- .../pluginSwr/parserZod/hooks/usePlaceOrder.ts | 3 +-- .../pluginSwr/parserZod/hooks/useUploadFile.ts | 3 +-- .../__snapshots__/pluginSwr/petStore/hooks/useAddPet.ts | 3 +-- .../__snapshots__/pluginSwr/petStore/hooks/useDeletePet.ts | 3 +-- .../pluginSwr/petStore/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/petStore/hooks/useGetInventory.ts | 3 +-- .../__snapshots__/pluginSwr/petStore/hooks/useGetPetById.ts | 3 +-- .../__snapshots__/pluginSwr/petStore/hooks/usePlaceOrder.ts | 3 +-- .../__snapshots__/pluginSwr/petStore/hooks/useUploadFile.ts | 3 +-- .../pluginSwr/queryDisabled/hooks/useAddPet.ts | 3 +-- .../pluginSwr/queryDisabled/hooks/useDeletePet.ts | 3 +-- .../pluginSwr/queryDisabled/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/queryDisabled/hooks/useGetInventory.ts | 3 +-- .../pluginSwr/queryDisabled/hooks/useGetPetById.ts | 3 +-- .../pluginSwr/queryDisabled/hooks/usePlaceOrder.ts | 3 +-- .../pluginSwr/queryDisabled/hooks/useUploadFile.ts | 3 +-- .../__snapshots__/pluginSwr/queryMethods/hooks/useAddPet.ts | 3 +-- .../pluginSwr/queryMethods/hooks/useDeletePet.ts | 3 +-- .../pluginSwr/queryMethods/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/queryMethods/hooks/useGetInventory.ts | 3 +-- .../pluginSwr/queryMethods/hooks/useGetPetById.ts | 3 +-- .../pluginSwr/queryMethods/hooks/usePlaceOrder.ts | 3 +-- .../pluginSwr/queryMethods/hooks/useUploadFile.ts | 3 +-- .../pluginSwr/withClientPlugin/hooks/useAddPet.ts | 3 +-- .../pluginSwr/withClientPlugin/hooks/useDeletePet.ts | 3 +-- .../pluginSwr/withClientPlugin/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginSwr/withClientPlugin/hooks/useGetInventory.ts | 3 +-- .../pluginSwr/withClientPlugin/hooks/useGetPetById.ts | 3 +-- .../pluginSwr/withClientPlugin/hooks/usePlaceOrder.ts | 3 +-- .../pluginSwr/withClientPlugin/hooks/useUploadFile.ts | 3 +-- .../excludeByOperationId/hooks/useFindPetsByStatus.ts | 3 +-- .../excludeByOperationId/hooks/useGetInventory.ts | 3 +-- .../excludeByOperationId/hooks/useGetPetById.ts | 3 +-- .../excludeByOperationId/hooks/usePlaceOrder.ts | 3 +-- .../excludeByOperationId/hooks/useUploadFile.ts | 3 +-- .../pluginVueQuery/groupByTag/hooks/pet/useAddPet.ts | 3 +-- .../pluginVueQuery/groupByTag/hooks/pet/useDeletePet.ts | 3 +-- .../groupByTag/hooks/pet/useFindPetsByStatus.ts | 3 +-- .../pluginVueQuery/groupByTag/hooks/pet/useGetPetById.ts | 3 +-- .../pluginVueQuery/groupByTag/hooks/pet/useUploadFile.ts | 3 +-- .../groupByTag/hooks/store/useGetInventory.ts | 3 +-- .../pluginVueQuery/groupByTag/hooks/store/usePlaceOrder.ts | 3 +-- .../pluginVueQuery/includeByTag/hooks/useAddPet.ts | 3 +-- .../pluginVueQuery/includeByTag/hooks/useDeletePet.ts | 3 +-- .../includeByTag/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginVueQuery/includeByTag/hooks/useGetPetById.ts | 3 +-- .../pluginVueQuery/includeByTag/hooks/useUploadFile.ts | 3 +-- .../pluginVueQuery/infinite/hooks/useAddPet.ts | 3 +-- .../pluginVueQuery/infinite/hooks/useDeletePet.ts | 3 +-- .../pluginVueQuery/infinite/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginVueQuery/infinite/hooks/useGetInventory.ts | 3 +-- .../pluginVueQuery/infinite/hooks/useGetPetById.ts | 3 +-- .../pluginVueQuery/infinite/hooks/usePlaceOrder.ts | 3 +-- .../pluginVueQuery/infinite/hooks/useUploadFile.ts | 3 +-- .../mutationDisabled/hooks/useFindPetsByStatus.ts | 3 +-- .../mutationDisabled/hooks/useGetInventory.ts | 3 +-- .../pluginVueQuery/mutationDisabled/hooks/useGetPetById.ts | 3 +-- .../pluginVueQuery/paramsCasing/hooks/useUpdatePet.ts | 3 +-- .../pluginVueQuery/parserZod/hooks/useAddPet.ts | 3 +-- .../pluginVueQuery/parserZod/hooks/useDeletePet.ts | 3 +-- .../pluginVueQuery/parserZod/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginVueQuery/parserZod/hooks/useGetInventory.ts | 3 +-- .../pluginVueQuery/parserZod/hooks/useGetPetById.ts | 3 +-- .../pluginVueQuery/parserZod/hooks/usePlaceOrder.ts | 3 +-- .../pluginVueQuery/parserZod/hooks/useUploadFile.ts | 3 +-- .../pluginVueQuery/petStore/hooks/useAddPet.ts | 3 +-- .../pluginVueQuery/petStore/hooks/useDeletePet.ts | 3 +-- .../pluginVueQuery/petStore/hooks/useFindPetsByStatus.ts | 3 +-- .../pluginVueQuery/petStore/hooks/useGetInventory.ts | 3 +-- .../pluginVueQuery/petStore/hooks/useGetPetById.ts | 3 +-- .../pluginVueQuery/petStore/hooks/usePlaceOrder.ts | 3 +-- .../pluginVueQuery/petStore/hooks/useUploadFile.ts | 3 +-- .../pluginVueQuery/withClientPlugin/hooks/useAddPet.ts | 3 +-- .../pluginVueQuery/withClientPlugin/hooks/useDeletePet.ts | 3 +-- .../withClientPlugin/hooks/useFindPetsByStatus.ts | 3 +-- .../withClientPlugin/hooks/useGetInventory.ts | 3 +-- .../pluginVueQuery/withClientPlugin/hooks/useGetPetById.ts | 3 +-- .../pluginVueQuery/withClientPlugin/hooks/usePlaceOrder.ts | 3 +-- .../pluginVueQuery/withClientPlugin/hooks/useUploadFile.ts | 3 +-- 215 files changed, 221 insertions(+), 429 deletions(-) diff --git a/.changeset/client-unwrap-method.md b/.changeset/client-unwrap-method.md index 24c7ab248..f3cc02b65 100644 --- a/.changeset/client-unwrap-method.md +++ b/.changeset/client-unwrap-method.md @@ -1,6 +1,9 @@ --- '@kubb/plugin-axios': minor '@kubb/plugin-fetch': minor +'@kubb/plugin-react-query': patch +'@kubb/plugin-vue-query': patch +'@kubb/plugin-swr': patch --- Generated calls now return a promise with an extra `unwrap()` method. Calling it gives you the bare @@ -12,3 +15,6 @@ const pet = await getPetById({ path: { petId: 1 } }).unwrap() ``` Awaiting the call directly still gives the full result, so nothing existing changes. + +`plugin-react-query`, `plugin-vue-query`, and `plugin-swr` now build their generated query and +mutation bodies on top of `unwrap()` too, instead of destructuring the result by hand. diff --git a/internals/tanstack-query/src/components/InfiniteQueryOptions.tsx b/internals/tanstack-query/src/components/InfiniteQueryOptions.tsx index 65769576a..c9f5c1063 100644 --- a/internals/tanstack-query/src/components/InfiniteQueryOptions.tsx +++ b/internals/tanstack-query/src/components/InfiniteQueryOptions.tsx @@ -63,8 +63,7 @@ export function InfiniteQueryOptions({ const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver, memberTypeWrapper }) const paramsSignature = declarationPrinter.print(paramsNode) ?? '' - const queryFnBody = `const { data } = await ${buildClientCall(node, { clientName, signal: true, unwrapName })} - return data` + const queryFnBody = `return ${buildClientCall(node, { clientName, signal: true, unwrapName })}.unwrap()` const hasNewParams = nextParam != null || previousParam != null diff --git a/packages/plugin-react-query/src/components/MutationOptions.tsx b/packages/plugin-react-query/src/components/MutationOptions.tsx index d5e36d5b2..66a271483 100644 --- a/packages/plugin-react-query/src/components/MutationOptions.tsx +++ b/packages/plugin-react-query/src/components/MutationOptions.tsx @@ -41,8 +41,7 @@ export function MutationOptions({ name, clientName, node, tsResolver, mutationKe const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] }) const TRequest = hasMutationParams ? tsResolver.response.options(node) : 'undefined' const argBindingStr = hasMutationParams ? (callPrinter.print(groupedParamsNode) ?? '') : '_' - const mutationFnBody = `const { data } = await ${buildClientCall(node, { clientName, signal: false })} - return data` + const mutationFnBody = `return ${buildClientCall(node, { clientName, signal: false })}.unwrap()` return ( diff --git a/packages/plugin-react-query/src/components/QueryOptions.tsx b/packages/plugin-react-query/src/components/QueryOptions.tsx index 7fff89fd5..c17c67431 100644 --- a/packages/plugin-react-query/src/components/QueryOptions.tsx +++ b/packages/plugin-react-query/src/components/QueryOptions.tsx @@ -25,8 +25,7 @@ export function QueryOptions({ name, clientName, node, tsResolver, queryKeyName const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver }) const paramsSignature = declarationPrinter.print(paramsNode) ?? '' - const queryFnBody = `const { data } = await ${buildClientCall(node, { clientName, signal: true })} - return data` + const queryFnBody = `return ${buildClientCall(node, { clientName, signal: true })}.unwrap()` return ( diff --git a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTags.ts b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTags.ts index e08ba0ce5..b66ab985b 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTags.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTags.ts @@ -22,8 +22,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsInfinite.ts b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsInfinite.ts index 860876fc0..a012a03c7 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsInfinite.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsInfinite.ts @@ -33,8 +33,7 @@ export function findPetsByTagsInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1), diff --git a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsSuspense.ts b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsSuspense.ts index d054f8643..6e98c9671 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsSuspense.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsSuspense.ts @@ -23,8 +23,7 @@ export function findPetsByTagsSuspenseQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsSuspenseInfinite.ts b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsSuspenseInfinite.ts index 2aa308155..6b1feae67 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsSuspenseInfinite.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useFindPetsByTagsSuspenseInfinite.ts @@ -33,8 +33,7 @@ export function findPetsByTagsSuspenseInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1), diff --git a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useUpdatePetWithForm.ts b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useUpdatePetWithForm.ts index cd96517c7..db709c4ea 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useUpdatePetWithForm.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/clientPostImportPath/useUpdatePetWithForm.ts @@ -17,8 +17,7 @@ export function updatePetWithFormMutationOptions(config: Par return mutationOptions, UpdatePetWithFormOptions, TContext>({ mutationKey, mutationFn: async ({ path, body }) => { - const { data } = await updatePetWithForm({ ...config, path, body, throwOnError: true }) - return data + return updatePetWithForm({ ...config, path, body, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/createUsersWithListInputAsQuery/useCreateUsersWithListInput.ts b/packages/plugin-react-query/src/generators/__snapshots__/createUsersWithListInputAsQuery/useCreateUsersWithListInput.ts index fef6408a4..f904e4d46 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/createUsersWithListInputAsQuery/useCreateUsersWithListInput.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/createUsersWithListInputAsQuery/useCreateUsersWithListInput.ts @@ -23,8 +23,7 @@ export function createUsersWithListInputQueryOptions( return queryOptions, CreateUsersWithListInputStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await createUsersWithListInput({ ...config, body, signal: config.signal ?? signal, throwOnError: true }) - return data + return createUsersWithListInput({ ...config, body, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/deletePet/useDeletePet.ts b/packages/plugin-react-query/src/generators/__snapshots__/deletePet/useDeletePet.ts index edd861310..ad704e4ff 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/deletePet/useDeletePet.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/deletePet/useDeletePet.ts @@ -17,8 +17,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async ({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByStatusAllOptional/useFindPetsByStatus.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByStatusAllOptional/useFindPetsByStatus.ts index 12622d602..622840094 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByStatusAllOptional/useFindPetsByStatus.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByStatusAllOptional/useFindPetsByStatus.ts @@ -23,8 +23,7 @@ export function findPetsByStatusQueryOptions( return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts index e08ba0ce5..b66ab985b 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts @@ -22,8 +22,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsInfinite.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsInfinite.ts index 860876fc0..a012a03c7 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsInfinite.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsInfinite.ts @@ -33,8 +33,7 @@ export function findPetsByTagsInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1), diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsSuspense.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsSuspense.ts index d054f8643..6e98c9671 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsSuspense.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsSuspense.ts @@ -23,8 +23,7 @@ export function findPetsByTagsSuspenseQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsSuspenseInfinite.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsSuspenseInfinite.ts index 2aa308155..6b1feae67 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsSuspenseInfinite.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByTags/useFindPetsByTagsSuspenseInfinite.ts @@ -33,8 +33,7 @@ export function findPetsByTagsSuspenseInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1), diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsInfinite.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsInfinite.ts index 860876fc0..a012a03c7 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsInfinite.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsInfinite.ts @@ -33,8 +33,7 @@ export function findPetsByTagsInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1), diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsSuspense.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsSuspense.ts index d054f8643..6e98c9671 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsSuspense.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsSuspense.ts @@ -23,8 +23,7 @@ export function findPetsByTagsSuspenseQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsSuspenseInfinite.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsSuspenseInfinite.ts index 2aa308155..6b1feae67 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsSuspenseInfinite.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByTagsObject/useFindPetsByTagsSuspenseInfinite.ts @@ -33,8 +33,7 @@ export function findPetsByTagsSuspenseInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1), diff --git a/packages/plugin-react-query/src/generators/__snapshots__/findByTagsTemplateString/useFindPetsByTags.ts b/packages/plugin-react-query/src/generators/__snapshots__/findByTagsTemplateString/useFindPetsByTags.ts index e08ba0ce5..b66ab985b 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/findByTagsTemplateString/useFindPetsByTags.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/findByTagsTemplateString/useFindPetsByTags.ts @@ -22,8 +22,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/getPetById/useGetPetById.ts b/packages/plugin-react-query/src/generators/__snapshots__/getPetById/useGetPetById.ts index 33bca40e5..ef58494db 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/getPetById/useGetPetById.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/getPetById/useGetPetById.ts @@ -19,8 +19,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/getPetIdCamelCase/useGetPetByIdSuspense.ts b/packages/plugin-react-query/src/generators/__snapshots__/getPetIdCamelCase/useGetPetByIdSuspense.ts index f60839fc6..4294619d2 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/getPetIdCamelCase/useGetPetByIdSuspense.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/getPetIdCamelCase/useGetPetByIdSuspense.ts @@ -22,8 +22,7 @@ export function getPetByIdSuspenseQueryOptions( return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/headersOnly/useRetrieveMyProfile.ts b/packages/plugin-react-query/src/generators/__snapshots__/headersOnly/useRetrieveMyProfile.ts index d8e2b780c..04a7b8b72 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/headersOnly/useRetrieveMyProfile.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/headersOnly/useRetrieveMyProfile.ts @@ -22,8 +22,7 @@ export function retrieveMyProfileQueryOptions( return queryOptions, RetrieveMyProfileStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await retrieveMyProfile({ ...config, headers, signal: config.signal ?? signal, throwOnError: true }) - return data + return retrieveMyProfile({ ...config, headers, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/multiContentType/useUploadFile.ts b/packages/plugin-react-query/src/generators/__snapshots__/multiContentType/useUploadFile.ts index acc0e88c6..3a64fb4f0 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/multiContentType/useUploadFile.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/multiContentType/useUploadFile.ts @@ -21,8 +21,7 @@ export function uploadFileMutationOptions( return mutationOptions, UploadFileOptions, TContext>({ mutationKey, mutationFn: async ({ path, body }) => { - const { data } = await uploadFile({ ...config, path, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, body, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-react-query/src/generators/__snapshots__/updatePetById/useUpdatePetWithForm.ts b/packages/plugin-react-query/src/generators/__snapshots__/updatePetById/useUpdatePetWithForm.ts index cd96517c7..db709c4ea 100644 --- a/packages/plugin-react-query/src/generators/__snapshots__/updatePetById/useUpdatePetWithForm.ts +++ b/packages/plugin-react-query/src/generators/__snapshots__/updatePetById/useUpdatePetWithForm.ts @@ -17,8 +17,7 @@ export function updatePetWithFormMutationOptions(config: Par return mutationOptions, UpdatePetWithFormOptions, TContext>({ mutationKey, mutationFn: async ({ path, body }) => { - const { data } = await updatePetWithForm({ ...config, path, body, throwOnError: true }) - return data + return updatePetWithForm({ ...config, path, body, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-swr/src/components/Mutation.tsx b/packages/plugin-swr/src/components/Mutation.tsx index 2506e06c3..541ebf917 100644 --- a/packages/plugin-swr/src/components/Mutation.tsx +++ b/packages/plugin-swr/src/components/Mutation.tsx @@ -61,8 +61,7 @@ export function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeNam const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] }) const argTypeBody = hasMutationParams ? tsResolver.response.options(node) : '' const argBindingStr = hasMutationParams ? (callPrinter.print(groupedParamsNode) ?? '') : '' - const mutationFnBody = `const { data } = await ${buildClientCall(node, { clientName, signal: false })} - return data` + const mutationFnBody = `return ${buildClientCall(node, { clientName, signal: false })}.unwrap()` const generics = [TData, TError, `${mutationKeyTypeName} | null`, mutationArgTypeName] diff --git a/packages/plugin-swr/src/components/QueryOptions.tsx b/packages/plugin-swr/src/components/QueryOptions.tsx index 62445d97a..d54ae2e4f 100644 --- a/packages/plugin-swr/src/components/QueryOptions.tsx +++ b/packages/plugin-swr/src/components/QueryOptions.tsx @@ -17,8 +17,7 @@ const declarationPrinter = functionPrinter({ mode: 'declaration' }) export function QueryOptions({ name, clientName, node, tsResolver }: Props): KubbReactNode { const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver }) const paramsSignature = declarationPrinter.print(paramsNode) ?? '' - const fetcherBody = `const { data } = await ${buildClientCall(node, { clientName, signal: false })} - return data` + const fetcherBody = `return ${buildClientCall(node, { clientName, signal: false })}.unwrap()` return ( diff --git a/packages/plugin-swr/src/generators/__snapshots__/createPet/useCreatePet.ts b/packages/plugin-swr/src/generators/__snapshots__/createPet/useCreatePet.ts index 5fbfc2163..4dc0ecd6b 100644 --- a/packages/plugin-swr/src/generators/__snapshots__/createPet/useCreatePet.ts +++ b/packages/plugin-swr/src/generators/__snapshots__/createPet/useCreatePet.ts @@ -34,8 +34,7 @@ export function useCreatePet( return useSWRMutation, CreatePetMutationKey | null, CreatePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await createPet({ ...config, body, throwOnError: true }) - return data + return createPet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/packages/plugin-swr/src/generators/__snapshots__/deletePet/useDeletePet.ts b/packages/plugin-swr/src/generators/__snapshots__/deletePet/useDeletePet.ts index 0fad8915b..33067e884 100644 --- a/packages/plugin-swr/src/generators/__snapshots__/deletePet/useDeletePet.ts +++ b/packages/plugin-swr/src/generators/__snapshots__/deletePet/useDeletePet.ts @@ -34,8 +34,7 @@ export function useDeletePet( return useSWRMutation, DeletePetMutationKey | null, DeletePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, headers } }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/packages/plugin-swr/src/generators/__snapshots__/findByStatusAllOptional/useFindPetsByStatus.ts b/packages/plugin-swr/src/generators/__snapshots__/findByStatusAllOptional/useFindPetsByStatus.ts index 6d5dd7ddd..4fcc3e0b9 100644 --- a/packages/plugin-swr/src/generators/__snapshots__/findByStatusAllOptional/useFindPetsByStatus.ts +++ b/packages/plugin-swr/src/generators/__snapshots__/findByStatusAllOptional/useFindPetsByStatus.ts @@ -21,8 +21,7 @@ export function findPetsByStatusQueryOptions( ) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/packages/plugin-swr/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts b/packages/plugin-swr/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts index adf410c83..b470b6baa 100644 --- a/packages/plugin-swr/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts +++ b/packages/plugin-swr/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts @@ -20,8 +20,7 @@ export function findPetsByTagsQueryOptions( ) { return { fetcher: async () => { - const { data } = await findPetsByTags({ ...config, query, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/packages/plugin-swr/src/generators/__snapshots__/getAsMutation/useFindPetsByTags.ts b/packages/plugin-swr/src/generators/__snapshots__/getAsMutation/useFindPetsByTags.ts index acb1dca66..48f3bb70f 100644 --- a/packages/plugin-swr/src/generators/__snapshots__/getAsMutation/useFindPetsByTags.ts +++ b/packages/plugin-swr/src/generators/__snapshots__/getAsMutation/useFindPetsByTags.ts @@ -34,8 +34,7 @@ export function useFindPetsByTags( return useSWRMutation, FindPetsByTagsMutationKey | null, FindPetsByTagsMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { query } }) => { - const { data } = await findPetsByTags({ ...config, query, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/packages/plugin-swr/src/generators/__snapshots__/getPetById/useGetPetById.ts b/packages/plugin-swr/src/generators/__snapshots__/getPetById/useGetPetById.ts index 48f2d4218..de7c4f45a 100644 --- a/packages/plugin-swr/src/generators/__snapshots__/getPetById/useGetPetById.ts +++ b/packages/plugin-swr/src/generators/__snapshots__/getPetById/useGetPetById.ts @@ -17,8 +17,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/packages/plugin-swr/src/generators/__snapshots__/updatePetWithForm/useUpdatePetWithForm.ts b/packages/plugin-swr/src/generators/__snapshots__/updatePetWithForm/useUpdatePetWithForm.ts index 17271ae10..e86d40a30 100644 --- a/packages/plugin-swr/src/generators/__snapshots__/updatePetWithForm/useUpdatePetWithForm.ts +++ b/packages/plugin-swr/src/generators/__snapshots__/updatePetWithForm/useUpdatePetWithForm.ts @@ -37,8 +37,7 @@ export function useUpdatePetWithForm( return useSWRMutation, UpdatePetWithFormMutationKey | null, UpdatePetWithFormMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, body } }) => { - const { data } = await updatePetWithForm({ ...config, path, body, throwOnError: true }) - return data + return updatePetWithForm({ ...config, path, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/packages/plugin-vue-query/src/components/Mutation.tsx b/packages/plugin-vue-query/src/components/Mutation.tsx index 0733142a6..06f7088fa 100644 --- a/packages/plugin-vue-query/src/components/Mutation.tsx +++ b/packages/plugin-vue-query/src/components/Mutation.tsx @@ -55,8 +55,7 @@ export function Mutation({ name, clientName, node, tsResolver, mutationKeyName } const hasMutationParams = groupedParam !== null const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] }) const argBindingStr = hasMutationParams ? (callPrinter.print(groupedParamsNode) ?? '') : '' - const mutationFnBody = `const { data } = await ${buildVueClientCall(node, { clientName, signal: false })} - return data` + const mutationFnBody = `return ${buildVueClientCall(node, { clientName, signal: false })}.unwrap()` const TRequest = resolveMutationRequestType(node, tsResolver) const generics = [TData, TError, TRequest, 'TContext'].join(', ') diff --git a/packages/plugin-vue-query/src/components/QueryOptions.tsx b/packages/plugin-vue-query/src/components/QueryOptions.tsx index c565e5b0b..c343d156f 100644 --- a/packages/plugin-vue-query/src/components/QueryOptions.tsx +++ b/packages/plugin-vue-query/src/components/QueryOptions.tsx @@ -30,8 +30,7 @@ export function QueryOptions({ name, clientName, node, tsResolver, queryKeyName const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver }) const paramsSignature = declarationPrinter.print(paramsNode) ?? '' - const queryFnBody = `const { data } = await ${buildVueClientCall(node, { clientName, signal: true })} - return data` + const queryFnBody = `return ${buildVueClientCall(node, { clientName, signal: true })}.unwrap()` return ( diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts b/packages/plugin-vue-query/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts index 909365883..78bfd6c74 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/findByTags/useFindPetsByTags.ts @@ -25,8 +25,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/findByTagsTemplateString/useFindPetsByTags.ts b/packages/plugin-vue-query/src/generators/__snapshots__/findByTagsTemplateString/useFindPetsByTags.ts index 909365883..78bfd6c74 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/findByTagsTemplateString/useFindPetsByTags.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/findByTagsTemplateString/useFindPetsByTags.ts @@ -25,8 +25,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/findByTagsWithCustomQueryKey/useFindPetsByTags.ts b/packages/plugin-vue-query/src/generators/__snapshots__/findByTagsWithCustomQueryKey/useFindPetsByTags.ts index 8d0e19cd3..9a9b50140 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/findByTagsWithCustomQueryKey/useFindPetsByTags.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/findByTagsWithCustomQueryKey/useFindPetsByTags.ts @@ -25,8 +25,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTags/useFindPetsByTagsInfinite.ts b/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTags/useFindPetsByTagsInfinite.ts index 6af38f73b..df0e10004 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTags/useFindPetsByTagsInfinite.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTags/useFindPetsByTagsInfinite.ts @@ -35,8 +35,7 @@ export function findPetsByTagsInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1), diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTagsCursor/useFindPetsByTagsInfinite.ts b/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTagsCursor/useFindPetsByTagsInfinite.ts index 7354620f9..d775dec7c 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTagsCursor/useFindPetsByTagsInfinite.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/findInfiniteByTagsCursor/useFindPetsByTagsInfinite.ts @@ -35,8 +35,7 @@ export function findPetsByTagsInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage) => lastPage['cursor'], diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/postAsQuery/useUpdatePetWithForm.ts b/packages/plugin-vue-query/src/generators/__snapshots__/postAsQuery/useUpdatePetWithForm.ts index 91ee3d9d8..3417042e5 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/postAsQuery/useUpdatePetWithForm.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/postAsQuery/useUpdatePetWithForm.ts @@ -40,15 +40,14 @@ export function updatePetWithFormQueryOptions( return queryOptions, UpdatePetWithFormStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await updatePetWithForm({ + return updatePetWithForm({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), signal: config.signal ?? signal, throwOnError: true, - }) - return data + }).unwrap() }, }) } diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/updatePetById/useUpdatePetWithForm.ts b/packages/plugin-vue-query/src/generators/__snapshots__/updatePetById/useUpdatePetWithForm.ts index 24f31e407..4a63e861c 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/updatePetById/useUpdatePetWithForm.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/updatePetById/useUpdatePetWithForm.ts @@ -29,8 +29,7 @@ export function useUpdatePetWithForm( return useMutation, UpdatePetWithFormOptions, TContext>( { mutationFn: async ({ path, body }) => { - const { data } = await updatePetWithForm({ ...config, path: toValue(path), body: toValue(body), throwOnError: true }) - return data + return updatePetWithForm({ ...config, path: toValue(path), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions, diff --git a/packages/plugin-vue-query/src/generators/__snapshots__/updatePetByIdWithCustomMutationKey/useUpdatePetWithForm.ts b/packages/plugin-vue-query/src/generators/__snapshots__/updatePetByIdWithCustomMutationKey/useUpdatePetWithForm.ts index a1fe2e04c..c8993bcac 100644 --- a/packages/plugin-vue-query/src/generators/__snapshots__/updatePetByIdWithCustomMutationKey/useUpdatePetWithForm.ts +++ b/packages/plugin-vue-query/src/generators/__snapshots__/updatePetByIdWithCustomMutationKey/useUpdatePetWithForm.ts @@ -29,8 +29,7 @@ export function useUpdatePetWithForm( return useMutation, UpdatePetWithFormOptions, TContext>( { mutationFn: async ({ path, body }) => { - const { data } = await updatePetWithForm({ ...config, path: toValue(path), body: toValue(body), throwOnError: true }) - return data + return updatePetWithForm({ ...config, path: toValue(path), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions, diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useGetInventory.ts index 429740790..5cb2467b1 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/usePlaceOrder.ts index f8b691050..0d18d3336 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/usePlaceOrder.ts @@ -16,8 +16,7 @@ export function placeOrderMutationOptions(config: Partial, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useUploadFile.ts index 0265a8474..5f8e980ae 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/excludeByOperationId/hooks/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useAddPet.ts index 2583987c5..099d53ce2 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useAddPet.ts @@ -16,8 +16,7 @@ export function addPetMutationOptions(config: Partial, AddPetOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useDeletePet.ts index eaf868ef1..f94b1beb9 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useDeletePet.ts @@ -16,8 +16,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useFindPetsByStatus.ts index 55033810b..7f23d48f6 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useGetPetById.ts index c75374ee6..2857d9a02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useUploadFile.ts index 4233bb97a..d4b0b1d0c 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/pet/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/store/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/store/useGetInventory.ts index af2066ff4..b188ef801 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/store/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/store/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/store/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/store/usePlaceOrder.ts index 0c3bac1d1..9b2de3e53 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/store/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/groupByTag/hooks/store/usePlaceOrder.ts @@ -16,8 +16,7 @@ export function placeOrderMutationOptions(config: Partial, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useAddPet.ts index 91b9c0487..ee3cceef5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useAddPet.ts @@ -16,8 +16,7 @@ export function addPetMutationOptions(config: Partial, AddPetOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useDeletePet.ts index 45c8431e7..c2213c5f5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useDeletePet.ts @@ -16,8 +16,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useUploadFile.ts index 0265a8474..5f8e980ae 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/includeByTag/hooks/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useAddPet.ts index 91b9c0487..ee3cceef5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useAddPet.ts @@ -16,8 +16,7 @@ export function addPetMutationOptions(config: Partial, AddPetOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useDeletePet.ts index 45c8431e7..c2213c5f5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useDeletePet.ts @@ -16,8 +16,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useGetInventory.ts index 429740790..5cb2467b1 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/usePlaceOrder.ts index f8b691050..0d18d3336 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/usePlaceOrder.ts @@ -16,8 +16,7 @@ export function placeOrderMutationOptions(config: Partial, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useUploadFile.ts index 0265a8474..5f8e980ae 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/infinite/hooks/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useGetInventory.ts index 429740790..5cb2467b1 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/mutationDisabled/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/hooks/useUpdatePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/hooks/useUpdatePet.ts index 31bed050a..b77184cfb 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/hooks/useUpdatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/paramsCasing/hooks/useUpdatePet.ts @@ -16,8 +16,7 @@ export function updatePetMutationOptions(config: Partial, UpdatePetOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body, headers }) => { - const { data } = await updatePet({ ...config, path, query, body, headers, throwOnError: true }) - return data + return updatePet({ ...config, path, query, body, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useAddPet.ts index 91b9c0487..ee3cceef5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useAddPet.ts @@ -16,8 +16,7 @@ export function addPetMutationOptions(config: Partial, AddPetOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useDeletePet.ts index 45c8431e7..c2213c5f5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useDeletePet.ts @@ -16,8 +16,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useGetInventory.ts index 429740790..5cb2467b1 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/usePlaceOrder.ts index f8b691050..0d18d3336 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/usePlaceOrder.ts @@ -16,8 +16,7 @@ export function placeOrderMutationOptions(config: Partial, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useUploadFile.ts index 0265a8474..5f8e980ae 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/parserZod/hooks/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useAddPet.ts index 91b9c0487..ee3cceef5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useAddPet.ts @@ -16,8 +16,7 @@ export function addPetMutationOptions(config: Partial, AddPetOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useDeletePet.ts index 45c8431e7..c2213c5f5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useDeletePet.ts @@ -16,8 +16,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useGetInventory.ts index 429740790..5cb2467b1 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/usePlaceOrder.ts index f8b691050..0d18d3336 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/usePlaceOrder.ts @@ -16,8 +16,7 @@ export function placeOrderMutationOptions(config: Partial, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useUploadFile.ts index 0265a8474..5f8e980ae 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/petStore/hooks/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useAddPet.ts index 91b9c0487..ee3cceef5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useAddPet.ts @@ -16,8 +16,7 @@ export function addPetMutationOptions(config: Partial, AddPetOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useDeletePet.ts index 45c8431e7..c2213c5f5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useDeletePet.ts @@ -16,8 +16,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useGetInventory.ts index 429740790..5cb2467b1 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/usePlaceOrder.ts index f8b691050..0d18d3336 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/usePlaceOrder.ts @@ -16,8 +16,7 @@ export function placeOrderMutationOptions(config: Partial, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useUploadFile.ts index 0265a8474..5f8e980ae 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/queryMethods/hooks/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useAddPet.ts index 91b9c0487..ee3cceef5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useAddPet.ts @@ -16,8 +16,7 @@ export function addPetMutationOptions(config: Partial, AddPetOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useDeletePet.ts index 45c8431e7..c2213c5f5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useDeletePet.ts @@ -16,8 +16,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useFindPetsByStatusSuspense.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useFindPetsByStatusSuspense.ts index ba215ddf8..1afcf7e82 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useFindPetsByStatusSuspense.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useFindPetsByStatusSuspense.ts @@ -18,8 +18,7 @@ export function findPetsByStatusSuspenseQueryOptions({ query }: FindPetsByStatus return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetInventory.ts index 429740790..5cb2467b1 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetInventorySuspense.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetInventorySuspense.ts index a30938079..73442315e 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetInventorySuspense.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetInventorySuspense.ts @@ -18,8 +18,7 @@ export function getInventorySuspenseQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetPetByIdSuspense.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetPetByIdSuspense.ts index 3e204f2f7..286049325 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetPetByIdSuspense.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useGetPetByIdSuspense.ts @@ -18,8 +18,7 @@ export function getPetByIdSuspenseQueryOptions({ path }: GetPetByIdOptions, conf return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/usePlaceOrder.ts index f8b691050..0d18d3336 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/usePlaceOrder.ts @@ -16,8 +16,7 @@ export function placeOrderMutationOptions(config: Partial, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useUploadFile.ts index 0265a8474..5f8e980ae 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/suspense/hooks/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useAddPet.ts index 91b9c0487..ee3cceef5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useAddPet.ts @@ -16,8 +16,7 @@ export function addPetMutationOptions(config: Partial, AddPetOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useDeletePet.ts index 45c8431e7..c2213c5f5 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useDeletePet.ts @@ -16,8 +16,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useFindPetsByStatus.ts index ac0b21f96..6d3757c4b 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useFindPetsByStatus.ts @@ -18,8 +18,7 @@ export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useGetInventory.ts index 429740790..5cb2467b1 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useGetInventory.ts @@ -18,8 +18,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useGetPetById.ts index a6b173e0c..e1c6a2c02 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useGetPetById.ts @@ -18,8 +18,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/usePlaceOrder.ts index f8b691050..0d18d3336 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/usePlaceOrder.ts @@ -16,8 +16,7 @@ export function placeOrderMutationOptions(config: Partial, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useUploadFile.ts index 0265a8474..5f8e980ae 100644 --- a/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginReactQuery/withClientPlugin/hooks/useUploadFile.ts @@ -16,8 +16,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useFindPetsByStatus.ts index 320f4ba0a..424d6e458 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useGetInventory.ts index 14780be27..d74713298 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useGetInventory.ts @@ -16,8 +16,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useGetPetById.ts index a9d8cb949..c88a12d2c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/usePlaceOrder.ts index 2d04c250a..f570f0cdf 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/usePlaceOrder.ts @@ -31,8 +31,7 @@ export function usePlaceOrder(options: { return useSWRMutation, PlaceOrderMutationKey | null, PlaceOrderMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useUploadFile.ts index 42a941cf6..6416e4644 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/excludeByOperationId/hooks/useUploadFile.ts @@ -30,8 +30,7 @@ export function useUploadFile(options: { return useSWRMutation, UploadFileMutationKey | null, UploadFileMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body } }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useAddPet.ts index b45c36e6e..62b4ab441 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useAddPet.ts @@ -31,8 +31,7 @@ export function useAddPet(options: { return useSWRMutation, AddPetMutationKey | null, AddPetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useDeletePet.ts index c01248d83..a0f17d1c8 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useDeletePet.ts @@ -31,8 +31,7 @@ export function useDeletePet(options: { return useSWRMutation, DeletePetMutationKey | null, DeletePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, headers } }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useFindPetsByStatus.ts index b0d641501..f03d65272 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useGetPetById.ts index 26e8827e8..7eedcafee 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useUploadFile.ts index 7a66dfaaa..b204314bc 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/pet/useUploadFile.ts @@ -30,8 +30,7 @@ export function useUploadFile(options: { return useSWRMutation, UploadFileMutationKey | null, UploadFileMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body } }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/store/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/store/useGetInventory.ts index 1c39cd64d..8c6db9b6d 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/store/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/store/useGetInventory.ts @@ -16,8 +16,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/store/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/store/usePlaceOrder.ts index 48ec6e6dd..f20b861b6 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/store/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/groupByTag/hooks/store/usePlaceOrder.ts @@ -31,8 +31,7 @@ export function usePlaceOrder(options: { return useSWRMutation, PlaceOrderMutationKey | null, PlaceOrderMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useAddPet.ts index 77a3f9e58..28a2a062b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useAddPet.ts @@ -31,8 +31,7 @@ export function useAddPet(options: { return useSWRMutation, AddPetMutationKey | null, AddPetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useDeletePet.ts index 217e93073..938795032 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useDeletePet.ts @@ -31,8 +31,7 @@ export function useDeletePet(options: { return useSWRMutation, DeletePetMutationKey | null, DeletePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, headers } }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useFindPetsByStatus.ts index 320f4ba0a..424d6e458 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useGetPetById.ts index a9d8cb949..c88a12d2c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useUploadFile.ts index 42a941cf6..6416e4644 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/includeByTag/hooks/useUploadFile.ts @@ -30,8 +30,7 @@ export function useUploadFile(options: { return useSWRMutation, UploadFileMutationKey | null, UploadFileMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body } }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useFindPetsByStatus.ts index 320f4ba0a..424d6e458 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useGetInventory.ts index 14780be27..d74713298 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useGetInventory.ts @@ -16,8 +16,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useGetPetById.ts index a9d8cb949..c88a12d2c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/mutationDisabled/hooks/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/hooks/useUpdatePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/hooks/useUpdatePet.ts index b99ed503d..f89424974 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/hooks/useUpdatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/paramsCasing/hooks/useUpdatePet.ts @@ -29,8 +29,7 @@ export function useUpdatePet(options: { return useSWRMutation, UpdatePetMutationKey | null, UpdatePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body, headers } }) => { - const { data } = await updatePet({ ...config, path, query, body, headers, throwOnError: true }) - return data + return updatePet({ ...config, path, query, body, headers, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useAddPet.ts index 77a3f9e58..28a2a062b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useAddPet.ts @@ -31,8 +31,7 @@ export function useAddPet(options: { return useSWRMutation, AddPetMutationKey | null, AddPetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useDeletePet.ts index 217e93073..938795032 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useDeletePet.ts @@ -31,8 +31,7 @@ export function useDeletePet(options: { return useSWRMutation, DeletePetMutationKey | null, DeletePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, headers } }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useFindPetsByStatus.ts index 320f4ba0a..424d6e458 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useGetInventory.ts index 14780be27..d74713298 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useGetInventory.ts @@ -16,8 +16,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useGetPetById.ts index a9d8cb949..c88a12d2c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/usePlaceOrder.ts index 2d04c250a..f570f0cdf 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/usePlaceOrder.ts @@ -31,8 +31,7 @@ export function usePlaceOrder(options: { return useSWRMutation, PlaceOrderMutationKey | null, PlaceOrderMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useUploadFile.ts index 42a941cf6..6416e4644 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/parserZod/hooks/useUploadFile.ts @@ -30,8 +30,7 @@ export function useUploadFile(options: { return useSWRMutation, UploadFileMutationKey | null, UploadFileMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body } }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useAddPet.ts index 77a3f9e58..28a2a062b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useAddPet.ts @@ -31,8 +31,7 @@ export function useAddPet(options: { return useSWRMutation, AddPetMutationKey | null, AddPetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useDeletePet.ts index 217e93073..938795032 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useDeletePet.ts @@ -31,8 +31,7 @@ export function useDeletePet(options: { return useSWRMutation, DeletePetMutationKey | null, DeletePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, headers } }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useFindPetsByStatus.ts index 320f4ba0a..424d6e458 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useGetInventory.ts index 14780be27..d74713298 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useGetInventory.ts @@ -16,8 +16,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useGetPetById.ts index a9d8cb949..c88a12d2c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/usePlaceOrder.ts index 2d04c250a..f570f0cdf 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/usePlaceOrder.ts @@ -31,8 +31,7 @@ export function usePlaceOrder(options: { return useSWRMutation, PlaceOrderMutationKey | null, PlaceOrderMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useUploadFile.ts index 42a941cf6..6416e4644 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/petStore/hooks/useUploadFile.ts @@ -30,8 +30,7 @@ export function useUploadFile(options: { return useSWRMutation, UploadFileMutationKey | null, UploadFileMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body } }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useAddPet.ts index 31b3e2db8..90d5686a8 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useAddPet.ts @@ -14,8 +14,7 @@ type AddPetQueryKey = ReturnType export function addPetQueryOptions({ body }: AddPetOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useDeletePet.ts index 431fdfb3e..a84130118 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useDeletePet.ts @@ -14,8 +14,7 @@ type DeletePetQueryKey = ReturnType export function deletePetQueryOptions({ path, headers }: DeletePetOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useFindPetsByStatus.ts index e655a88ab..c3bd9bea8 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useFindPetsByStatus.ts @@ -14,8 +14,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useGetInventory.ts index 639428a2c..0c20b9f1c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useGetInventory.ts @@ -13,8 +13,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useGetPetById.ts index fa07c0824..553feaa03 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useGetPetById.ts @@ -14,8 +14,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/usePlaceOrder.ts index dec4fbd40..58bd4a7a5 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/usePlaceOrder.ts @@ -14,8 +14,7 @@ type PlaceOrderQueryKey = ReturnType export function placeOrderQueryOptions({ body }: PlaceOrderOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useUploadFile.ts index 8a77ca0da..7e9d69c07 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryDisabled/hooks/useUploadFile.ts @@ -14,8 +14,7 @@ type UploadFileQueryKey = ReturnType export function uploadFileQueryOptions({ path, query, body }: UploadFileOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useAddPet.ts index 77a3f9e58..28a2a062b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useAddPet.ts @@ -31,8 +31,7 @@ export function useAddPet(options: { return useSWRMutation, AddPetMutationKey | null, AddPetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useDeletePet.ts index 217e93073..938795032 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useDeletePet.ts @@ -31,8 +31,7 @@ export function useDeletePet(options: { return useSWRMutation, DeletePetMutationKey | null, DeletePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, headers } }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useFindPetsByStatus.ts index 320f4ba0a..424d6e458 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useGetInventory.ts index 14780be27..d74713298 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useGetInventory.ts @@ -16,8 +16,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useGetPetById.ts index a9d8cb949..c88a12d2c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/usePlaceOrder.ts index 2d04c250a..f570f0cdf 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/usePlaceOrder.ts @@ -31,8 +31,7 @@ export function usePlaceOrder(options: { return useSWRMutation, PlaceOrderMutationKey | null, PlaceOrderMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useUploadFile.ts index 42a941cf6..6416e4644 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/queryMethods/hooks/useUploadFile.ts @@ -30,8 +30,7 @@ export function useUploadFile(options: { return useSWRMutation, UploadFileMutationKey | null, UploadFileMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body } }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useAddPet.ts index 77a3f9e58..28a2a062b 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useAddPet.ts @@ -31,8 +31,7 @@ export function useAddPet(options: { return useSWRMutation, AddPetMutationKey | null, AddPetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useDeletePet.ts index 217e93073..938795032 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useDeletePet.ts @@ -31,8 +31,7 @@ export function useDeletePet(options: { return useSWRMutation, DeletePetMutationKey | null, DeletePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, headers } }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useFindPetsByStatus.ts index 320f4ba0a..424d6e458 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ type FindPetsByStatusQueryKey = ReturnType export function findPetsByStatusQueryOptions({ query }: FindPetsByStatusOptions = {}, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useGetInventory.ts index 14780be27..d74713298 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useGetInventory.ts @@ -16,8 +16,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useGetPetById.ts index a9d8cb949..c88a12d2c 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/usePlaceOrder.ts index 2d04c250a..f570f0cdf 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/usePlaceOrder.ts @@ -31,8 +31,7 @@ export function usePlaceOrder(options: { return useSWRMutation, PlaceOrderMutationKey | null, PlaceOrderMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useUploadFile.ts index 42a941cf6..6416e4644 100644 --- a/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginSwr/withClientPlugin/hooks/useUploadFile.ts @@ -30,8 +30,7 @@ export function useUploadFile(options: { return useSWRMutation, UploadFileMutationKey | null, UploadFileMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body } }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, mutationOptions ) diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useFindPetsByStatus.ts index 974d33768..67556cf08 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions({ query }: { query?: MaybeRefOrGett return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useGetInventory.ts index 7c298abb6..e4f96502f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useGetInventory.ts @@ -19,8 +19,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useGetPetById.ts index 2a572420c..8be38a998 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useGetPetById.ts @@ -20,8 +20,7 @@ export function getPetByIdQueryOptions({ path }: { path: MaybeRefOrGetter, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/usePlaceOrder.ts index 20a10e050..2f55e6449 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/usePlaceOrder.ts @@ -27,8 +27,7 @@ export function usePlaceOrder(options: { return useMutation, PlaceOrderOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body: toValue(body), throwOnError: true }) - return data + return placeOrder({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useUploadFile.ts index 2a1ca04bc..7247e006e 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/excludeByOperationId/hooks/useUploadFile.ts @@ -26,8 +26,7 @@ export function useUploadFile(options: { return useMutation, UploadFileOptions, TContext>({ mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }) - return data + return uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useAddPet.ts index efc2477dc..403155f19 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useAddPet.ts @@ -27,8 +27,7 @@ export function useAddPet(options: { return useMutation, AddPetOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body: toValue(body), throwOnError: true }) - return data + return addPet({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useDeletePet.ts index 771a6a436..a7dc75325 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useDeletePet.ts @@ -27,8 +27,7 @@ export function useDeletePet(options: { return useMutation, DeletePetOptions, TContext>({ mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }) - return data + return deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useFindPetsByStatus.ts index 8b1f509e4..e407b5ff5 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions({ query }: { query?: MaybeRefOrGett return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useGetPetById.ts index eca6542f5..47dd62a37 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useGetPetById.ts @@ -20,8 +20,7 @@ export function getPetByIdQueryOptions({ path }: { path: MaybeRefOrGetter, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useUploadFile.ts index 33302d3fe..e7d7fd90d 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/pet/useUploadFile.ts @@ -26,8 +26,7 @@ export function useUploadFile(options: { return useMutation, UploadFileOptions, TContext>({ mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }) - return data + return uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/store/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/store/useGetInventory.ts index a95fd9d0c..765cb8645 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/store/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/store/useGetInventory.ts @@ -19,8 +19,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/store/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/store/usePlaceOrder.ts index 7851f6f61..7b41a6686 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/store/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/groupByTag/hooks/store/usePlaceOrder.ts @@ -27,8 +27,7 @@ export function usePlaceOrder(options: { return useMutation, PlaceOrderOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body: toValue(body), throwOnError: true }) - return data + return placeOrder({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useAddPet.ts index 60c495127..d009422eb 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useAddPet.ts @@ -27,8 +27,7 @@ export function useAddPet(options: { return useMutation, AddPetOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body: toValue(body), throwOnError: true }) - return data + return addPet({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useDeletePet.ts index e1cdd224e..2f8853419 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useDeletePet.ts @@ -27,8 +27,7 @@ export function useDeletePet(options: { return useMutation, DeletePetOptions, TContext>({ mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }) - return data + return deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useFindPetsByStatus.ts index 974d33768..67556cf08 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions({ query }: { query?: MaybeRefOrGett return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useGetPetById.ts index 2a572420c..8be38a998 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useGetPetById.ts @@ -20,8 +20,7 @@ export function getPetByIdQueryOptions({ path }: { path: MaybeRefOrGetter, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useUploadFile.ts index 2a1ca04bc..7247e006e 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/includeByTag/hooks/useUploadFile.ts @@ -26,8 +26,7 @@ export function useUploadFile(options: { return useMutation, UploadFileOptions, TContext>({ mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }) - return data + return uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useAddPet.ts index 60c495127..d009422eb 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useAddPet.ts @@ -27,8 +27,7 @@ export function useAddPet(options: { return useMutation, AddPetOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body: toValue(body), throwOnError: true }) - return data + return addPet({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useDeletePet.ts index e1cdd224e..2f8853419 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useDeletePet.ts @@ -27,8 +27,7 @@ export function useDeletePet(options: { return useMutation, DeletePetOptions, TContext>({ mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }) - return data + return deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useFindPetsByStatus.ts index 974d33768..67556cf08 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions({ query }: { query?: MaybeRefOrGett return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useGetInventory.ts index 7c298abb6..e4f96502f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useGetInventory.ts @@ -19,8 +19,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useGetPetById.ts index 2a572420c..8be38a998 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useGetPetById.ts @@ -20,8 +20,7 @@ export function getPetByIdQueryOptions({ path }: { path: MaybeRefOrGetter, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/usePlaceOrder.ts index 20a10e050..2f55e6449 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/usePlaceOrder.ts @@ -27,8 +27,7 @@ export function usePlaceOrder(options: { return useMutation, PlaceOrderOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body: toValue(body), throwOnError: true }) - return data + return placeOrder({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useUploadFile.ts index 2a1ca04bc..7247e006e 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/infinite/hooks/useUploadFile.ts @@ -26,8 +26,7 @@ export function useUploadFile(options: { return useMutation, UploadFileOptions, TContext>({ mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }) - return data + return uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useFindPetsByStatus.ts index 974d33768..67556cf08 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions({ query }: { query?: MaybeRefOrGett return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useGetInventory.ts index 7c298abb6..e4f96502f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useGetInventory.ts @@ -19,8 +19,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useGetPetById.ts index 2a572420c..8be38a998 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/mutationDisabled/hooks/useGetPetById.ts @@ -20,8 +20,7 @@ export function getPetByIdQueryOptions({ path }: { path: MaybeRefOrGetter, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/hooks/useUpdatePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/hooks/useUpdatePet.ts index 4e218c213..75d1d4aba 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/hooks/useUpdatePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/paramsCasing/hooks/useUpdatePet.ts @@ -25,8 +25,7 @@ export function useUpdatePet(options: { return useMutation, UpdatePetOptions, TContext>({ mutationFn: async({ path, query, body, headers }) => { - const { data } = await updatePet({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), headers: toValue(headers), throwOnError: true }) - return data + return updatePet({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), headers: toValue(headers), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useAddPet.ts index 60c495127..d009422eb 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useAddPet.ts @@ -27,8 +27,7 @@ export function useAddPet(options: { return useMutation, AddPetOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body: toValue(body), throwOnError: true }) - return data + return addPet({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useDeletePet.ts index e1cdd224e..2f8853419 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useDeletePet.ts @@ -27,8 +27,7 @@ export function useDeletePet(options: { return useMutation, DeletePetOptions, TContext>({ mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }) - return data + return deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useFindPetsByStatus.ts index 974d33768..67556cf08 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions({ query }: { query?: MaybeRefOrGett return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useGetInventory.ts index 7c298abb6..e4f96502f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useGetInventory.ts @@ -19,8 +19,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useGetPetById.ts index 2a572420c..8be38a998 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useGetPetById.ts @@ -20,8 +20,7 @@ export function getPetByIdQueryOptions({ path }: { path: MaybeRefOrGetter, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/usePlaceOrder.ts index 20a10e050..2f55e6449 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/usePlaceOrder.ts @@ -27,8 +27,7 @@ export function usePlaceOrder(options: { return useMutation, PlaceOrderOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body: toValue(body), throwOnError: true }) - return data + return placeOrder({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useUploadFile.ts index 2a1ca04bc..7247e006e 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/parserZod/hooks/useUploadFile.ts @@ -26,8 +26,7 @@ export function useUploadFile(options: { return useMutation, UploadFileOptions, TContext>({ mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }) - return data + return uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useAddPet.ts index 60c495127..d009422eb 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useAddPet.ts @@ -27,8 +27,7 @@ export function useAddPet(options: { return useMutation, AddPetOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body: toValue(body), throwOnError: true }) - return data + return addPet({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useDeletePet.ts index e1cdd224e..2f8853419 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useDeletePet.ts @@ -27,8 +27,7 @@ export function useDeletePet(options: { return useMutation, DeletePetOptions, TContext>({ mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }) - return data + return deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useFindPetsByStatus.ts index 974d33768..67556cf08 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions({ query }: { query?: MaybeRefOrGett return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useGetInventory.ts index 7c298abb6..e4f96502f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useGetInventory.ts @@ -19,8 +19,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useGetPetById.ts index 2a572420c..8be38a998 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useGetPetById.ts @@ -20,8 +20,7 @@ export function getPetByIdQueryOptions({ path }: { path: MaybeRefOrGetter, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/usePlaceOrder.ts index 20a10e050..2f55e6449 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/usePlaceOrder.ts @@ -27,8 +27,7 @@ export function usePlaceOrder(options: { return useMutation, PlaceOrderOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body: toValue(body), throwOnError: true }) - return data + return placeOrder({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useUploadFile.ts index 2a1ca04bc..7247e006e 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/petStore/hooks/useUploadFile.ts @@ -26,8 +26,7 @@ export function useUploadFile(options: { return useMutation, UploadFileOptions, TContext>({ mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }) - return data + return uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useAddPet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useAddPet.ts index 60c495127..d009422eb 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useAddPet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useAddPet.ts @@ -27,8 +27,7 @@ export function useAddPet(options: { return useMutation, AddPetOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await addPet({ ...config, body: toValue(body), throwOnError: true }) - return data + return addPet({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useDeletePet.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useDeletePet.ts index e1cdd224e..2f8853419 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useDeletePet.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useDeletePet.ts @@ -27,8 +27,7 @@ export function useDeletePet(options: { return useMutation, DeletePetOptions, TContext>({ mutationFn: async({ path, headers }) => { - const { data } = await deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }) - return data + return deletePet({ ...config, path: toValue(path), headers: toValue(headers), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useFindPetsByStatus.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useFindPetsByStatus.ts index 974d33768..67556cf08 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useFindPetsByStatus.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions({ query }: { query?: MaybeRefOrGett return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useGetInventory.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useGetInventory.ts index 7c298abb6..e4f96502f 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useGetInventory.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useGetInventory.ts @@ -19,8 +19,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useGetPetById.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useGetPetById.ts index 2a572420c..8be38a998 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useGetPetById.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useGetPetById.ts @@ -20,8 +20,7 @@ export function getPetByIdQueryOptions({ path }: { path: MaybeRefOrGetter, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/usePlaceOrder.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/usePlaceOrder.ts index 20a10e050..2f55e6449 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/usePlaceOrder.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/usePlaceOrder.ts @@ -27,8 +27,7 @@ export function usePlaceOrder(options: { return useMutation, PlaceOrderOptions, TContext>({ mutationFn: async({ body }) => { - const { data } = await placeOrder({ ...config, body: toValue(body), throwOnError: true }) - return data + return placeOrder({ ...config, body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions diff --git a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useUploadFile.ts b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useUploadFile.ts index 2a1ca04bc..7247e006e 100644 --- a/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useUploadFile.ts +++ b/tests/3.0.x/__snapshots__/pluginVueQuery/withClientPlugin/hooks/useUploadFile.ts @@ -26,8 +26,7 @@ export function useUploadFile(options: { return useMutation, UploadFileOptions, TContext>({ mutationFn: async({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }) - return data + return uploadFile({ ...config, path: toValue(path), query: toValue(query), body: toValue(body), throwOnError: true }).unwrap() }, mutationKey, ...mutationOptions From 5264b051de2642b4947c71be0922862e185ef188 Mon Sep 17 00:00:00 2001 From: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com> Date: Wed, 2 Sep 2026 17:51:29 +0000 Subject: [PATCH 9/9] chore(examples): update generated files --- .../src/gen/clients/hooks/pet/useAddFiles.ts | 3 +- .../src/gen/clients/hooks/pet/useAddPet.ts | 3 +- .../src/gen/clients/hooks/pet/useDeletePet.ts | 3 +- .../clients/hooks/pet/useFindPetsByStatus.ts | 3 +- .../clients/hooks/pet/useFindPetsByTags.ts | 3 +- .../hooks/pet/useFindPetsByTagsInfinite.ts | 3 +- .../gen/clients/hooks/pet/useGetPetById.ts | 3 +- .../src/gen/clients/hooks/pet/useUpdatePet.ts | 3 +- .../clients/hooks/pet/useUpdatePetWithForm.ts | 3 +- .../gen/clients/hooks/pet/useUploadFile.ts | 3 +- .../gen/clients/hooks/pets/useCreatePets.ts | 3 +- .../src/gen/hooks/pet/useAddPet.ts | 3 +- .../src/gen/hooks/pet/useDeletePet.ts | 3 +- .../src/gen/hooks/pet/useFindPetsByStatus.ts | 3 +- .../src/gen/hooks/pet/useFindPetsByTags.ts | 3 +- .../src/gen/hooks/pet/useGetPetById.ts | 3 +- .../src/gen/hooks/pet/useUpdatePet.ts | 3 +- .../src/gen/hooks/pet/useUpdatePetWithForm.ts | 3 +- .../src/gen/hooks/pet/useUploadFile.ts | 3 +- .../src/gen/hooks/store/useDeleteOrder.ts | 3 +- .../src/gen/hooks/store/useGetInventory.ts | 3 +- .../src/gen/hooks/store/useGetOrderById.ts | 3 +- .../src/gen/hooks/store/usePlaceOrder.ts | 3 +- .../src/gen/hooks/store/usePlaceOrderPatch.ts | 3 +- .../src/gen/hooks/user/useCreateUser.ts | 3 +- .../hooks/user/useCreateUsersWithListInput.ts | 3 +- .../src/gen/hooks/user/useDeleteUser.ts | 3 +- .../src/gen/hooks/user/useGetUserByName.ts | 3 +- .../src/gen/hooks/user/useLoginUser.ts | 3 +- .../src/gen/hooks/user/useLogoutUser.ts | 3 +- .../src/gen/hooks/user/useUpdateUser.ts | 3 +- examples/simple-single/src/gen/hooks.ts | 39 +++++++------------ examples/swr/src/gen/hooks/pet/useAddPet.ts | 3 +- .../swr/src/gen/hooks/pet/useDeletePet.ts | 3 +- .../src/gen/hooks/pet/useFindPetsByStatus.ts | 3 +- .../src/gen/hooks/pet/useFindPetsByTags.ts | 3 +- .../swr/src/gen/hooks/pet/useGetPetById.ts | 3 +- .../swr/src/gen/hooks/pet/useUpdatePet.ts | 3 +- .../src/gen/hooks/pet/useUpdatePetWithForm.ts | 3 +- .../swr/src/gen/hooks/pet/useUploadFile.ts | 3 +- .../swr/src/gen/hooks/store/useDeleteOrder.ts | 3 +- .../src/gen/hooks/store/useGetInventory.ts | 3 +- .../src/gen/hooks/store/useGetOrderById.ts | 3 +- .../swr/src/gen/hooks/store/usePlaceOrder.ts | 3 +- .../src/gen/hooks/store/usePlaceOrderPatch.ts | 3 +- .../swr/src/gen/hooks/user/useCreateUser.ts | 3 +- .../hooks/user/useCreateUsersWithListInput.ts | 3 +- .../swr/src/gen/hooks/user/useDeleteUser.ts | 3 +- .../src/gen/hooks/user/useGetUserByName.ts | 3 +- .../swr/src/gen/hooks/user/useLoginUser.ts | 3 +- .../swr/src/gen/hooks/user/useLogoutUser.ts | 3 +- .../swr/src/gen/hooks/user/useUpdateUser.ts | 3 +- .../src/gen/hooks/pet/useFindPetsByStatus.ts | 3 +- .../src/gen/hooks/pet/useFindPetsByTags.ts | 3 +- .../src/gen/hooks/pet/useGetPetById.ts | 3 +- .../src/gen/hooks/store/useGetInventory.ts | 3 +- .../src/gen/hooks/store/useGetOrderById.ts | 3 +- .../src/gen/hooks/user/useGetUserByName.ts | 3 +- .../src/gen/hooks/user/useLoginUser.ts | 3 +- .../src/gen/hooks/user/useLogoutUser.ts | 3 +- 60 files changed, 72 insertions(+), 144 deletions(-) diff --git a/examples/advanced/src/gen/clients/hooks/pet/useAddFiles.ts b/examples/advanced/src/gen/clients/hooks/pet/useAddFiles.ts index 03be6a659..6e28592d6 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useAddFiles.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useAddFiles.ts @@ -15,8 +15,7 @@ export function addFilesMutationOptions( return mutationOptions, AddFilesOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await addFiles({ ...config, body, throwOnError: true }) - return data + return addFiles({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pet/useAddPet.ts b/examples/advanced/src/gen/clients/hooks/pet/useAddPet.ts index 06af41b62..609a829de 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useAddPet.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useAddPet.ts @@ -15,8 +15,7 @@ export function addPetMutationOptions( return mutationOptions, AddPetOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pet/useDeletePet.ts b/examples/advanced/src/gen/clients/hooks/pet/useDeletePet.ts index a9134abe9..ce28e5dff 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useDeletePet.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useDeletePet.ts @@ -11,8 +11,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async ({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByStatus.ts b/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByStatus.ts index 27230b41d..9a5305bb5 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByStatus.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByStatus.ts @@ -16,8 +16,7 @@ export function findPetsByStatusQueryOptions( return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByTags.ts b/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByTags.ts index ddb821c8a..d9647cd1f 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByTags.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByTags.ts @@ -17,8 +17,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, headers, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, headers, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByTagsInfinite.ts b/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByTagsInfinite.ts index a6c8d658f..a02c086a9 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByTagsInfinite.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useFindPetsByTagsInfinite.ts @@ -27,8 +27,7 @@ export function findPetsByTagsInfiniteQueryOptions( ...(query ?? {}), ['pageSize']: pageParam as unknown as FindPetsByTagsQuery['pageSize'], } as FindPetsByTagsQuery - const { data } = await findPetsByTags({ ...config, query, headers, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, headers, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, initialPageParam: 0, getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1), diff --git a/examples/advanced/src/gen/clients/hooks/pet/useGetPetById.ts b/examples/advanced/src/gen/clients/hooks/pet/useGetPetById.ts index a09692ab7..4faef1da6 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useGetPetById.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useGetPetById.ts @@ -13,8 +13,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pet/useUpdatePet.ts b/examples/advanced/src/gen/clients/hooks/pet/useUpdatePet.ts index 0959cfd55..5adc62bc5 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useUpdatePet.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useUpdatePet.ts @@ -27,8 +27,7 @@ export function updatePetMutationOptions( >({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await updatePet({ ...config, body, throwOnError: true }) - return data + return updatePet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pet/useUpdatePetWithForm.ts b/examples/advanced/src/gen/clients/hooks/pet/useUpdatePetWithForm.ts index 698bdeea4..71e617646 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useUpdatePetWithForm.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useUpdatePetWithForm.ts @@ -11,8 +11,7 @@ export function updatePetWithFormMutationOptions(config: Par return mutationOptions, UpdatePetWithFormOptions, TContext>({ mutationKey, mutationFn: async ({ path, query }) => { - const { data } = await updatePetWithForm({ ...config, path, query, throwOnError: true }) - return data + return updatePetWithForm({ ...config, path, query, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pet/useUploadFile.ts b/examples/advanced/src/gen/clients/hooks/pet/useUploadFile.ts index 333c4935f..8e0775da7 100644 --- a/examples/advanced/src/gen/clients/hooks/pet/useUploadFile.ts +++ b/examples/advanced/src/gen/clients/hooks/pet/useUploadFile.ts @@ -11,8 +11,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async ({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/advanced/src/gen/clients/hooks/pets/useCreatePets.ts b/examples/advanced/src/gen/clients/hooks/pets/useCreatePets.ts index 73d3be8b5..975b7dd51 100644 --- a/examples/advanced/src/gen/clients/hooks/pets/useCreatePets.ts +++ b/examples/advanced/src/gen/clients/hooks/pets/useCreatePets.ts @@ -11,8 +11,7 @@ export function createPetsMutationOptions(config: Partial, CreatePetsOptions, TContext>({ mutationKey, mutationFn: async ({ path, query, body, headers }) => { - const { data } = await createPets({ ...config, path, query, body, headers, throwOnError: true }) - return data + return createPets({ ...config, path, query, body, headers, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/pet/useAddPet.ts b/examples/react-query/src/gen/hooks/pet/useAddPet.ts index af4402c13..a2b816526 100644 --- a/examples/react-query/src/gen/hooks/pet/useAddPet.ts +++ b/examples/react-query/src/gen/hooks/pet/useAddPet.ts @@ -19,8 +19,7 @@ export function addPetMutationOptions( return mutationOptions, AddPetOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/pet/useDeletePet.ts b/examples/react-query/src/gen/hooks/pet/useDeletePet.ts index 5db82fc0c..02cbf2896 100644 --- a/examples/react-query/src/gen/hooks/pet/useDeletePet.ts +++ b/examples/react-query/src/gen/hooks/pet/useDeletePet.ts @@ -15,8 +15,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async ({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/pet/useFindPetsByStatus.ts b/examples/react-query/src/gen/hooks/pet/useFindPetsByStatus.ts index 629d08f9b..eced35d23 100644 --- a/examples/react-query/src/gen/hooks/pet/useFindPetsByStatus.ts +++ b/examples/react-query/src/gen/hooks/pet/useFindPetsByStatus.ts @@ -21,8 +21,7 @@ export function findPetsByStatusQueryOptions( return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/pet/useFindPetsByTags.ts b/examples/react-query/src/gen/hooks/pet/useFindPetsByTags.ts index a366e1dd7..9c673f0f2 100644 --- a/examples/react-query/src/gen/hooks/pet/useFindPetsByTags.ts +++ b/examples/react-query/src/gen/hooks/pet/useFindPetsByTags.ts @@ -21,8 +21,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/pet/useGetPetById.ts b/examples/react-query/src/gen/hooks/pet/useGetPetById.ts index 004c4425a..4222a610a 100644 --- a/examples/react-query/src/gen/hooks/pet/useGetPetById.ts +++ b/examples/react-query/src/gen/hooks/pet/useGetPetById.ts @@ -17,8 +17,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/pet/useUpdatePet.ts b/examples/react-query/src/gen/hooks/pet/useUpdatePet.ts index 3267d0aa8..447099311 100644 --- a/examples/react-query/src/gen/hooks/pet/useUpdatePet.ts +++ b/examples/react-query/src/gen/hooks/pet/useUpdatePet.ts @@ -19,8 +19,7 @@ export function updatePetMutationOptions( return mutationOptions, UpdatePetOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await updatePet({ ...config, body, throwOnError: true }) - return data + return updatePet({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/pet/useUpdatePetWithForm.ts b/examples/react-query/src/gen/hooks/pet/useUpdatePetWithForm.ts index f81714f05..20544e301 100644 --- a/examples/react-query/src/gen/hooks/pet/useUpdatePetWithForm.ts +++ b/examples/react-query/src/gen/hooks/pet/useUpdatePetWithForm.ts @@ -15,8 +15,7 @@ export function updatePetWithFormMutationOptions(config: Par return mutationOptions, UpdatePetWithFormOptions, TContext>({ mutationKey, mutationFn: async ({ path, query }) => { - const { data } = await updatePetWithForm({ ...config, path, query, throwOnError: true }) - return data + return updatePetWithForm({ ...config, path, query, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/pet/useUploadFile.ts b/examples/react-query/src/gen/hooks/pet/useUploadFile.ts index 60336c24d..5e3954d6d 100644 --- a/examples/react-query/src/gen/hooks/pet/useUploadFile.ts +++ b/examples/react-query/src/gen/hooks/pet/useUploadFile.ts @@ -19,8 +19,7 @@ export function uploadFileMutationOptions( return mutationOptions, UploadFileOptions, TContext>({ mutationKey, mutationFn: async ({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/store/useDeleteOrder.ts b/examples/react-query/src/gen/hooks/store/useDeleteOrder.ts index 4904a0fd4..7b58916d5 100644 --- a/examples/react-query/src/gen/hooks/store/useDeleteOrder.ts +++ b/examples/react-query/src/gen/hooks/store/useDeleteOrder.ts @@ -15,8 +15,7 @@ export function deleteOrderMutationOptions(config: Partial, DeleteOrderOptions, TContext>({ mutationKey, mutationFn: async ({ path }) => { - const { data } = await deleteOrder({ ...config, path, throwOnError: true }) - return data + return deleteOrder({ ...config, path, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/store/useGetInventory.ts b/examples/react-query/src/gen/hooks/store/useGetInventory.ts index 88bd01d8b..83f2662d7 100644 --- a/examples/react-query/src/gen/hooks/store/useGetInventory.ts +++ b/examples/react-query/src/gen/hooks/store/useGetInventory.ts @@ -17,8 +17,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/store/useGetOrderById.ts b/examples/react-query/src/gen/hooks/store/useGetOrderById.ts index a072a17b0..edf5a1b0e 100644 --- a/examples/react-query/src/gen/hooks/store/useGetOrderById.ts +++ b/examples/react-query/src/gen/hooks/store/useGetOrderById.ts @@ -20,8 +20,7 @@ export function getOrderByIdQueryOptions( return queryOptions, GetOrderByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getOrderById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getOrderById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/store/usePlaceOrder.ts b/examples/react-query/src/gen/hooks/store/usePlaceOrder.ts index 492735b23..cb932e02a 100644 --- a/examples/react-query/src/gen/hooks/store/usePlaceOrder.ts +++ b/examples/react-query/src/gen/hooks/store/usePlaceOrder.ts @@ -19,8 +19,7 @@ export function placeOrderMutationOptions( return mutationOptions, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/store/usePlaceOrderPatch.ts b/examples/react-query/src/gen/hooks/store/usePlaceOrderPatch.ts index 89c5537d4..2233745a9 100644 --- a/examples/react-query/src/gen/hooks/store/usePlaceOrderPatch.ts +++ b/examples/react-query/src/gen/hooks/store/usePlaceOrderPatch.ts @@ -19,8 +19,7 @@ export function placeOrderPatchMutationOptions( return mutationOptions, PlaceOrderPatchOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await placeOrderPatch({ ...config, body, throwOnError: true }) - return data + return placeOrderPatch({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/user/useCreateUser.ts b/examples/react-query/src/gen/hooks/user/useCreateUser.ts index 285e155b6..890f54c41 100644 --- a/examples/react-query/src/gen/hooks/user/useCreateUser.ts +++ b/examples/react-query/src/gen/hooks/user/useCreateUser.ts @@ -19,8 +19,7 @@ export function createUserMutationOptions( return mutationOptions, CreateUserOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await createUser({ ...config, body, throwOnError: true }) - return data + return createUser({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/user/useCreateUsersWithListInput.ts b/examples/react-query/src/gen/hooks/user/useCreateUsersWithListInput.ts index 658ea650c..810081dd9 100644 --- a/examples/react-query/src/gen/hooks/user/useCreateUsersWithListInput.ts +++ b/examples/react-query/src/gen/hooks/user/useCreateUsersWithListInput.ts @@ -19,8 +19,7 @@ export function createUsersWithListInputMutationOptions( return mutationOptions, CreateUsersWithListInputOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await createUsersWithListInput({ ...config, body, throwOnError: true }) - return data + return createUsersWithListInput({ ...config, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/user/useDeleteUser.ts b/examples/react-query/src/gen/hooks/user/useDeleteUser.ts index 5f4adbb3e..b62d5f4fb 100644 --- a/examples/react-query/src/gen/hooks/user/useDeleteUser.ts +++ b/examples/react-query/src/gen/hooks/user/useDeleteUser.ts @@ -15,8 +15,7 @@ export function deleteUserMutationOptions(config: Partial, DeleteUserOptions, TContext>({ mutationKey, mutationFn: async ({ path }) => { - const { data } = await deleteUser({ ...config, path, throwOnError: true }) - return data + return deleteUser({ ...config, path, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/user/useGetUserByName.ts b/examples/react-query/src/gen/hooks/user/useGetUserByName.ts index 5fe7e2519..34cb4e8c7 100644 --- a/examples/react-query/src/gen/hooks/user/useGetUserByName.ts +++ b/examples/react-query/src/gen/hooks/user/useGetUserByName.ts @@ -20,8 +20,7 @@ export function getUserByNameQueryOptions( return queryOptions, GetUserByNameStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getUserByName({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getUserByName({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/user/useLoginUser.ts b/examples/react-query/src/gen/hooks/user/useLoginUser.ts index 3f768f767..58a158b8a 100644 --- a/examples/react-query/src/gen/hooks/user/useLoginUser.ts +++ b/examples/react-query/src/gen/hooks/user/useLoginUser.ts @@ -20,8 +20,7 @@ export function loginUserQueryOptions( return queryOptions, LoginUserStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await loginUser({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return loginUser({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/user/useLogoutUser.ts b/examples/react-query/src/gen/hooks/user/useLogoutUser.ts index 7e1864082..82025e315 100644 --- a/examples/react-query/src/gen/hooks/user/useLogoutUser.ts +++ b/examples/react-query/src/gen/hooks/user/useLogoutUser.ts @@ -17,8 +17,7 @@ export function logoutUserQueryOptions(config: Partial, LogoutUserResponse, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await logoutUser({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return logoutUser({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/react-query/src/gen/hooks/user/useUpdateUser.ts b/examples/react-query/src/gen/hooks/user/useUpdateUser.ts index 10f3952c4..846de211b 100644 --- a/examples/react-query/src/gen/hooks/user/useUpdateUser.ts +++ b/examples/react-query/src/gen/hooks/user/useUpdateUser.ts @@ -19,8 +19,7 @@ export function updateUserMutationOptions( return mutationOptions, UpdateUserOptions, TContext>({ mutationKey, mutationFn: async ({ path, body }) => { - const { data } = await updateUser({ ...config, path, body, throwOnError: true }) - return data + return updateUser({ ...config, path, body, throwOnError: true }).unwrap() }, }) } diff --git a/examples/simple-single/src/gen/hooks.ts b/examples/simple-single/src/gen/hooks.ts index a578ea6b3..a6014217d 100644 --- a/examples/simple-single/src/gen/hooks.ts +++ b/examples/simple-single/src/gen/hooks.ts @@ -73,8 +73,7 @@ export function updatePetMutationOptions( return mutationOptions, UpdatePetOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await updatePet({ ...config, body, throwOnError: true }) - return data + return updatePet({ ...config, body, throwOnError: true }).unwrap() }, }) } @@ -90,8 +89,7 @@ export function addPetMutationOptions( return mutationOptions, AddPetOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, }) } @@ -109,8 +107,7 @@ export function findPetsByStatusQueryOptions( return queryOptions, FindPetsByStatusStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } @@ -128,8 +125,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } @@ -143,8 +139,7 @@ export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Part return queryOptions, GetPetByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } @@ -156,8 +151,7 @@ export function updatePetWithFormMutationOptions(config: Par return mutationOptions, UpdatePetWithFormOptions, TContext>({ mutationKey, mutationFn: async ({ path, query }) => { - const { data } = await updatePetWithForm({ ...config, path, query, throwOnError: true }) - return data + return updatePetWithForm({ ...config, path, query, throwOnError: true }).unwrap() }, }) } @@ -169,8 +163,7 @@ export function deletePetMutationOptions(config: Partial, DeletePetOptions, TContext>({ mutationKey, mutationFn: async ({ path, headers }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, }) } @@ -182,8 +175,7 @@ export function uploadFileMutationOptions(config: Partial, UploadFileOptions, TContext>({ mutationKey, mutationFn: async ({ path, query, body }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, }) } @@ -197,8 +189,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } @@ -214,8 +205,7 @@ export function placeOrderMutationOptions( return mutationOptions, PlaceOrderOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, }) } @@ -231,8 +221,7 @@ export function placeOrderPatchMutationOptions( return mutationOptions, PlaceOrderPatchOptions, TContext>({ mutationKey, mutationFn: async ({ body }) => { - const { data } = await placeOrderPatch({ ...config, body, throwOnError: true }) - return data + return placeOrderPatch({ ...config, body, throwOnError: true }).unwrap() }, }) } @@ -249,8 +238,7 @@ export function getOrderByIdQueryOptions( return queryOptions, GetOrderByIdStatus200, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getOrderById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }) - return data + return getOrderById({ ...config, path, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } @@ -262,8 +250,7 @@ export function deleteOrderMutationOptions(config: Partial, DeleteOrderOptions, TContext>({ mutationKey, mutationFn: async ({ path }) => { - const { data } = await deleteOrder({ ...config, path, throwOnError: true }) - return data + return deleteOrder({ ...config, path, throwOnError: true }).unwrap() }, }) } diff --git a/examples/swr/src/gen/hooks/pet/useAddPet.ts b/examples/swr/src/gen/hooks/pet/useAddPet.ts index 0e402317d..9c9f294c5 100644 --- a/examples/swr/src/gen/hooks/pet/useAddPet.ts +++ b/examples/swr/src/gen/hooks/pet/useAddPet.ts @@ -40,8 +40,7 @@ export function useAddPet( return useSWRMutation, AddPetMutationKey | null, AddPetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await addPet({ ...config, body, throwOnError: true }) - return data + return addPet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/pet/useDeletePet.ts b/examples/swr/src/gen/hooks/pet/useDeletePet.ts index 41a271de5..4064d803e 100644 --- a/examples/swr/src/gen/hooks/pet/useDeletePet.ts +++ b/examples/swr/src/gen/hooks/pet/useDeletePet.ts @@ -35,8 +35,7 @@ export function useDeletePet( return useSWRMutation, DeletePetMutationKey | null, DeletePetMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, headers } }) => { - const { data } = await deletePet({ ...config, path, headers, throwOnError: true }) - return data + return deletePet({ ...config, path, headers, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/pet/useFindPetsByStatus.ts b/examples/swr/src/gen/hooks/pet/useFindPetsByStatus.ts index c6e3785c6..ef1ad60f5 100644 --- a/examples/swr/src/gen/hooks/pet/useFindPetsByStatus.ts +++ b/examples/swr/src/gen/hooks/pet/useFindPetsByStatus.ts @@ -20,8 +20,7 @@ export function findPetsByStatusQueryOptions( ) { return { fetcher: async () => { - const { data } = await findPetsByStatus({ ...config, query, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/examples/swr/src/gen/hooks/pet/useFindPetsByTags.ts b/examples/swr/src/gen/hooks/pet/useFindPetsByTags.ts index 40a873e9e..79d5336f3 100644 --- a/examples/swr/src/gen/hooks/pet/useFindPetsByTags.ts +++ b/examples/swr/src/gen/hooks/pet/useFindPetsByTags.ts @@ -20,8 +20,7 @@ export function findPetsByTagsQueryOptions( ) { return { fetcher: async () => { - const { data } = await findPetsByTags({ ...config, query, throwOnError: true }) - return data + return findPetsByTags({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/examples/swr/src/gen/hooks/pet/useGetPetById.ts b/examples/swr/src/gen/hooks/pet/useGetPetById.ts index b971a1208..d5705fea2 100644 --- a/examples/swr/src/gen/hooks/pet/useGetPetById.ts +++ b/examples/swr/src/gen/hooks/pet/useGetPetById.ts @@ -16,8 +16,7 @@ type GetPetByIdQueryKey = ReturnType export function getPetByIdQueryOptions({ path }: GetPetByIdOptions, config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getPetById({ ...config, path, throwOnError: true }) - return data + return getPetById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/examples/swr/src/gen/hooks/pet/useUpdatePet.ts b/examples/swr/src/gen/hooks/pet/useUpdatePet.ts index b83bc286d..71e0877c2 100644 --- a/examples/swr/src/gen/hooks/pet/useUpdatePet.ts +++ b/examples/swr/src/gen/hooks/pet/useUpdatePet.ts @@ -48,8 +48,7 @@ export function useUpdatePet( >( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await updatePet({ ...config, body, throwOnError: true }) - return data + return updatePet({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/pet/useUpdatePetWithForm.ts b/examples/swr/src/gen/hooks/pet/useUpdatePetWithForm.ts index 0f9788bd7..728876e8f 100644 --- a/examples/swr/src/gen/hooks/pet/useUpdatePetWithForm.ts +++ b/examples/swr/src/gen/hooks/pet/useUpdatePetWithForm.ts @@ -42,8 +42,7 @@ export function useUpdatePetWithForm( >( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query } }) => { - const { data } = await updatePetWithForm({ ...config, path, query, throwOnError: true }) - return data + return updatePetWithForm({ ...config, path, query, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/pet/useUploadFile.ts b/examples/swr/src/gen/hooks/pet/useUploadFile.ts index c010a2ba4..486ba6bee 100644 --- a/examples/swr/src/gen/hooks/pet/useUploadFile.ts +++ b/examples/swr/src/gen/hooks/pet/useUploadFile.ts @@ -36,8 +36,7 @@ export function useUploadFile( return useSWRMutation, UploadFileMutationKey | null, UploadFileMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, query, body } }) => { - const { data } = await uploadFile({ ...config, path, query, body, throwOnError: true }) - return data + return uploadFile({ ...config, path, query, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/store/useDeleteOrder.ts b/examples/swr/src/gen/hooks/store/useDeleteOrder.ts index 3ec482754..3fc379f17 100644 --- a/examples/swr/src/gen/hooks/store/useDeleteOrder.ts +++ b/examples/swr/src/gen/hooks/store/useDeleteOrder.ts @@ -43,8 +43,7 @@ export function useDeleteOrder( >( shouldFetch ? mutationKey : null, async (_url, { arg: { path } }) => { - const { data } = await deleteOrder({ ...config, path, throwOnError: true }) - return data + return deleteOrder({ ...config, path, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/store/useGetInventory.ts b/examples/swr/src/gen/hooks/store/useGetInventory.ts index 81300c3d9..0fff1e558 100644 --- a/examples/swr/src/gen/hooks/store/useGetInventory.ts +++ b/examples/swr/src/gen/hooks/store/useGetInventory.ts @@ -16,8 +16,7 @@ type GetInventoryQueryKey = ReturnType export function getInventoryQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await getInventory({ ...config, throwOnError: true }) - return data + return getInventory({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/examples/swr/src/gen/hooks/store/useGetOrderById.ts b/examples/swr/src/gen/hooks/store/useGetOrderById.ts index 279f39a0a..99027099c 100644 --- a/examples/swr/src/gen/hooks/store/useGetOrderById.ts +++ b/examples/swr/src/gen/hooks/store/useGetOrderById.ts @@ -19,8 +19,7 @@ export function getOrderByIdQueryOptions( ) { return { fetcher: async () => { - const { data } = await getOrderById({ ...config, path, throwOnError: true }) - return data + return getOrderById({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/examples/swr/src/gen/hooks/store/usePlaceOrder.ts b/examples/swr/src/gen/hooks/store/usePlaceOrder.ts index 2f905d982..4d92f527d 100644 --- a/examples/swr/src/gen/hooks/store/usePlaceOrder.ts +++ b/examples/swr/src/gen/hooks/store/usePlaceOrder.ts @@ -37,8 +37,7 @@ export function usePlaceOrder( return useSWRMutation, PlaceOrderMutationKey | null, PlaceOrderMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await placeOrder({ ...config, body, throwOnError: true }) - return data + return placeOrder({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/store/usePlaceOrderPatch.ts b/examples/swr/src/gen/hooks/store/usePlaceOrderPatch.ts index d1ec839d1..66b27b012 100644 --- a/examples/swr/src/gen/hooks/store/usePlaceOrderPatch.ts +++ b/examples/swr/src/gen/hooks/store/usePlaceOrderPatch.ts @@ -40,8 +40,7 @@ export function usePlaceOrderPatch( return useSWRMutation, PlaceOrderPatchMutationKey | null, PlaceOrderPatchMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await placeOrderPatch({ ...config, body, throwOnError: true }) - return data + return placeOrderPatch({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/user/useCreateUser.ts b/examples/swr/src/gen/hooks/user/useCreateUser.ts index a1fce9bca..2f35dd7d4 100644 --- a/examples/swr/src/gen/hooks/user/useCreateUser.ts +++ b/examples/swr/src/gen/hooks/user/useCreateUser.ts @@ -37,8 +37,7 @@ export function useCreateUser( return useSWRMutation, CreateUserMutationKey | null, CreateUserMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await createUser({ ...config, body, throwOnError: true }) - return data + return createUser({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/user/useCreateUsersWithListInput.ts b/examples/swr/src/gen/hooks/user/useCreateUsersWithListInput.ts index cb359cb5a..ccacf7356 100644 --- a/examples/swr/src/gen/hooks/user/useCreateUsersWithListInput.ts +++ b/examples/swr/src/gen/hooks/user/useCreateUsersWithListInput.ts @@ -45,8 +45,7 @@ export function useCreateUsersWithListInput( >( shouldFetch ? mutationKey : null, async (_url, { arg: { body } }) => { - const { data } = await createUsersWithListInput({ ...config, body, throwOnError: true }) - return data + return createUsersWithListInput({ ...config, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/user/useDeleteUser.ts b/examples/swr/src/gen/hooks/user/useDeleteUser.ts index a6a3b99f6..5b25f7ed7 100644 --- a/examples/swr/src/gen/hooks/user/useDeleteUser.ts +++ b/examples/swr/src/gen/hooks/user/useDeleteUser.ts @@ -43,8 +43,7 @@ export function useDeleteUser( >( shouldFetch ? mutationKey : null, async (_url, { arg: { path } }) => { - const { data } = await deleteUser({ ...config, path, throwOnError: true }) - return data + return deleteUser({ ...config, path, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/swr/src/gen/hooks/user/useGetUserByName.ts b/examples/swr/src/gen/hooks/user/useGetUserByName.ts index fbb641a5f..805295dcc 100644 --- a/examples/swr/src/gen/hooks/user/useGetUserByName.ts +++ b/examples/swr/src/gen/hooks/user/useGetUserByName.ts @@ -19,8 +19,7 @@ export function getUserByNameQueryOptions( ) { return { fetcher: async () => { - const { data } = await getUserByName({ ...config, path, throwOnError: true }) - return data + return getUserByName({ ...config, path, throwOnError: true }).unwrap() }, } } diff --git a/examples/swr/src/gen/hooks/user/useLoginUser.ts b/examples/swr/src/gen/hooks/user/useLoginUser.ts index 4757ac8f9..94f94ccec 100644 --- a/examples/swr/src/gen/hooks/user/useLoginUser.ts +++ b/examples/swr/src/gen/hooks/user/useLoginUser.ts @@ -19,8 +19,7 @@ export function loginUserQueryOptions( ) { return { fetcher: async () => { - const { data } = await loginUser({ ...config, query, throwOnError: true }) - return data + return loginUser({ ...config, query, throwOnError: true }).unwrap() }, } } diff --git a/examples/swr/src/gen/hooks/user/useLogoutUser.ts b/examples/swr/src/gen/hooks/user/useLogoutUser.ts index 204cfcf80..4dfdb8a19 100644 --- a/examples/swr/src/gen/hooks/user/useLogoutUser.ts +++ b/examples/swr/src/gen/hooks/user/useLogoutUser.ts @@ -16,8 +16,7 @@ type LogoutUserQueryKey = ReturnType export function logoutUserQueryOptions(config: Partial> = {}) { return { fetcher: async () => { - const { data } = await logoutUser({ ...config, throwOnError: true }) - return data + return logoutUser({ ...config, throwOnError: true }).unwrap() }, } } diff --git a/examples/swr/src/gen/hooks/user/useUpdateUser.ts b/examples/swr/src/gen/hooks/user/useUpdateUser.ts index 855106e13..bc956a546 100644 --- a/examples/swr/src/gen/hooks/user/useUpdateUser.ts +++ b/examples/swr/src/gen/hooks/user/useUpdateUser.ts @@ -37,8 +37,7 @@ export function useUpdateUser( return useSWRMutation, UpdateUserMutationKey | null, UpdateUserMutationArg>( shouldFetch ? mutationKey : null, async (_url, { arg: { path, body } }) => { - const { data } = await updateUser({ ...config, path, body, throwOnError: true }) - return data + return updateUser({ ...config, path, body, throwOnError: true }).unwrap() }, mutationOptions, ) diff --git a/examples/vue-query/src/gen/hooks/pet/useFindPetsByStatus.ts b/examples/vue-query/src/gen/hooks/pet/useFindPetsByStatus.ts index 7f1ca2ffc..5092df3bf 100644 --- a/examples/vue-query/src/gen/hooks/pet/useFindPetsByStatus.ts +++ b/examples/vue-query/src/gen/hooks/pet/useFindPetsByStatus.ts @@ -23,8 +23,7 @@ export function findPetsByStatusQueryOptions( return queryOptions, FindPetsByStatusStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByStatus({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/vue-query/src/gen/hooks/pet/useFindPetsByTags.ts b/examples/vue-query/src/gen/hooks/pet/useFindPetsByTags.ts index 5666fd3a3..c722cd609 100644 --- a/examples/vue-query/src/gen/hooks/pet/useFindPetsByTags.ts +++ b/examples/vue-query/src/gen/hooks/pet/useFindPetsByTags.ts @@ -23,8 +23,7 @@ export function findPetsByTagsQueryOptions( return queryOptions, FindPetsByTagsStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return findPetsByTags({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/vue-query/src/gen/hooks/pet/useGetPetById.ts b/examples/vue-query/src/gen/hooks/pet/useGetPetById.ts index a0f20c238..fa4011c9f 100644 --- a/examples/vue-query/src/gen/hooks/pet/useGetPetById.ts +++ b/examples/vue-query/src/gen/hooks/pet/useGetPetById.ts @@ -23,8 +23,7 @@ export function getPetByIdQueryOptions( return queryOptions, GetPetByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getPetById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/vue-query/src/gen/hooks/store/useGetInventory.ts b/examples/vue-query/src/gen/hooks/store/useGetInventory.ts index 7c84ec2cc..a7105fafa 100644 --- a/examples/vue-query/src/gen/hooks/store/useGetInventory.ts +++ b/examples/vue-query/src/gen/hooks/store/useGetInventory.ts @@ -17,8 +17,7 @@ export function getInventoryQueryOptions(config: Partial, GetInventoryStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return getInventory({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/vue-query/src/gen/hooks/store/useGetOrderById.ts b/examples/vue-query/src/gen/hooks/store/useGetOrderById.ts index 483acb8ab..01e22d71b 100644 --- a/examples/vue-query/src/gen/hooks/store/useGetOrderById.ts +++ b/examples/vue-query/src/gen/hooks/store/useGetOrderById.ts @@ -23,8 +23,7 @@ export function getOrderByIdQueryOptions( return queryOptions, GetOrderByIdStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getOrderById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getOrderById({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/vue-query/src/gen/hooks/user/useGetUserByName.ts b/examples/vue-query/src/gen/hooks/user/useGetUserByName.ts index 76ce1373c..63f4df212 100644 --- a/examples/vue-query/src/gen/hooks/user/useGetUserByName.ts +++ b/examples/vue-query/src/gen/hooks/user/useGetUserByName.ts @@ -23,8 +23,7 @@ export function getUserByNameQueryOptions( return queryOptions, GetUserByNameStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await getUserByName({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }) - return data + return getUserByName({ ...config, path: toValue(path), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/vue-query/src/gen/hooks/user/useLoginUser.ts b/examples/vue-query/src/gen/hooks/user/useLoginUser.ts index c7ca46264..8c036e36e 100644 --- a/examples/vue-query/src/gen/hooks/user/useLoginUser.ts +++ b/examples/vue-query/src/gen/hooks/user/useLoginUser.ts @@ -23,8 +23,7 @@ export function loginUserQueryOptions( return queryOptions, LoginUserStatus200>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await loginUser({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }) - return data + return loginUser({ ...config, query: toValue(query), signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) } diff --git a/examples/vue-query/src/gen/hooks/user/useLogoutUser.ts b/examples/vue-query/src/gen/hooks/user/useLogoutUser.ts index 2783a0036..d5cb23843 100644 --- a/examples/vue-query/src/gen/hooks/user/useLogoutUser.ts +++ b/examples/vue-query/src/gen/hooks/user/useLogoutUser.ts @@ -17,8 +17,7 @@ export function logoutUserQueryOptions(config: Partial, LogoutUserResponse>({ queryKey, queryFn: async ({ signal }) => { - const { data } = await logoutUser({ ...config, signal: config.signal ?? signal, throwOnError: true }) - return data + return logoutUser({ ...config, signal: config.signal ?? signal, throwOnError: true }).unwrap() }, }) }