From 307ff98be471b04a579494f8a95184a9e4091f71 Mon Sep 17 00:00:00 2001 From: Jorrin Date: Sat, 28 Mar 2026 01:49:35 +0100 Subject: [PATCH 1/8] feat: make tanstack query respect responseStyle --- .../@tanstack/meta/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../2.0.x/form-data/client/client.gen.ts | 6 + .../common/default-class/client/client.gen.ts | 6 + .../common/default/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../sdk-nested-classes/client/client.gen.ts | 6 + .../@hey-api/sdk/default/client/client.gen.ts | 6 + .../sdk/instance/client/client.gen.ts | 6 + .../sdk/throwOnError/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../colada/asClass/client/client.gen.ts | 6 + .../@pinia/colada/fetch/client/client.gen.ts | 6 + .../asClass/client/client.gen.ts | 6 + .../fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../preact-query/asClass/client/client.gen.ts | 6 + .../preact-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../react-query/asClass/client/client.gen.ts | 6 + .../react-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../@tanstack/react-query.gen.ts | 645 +++++ .../react-query/responseStyle/client.gen.ts | 16 + .../responseStyle/client/client.gen.ts | 296 +++ .../react-query/responseStyle/client/index.ts | 25 + .../responseStyle/client/types.gen.ts | 214 ++ .../responseStyle/client/utils.gen.ts | 316 +++ .../responseStyle/core/auth.gen.ts | 41 + .../responseStyle/core/bodySerializer.gen.ts | 82 + .../responseStyle/core/params.gen.ts | 169 ++ .../responseStyle/core/pathSerializer.gen.ts | 171 ++ .../core/queryKeySerializer.gen.ts | 117 + .../core/serverSentEvents.gen.ts | 243 ++ .../responseStyle/core/types.gen.ts | 104 + .../responseStyle/core/utils.gen.ts | 140 ++ .../react-query/responseStyle/index.ts | 4 + .../react-query/responseStyle/sdk.gen.ts | 127 + .../react-query/responseStyle/types.gen.ts | 1190 ++++++++++ .../useMutation/client/client.gen.ts | 6 + .../solid-query/asClass/client/client.gen.ts | 6 + .../solid-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../svelte-query/asClass/client/client.gen.ts | 6 + .../svelte-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../vue-query/asClass/client/client.gen.ts | 6 + .../vue-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../2.0.x/schema-unknown/client/client.gen.ts | 6 + .../security-api-key/client/client.gen.ts | 6 + .../2.0.x/security-basic/client/client.gen.ts | 6 + .../2.0.x/security-false/client/client.gen.ts | 6 + .../security-oauth2/client/client.gen.ts | 6 + .../servers-base-path/client/client.gen.ts | 6 + .../2.0.x/servers-host/client/client.gen.ts | 6 + .../2.0.x/servers/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../body-binary-format/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../common/default-class/client/client.gen.ts | 6 + .../common/default/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../sdk-nested-classes/client/client.gen.ts | 6 + .../@hey-api/sdk/default/client/client.gen.ts | 6 + .../sdk/instance/client/client.gen.ts | 6 + .../sdk/throwOnError/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../colada/asClass/client/client.gen.ts | 6 + .../@pinia/colada/fetch/client/client.gen.ts | 6 + .../asClass/client/client.gen.ts | 6 + .../fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../preact-query/asClass/client/client.gen.ts | 6 + .../preact-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../react-query/asClass/client/client.gen.ts | 6 + .../react-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../@tanstack/react-query.gen.ts | 960 ++++++++ .../react-query/responseStyle/client.gen.ts | 16 + .../responseStyle/client/client.gen.ts | 296 +++ .../react-query/responseStyle/client/index.ts | 25 + .../responseStyle/client/types.gen.ts | 214 ++ .../responseStyle/client/utils.gen.ts | 316 +++ .../responseStyle/core/auth.gen.ts | 41 + .../responseStyle/core/bodySerializer.gen.ts | 82 + .../responseStyle/core/params.gen.ts | 169 ++ .../responseStyle/core/pathSerializer.gen.ts | 171 ++ .../core/queryKeySerializer.gen.ts | 117 + .../core/serverSentEvents.gen.ts | 243 ++ .../responseStyle/core/types.gen.ts | 104 + .../responseStyle/core/utils.gen.ts | 140 ++ .../react-query/responseStyle/index.ts | 4 + .../react-query/responseStyle/sdk.gen.ts | 206 ++ .../react-query/responseStyle/types.gen.ts | 2081 ++++++++++++++++ .../useMutation/client/client.gen.ts | 6 + .../solid-query/asClass/client/client.gen.ts | 6 + .../solid-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../svelte-query/asClass/client/client.gen.ts | 6 + .../svelte-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../vue-query/asClass/client/client.gen.ts | 6 + .../vue-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../security-api-key/client/client.gen.ts | 6 + .../3.0.x/security-false/client/client.gen.ts | 6 + .../security-http-bearer/client/client.gen.ts | 6 + .../security-oauth2/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../3.0.x/servers/client/client.gen.ts | 6 + .../transformers-all-of/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../transformers-array/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../base-url-false/client/client.gen.ts | 6 + .../base-url-number/client/client.gen.ts | 6 + .../base-url-strict/client/client.gen.ts | 6 + .../base-url-string/client/client.gen.ts | 6 + .../clean-false/client/client.gen.ts | 6 + .../clean-false/core/response.gen.ts | 98 + .../default/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../sdk-client-optional/client/client.gen.ts | 6 + .../sdk-client-required/client/client.gen.ts | 6 + .../tsconfig-node16-sdk/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../clean-false/core/response.gen.ts | 98 + .../base-url-false/client/client.gen.ts | 6 + .../base-url-number/client/client.gen.ts | 6 + .../base-url-strict/client/client.gen.ts | 6 + .../base-url-string/client/client.gen.ts | 6 + .../clean-false/client/client.gen.ts | 6 + .../clean-false/core/response.gen.ts | 98 + .../client-fetch/default/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../sdk-client-optional/client/client.gen.ts | 6 + .../sdk-client-required/client/client.gen.ts | 6 + .../tsconfig-node16-sdk/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../base-url-false/client/client.gen.ts | 6 + .../base-url-number/client/client.gen.ts | 6 + .../base-url-strict/client/client.gen.ts | 6 + .../base-url-string/client/client.gen.ts | 6 + .../clean-false/client/client.gen.ts | 6 + .../clean-false/core/response.gen.ts | 98 + .../client-ky/default/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../sdk-client-optional/client/client.gen.ts | 6 + .../sdk-client-required/client/client.gen.ts | 6 + .../tsconfig-node16-sdk/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../clean-false/core/response.gen.ts | 98 + .../clean-false/core/response.gen.ts | 98 + .../base-url-false/client/client.gen.ts | 6 + .../base-url-number/client/client.gen.ts | 6 + .../base-url-strict/client/client.gen.ts | 6 + .../base-url-string/client/client.gen.ts | 6 + .../clean-false/client/client.gen.ts | 6 + .../clean-false/core/response.gen.ts | 98 + .../default/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../sdk-client-optional/client/client.gen.ts | 6 + .../sdk-client-required/client/client.gen.ts | 6 + .../tsconfig-node16-sdk/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../3.1.x/headers/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../3.1.x/pagination-ref/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../common/default-class/client/client.gen.ts | 6 + .../common/default/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../sdk-nested-classes/client/client.gen.ts | 6 + .../@hey-api/sdk/default/client/client.gen.ts | 6 + .../sdk/instance/client/client.gen.ts | 6 + .../sdk/throwOnError/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../colada/asClass/client/client.gen.ts | 6 + .../@pinia/colada/fetch/client/client.gen.ts | 6 + .../asClass/client/client.gen.ts | 6 + .../fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../preact-query/asClass/client/client.gen.ts | 6 + .../preact-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../react-query/asClass/client/client.gen.ts | 6 + .../react-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../@tanstack/react-query.gen.ts | 960 ++++++++ .../react-query/responseStyle/client.gen.ts | 16 + .../responseStyle/client/client.gen.ts | 296 +++ .../react-query/responseStyle/client/index.ts | 25 + .../responseStyle/client/types.gen.ts | 214 ++ .../responseStyle/client/utils.gen.ts | 316 +++ .../responseStyle/core/auth.gen.ts | 41 + .../responseStyle/core/bodySerializer.gen.ts | 82 + .../responseStyle/core/params.gen.ts | 169 ++ .../responseStyle/core/pathSerializer.gen.ts | 171 ++ .../core/queryKeySerializer.gen.ts | 117 + .../core/serverSentEvents.gen.ts | 243 ++ .../responseStyle/core/types.gen.ts | 104 + .../responseStyle/core/utils.gen.ts | 140 ++ .../react-query/responseStyle/index.ts | 4 + .../react-query/responseStyle/sdk.gen.ts | 206 ++ .../react-query/responseStyle/types.gen.ts | 2100 +++++++++++++++++ .../useMutation/client/client.gen.ts | 6 + .../solid-query/asClass/client/client.gen.ts | 6 + .../solid-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../svelte-query/asClass/client/client.gen.ts | 6 + .../svelte-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../vue-query/asClass/client/client.gen.ts | 6 + .../vue-query/fetch/client/client.gen.ts | 6 + .../name-builder/client/client.gen.ts | 6 + .../security-api-key/client/client.gen.ts | 6 + .../3.1.x/security-false/client/client.gen.ts | 6 + .../security-http-bearer/client/client.gen.ts | 6 + .../security-oauth2/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../3.1.x/servers/client/client.gen.ts | 6 + .../3.1.x/sse-angular/client/client.gen.ts | 6 + .../3.1.x/sse-fetch/client/client.gen.ts | 6 + .../3.1.x/sse-ofetch/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../transformers-all-of/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../transformers-array/client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../client/client.gen.ts | 6 + .../main/test/plugins.test.ts | 14 + .../@hey-api/client-angular/bundle/client.ts | 6 + .../@hey-api/client-fetch/bundle/client.ts | 6 + .../@hey-api/client-ky/bundle/client.ts | 6 + .../@hey-api/client-ofetch/bundle/client.ts | 6 + .../angular-query-experimental/config.ts | 1 + .../angular-query-experimental/types.ts | 14 + .../plugins/@tanstack/preact-query/config.ts | 1 + .../plugins/@tanstack/preact-query/types.ts | 14 + .../query-core/v5/infiniteQueryOptions.ts | 267 ++- .../query-core/v5/mutationOptions.ts | 235 +- .../plugins/@tanstack/query-core/v5/plugin.ts | 129 +- .../@tanstack/query-core/v5/queryOptions.ts | 244 +- .../plugins/@tanstack/react-query/config.ts | 1 + .../plugins/@tanstack/react-query/types.ts | 14 + .../plugins/@tanstack/solid-query/config.ts | 1 + .../plugins/@tanstack/solid-query/types.ts | 14 + .../plugins/@tanstack/svelte-query/config.ts | 1 + .../plugins/@tanstack/svelte-query/types.ts | 14 + .../src/plugins/@tanstack/vue-query/config.ts | 1 + .../src/plugins/@tanstack/vue-query/types.ts | 14 + 264 files changed, 16886 insertions(+), 202 deletions(-) create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts diff --git a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts +++ b/packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts new file mode 100644 index 0000000000..eb2dbea283 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts @@ -0,0 +1,645 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanstack/react-query'; + +import { client } from '../client.gen'; +import { callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexTypes, deleteCallWithoutParametersAndResponse, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, fooWow, getCallWithoutParametersAndResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionBody, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, serviceWithEmptyTag, testErrorCode, types } from '../sdk.gen'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData, TypesResponse } from '../types.gen'; + +type ResponseResult = TStyle extends "fields" ? { + data: TData; + request: Request; + response: Response; +} : TData; + +type ResponseError = TStyle extends "fields" ? { + error: TError; + request: Request; + response: Response; +} : TError; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); + +export const serviceWithEmptyTagOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await serviceWithEmptyTag({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: serviceWithEmptyTagQueryKey(options) +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await patchApiVbyApiVersionNoTag({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const fooWowMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await fooWow({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await deleteCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); + +export const getCallWithoutParametersAndResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await getCallWithoutParametersAndResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getCallWithoutParametersAndResponseQueryKey(options) +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await patchCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await putCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithDescriptionsMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDescriptions({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithParametersMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithParameters({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithWeirdParameterNames({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); + +export const callWithDefaultParametersOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithDefaultParameters({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithDefaultParametersQueryKey(options) +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDefaultOptionalParameters({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callToTestOrderOfParamsMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callToTestOrderOfParams({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateNameMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); + +export const duplicateName2Options = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await duplicateName2({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: duplicateName2QueryKey(options) +}); + +export const duplicateName3Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName3({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateName4Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName4({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); + +export const callWithNoContentResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithNoContentResponseQueryKey(options) +}); + +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); + +export const callWithResponseAndNoContentResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithResponseAndNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithResponseAndNoContentResponseQueryKey(options) +}); + +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); + +export const dummyAOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await dummyA({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: dummyAQueryKey(options) +}); + +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); + +export const dummyBOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await dummyB({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: dummyBQueryKey(options) +}); + +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); + +export const callWithResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithResponseQueryKey(options) +}); + +export const callWithDuplicateResponsesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDuplicateResponses({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithResponsesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithResponses({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); + +export const collectionFormatOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await collectionFormat({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: collectionFormatQueryKey(options) +}); + +export const typesQueryKey = (options: Options) => createQueryKey('types', options); + +export const typesOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await types({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: typesQueryKey(options) +}); + +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); + +export const complexTypesOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await complexTypes({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: complexTypesQueryKey(options) +}); + +export const callWithResultFromHeaderMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithResultFromHeader({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const testErrorCodeMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await testErrorCode({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +/** + * Body should not be unknown + * + * Body should not be unknown + */ +export const postApiVbyApiVersionBodyMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postApiVbyApiVersionBody({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts new file mode 100644 index 0000000000..25cd14eafb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig({ baseUrl: 'http://localhost:3000/base' })); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts new file mode 100644 index 0000000000..ce96094c02 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts @@ -0,0 +1,296 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined as string | undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined; + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response: Response; + + try { + response = await _fetch(request); + } catch (error) { + // Handle fetch exceptions (AbortError, network errors, etc.) + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, undefined as any, request, opts)) as unknown; + } + } + + finalError = finalError || ({} as unknown); + + if (opts.throwOnError) { + throw finalError; + } + + // Return error response + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + request, + response: undefined as any, + }; + } + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if (response.status === 204 || response.headers.get('Content-Length') === '0') { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'text': + data = await response[parseAs](); + break; + case 'json': { + // Some servers return 200 with no Content-Length and empty body. + // response.json() would throw; read as text and parse if non-empty. + const text = await response.text(); + data = text ? JSON.parse(text) : {}; + break; + } + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined, + url, + }); + }; + + const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options }); + + return { + buildUrl: _buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/index.ts @@ -0,0 +1,25 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Auth } from '../core/auth.gen'; +export type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +export { + formDataBodySerializer, + jsonBodySerializer, + urlSearchParamsBodySerializer, +} from '../core/bodySerializer.gen'; +export { buildClientParams } from '../core/params.gen'; +export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'; +export { createClient } from './client.gen'; +export type { + Client, + ClientOptions, + Config, + CreateClientConfig, + Options, + RequestOptions, + RequestResult, + ResolvedRequestOptions, + ResponseStyle, + TDataShape, +} from './types.gen'; +export { createConfig, mergeHeaders } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts new file mode 100644 index 0000000000..a3f8616511 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts @@ -0,0 +1,214 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> + extends + Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onRequest' + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record ? TData[keyof TData] : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? (TData extends Record ? TData[keyof TData] : TData) | undefined + : ( + | { + data: TData extends Record ? TData[keyof TData] : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record ? TError[keyof TError] : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick>, 'method'>, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts new file mode 100644 index 0000000000..5162192d8a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts @@ -0,0 +1,316 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = (contentType: string | null): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type)) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e., their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = (request: Req, options: Options) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts new file mode 100644 index 0000000000..3ebf994788 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts @@ -0,0 +1,41 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..67daca60f8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts @@ -0,0 +1,82 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: unknown) => unknown; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: (body: unknown): FormData => { + const data = new FormData(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: unknown): string => + JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: (body: unknown): string => { + const data = new URLSearchParams(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts new file mode 100644 index 0000000000..7955601a5c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts @@ -0,0 +1,169 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = (args: ReadonlyArray, fields: FieldsConfig) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix)); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[key.slice(prefix.length)] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..994b2848c6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts @@ -0,0 +1,171 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions extends SerializePrimitiveOptions, SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..5000df606f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts @@ -0,0 +1,117 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b)); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined => { + if (value === null) { + return null; + } + + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + return value; + } + + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..6aa6cf02a4 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts @@ -0,0 +1,243 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + // Normalize line endings: CRLF -> LF, then CR -> LF + buffer = buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); + + const chunks = buffer.split('\n\n'); + buffer = chunks.pop() ?? ''; + + for (const chunk of chunks) { + const lines = chunk.split('\n'); + const dataLines: Array = []; + let eventName: string | undefined; + + for (const line of lines) { + if (line.startsWith('data:')) { + dataLines.push(line.replace(/^data:\s*/, '')); + } else if (line.startsWith('event:')) { + eventName = line.replace(/^event:\s*/, ''); + } else if (line.startsWith('id:')) { + lastEventId = line.replace(/^id:\s*/, ''); + } else if (line.startsWith('retry:')) { + const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10); + if (!Number.isNaN(parsed)) { + retryDelay = parsed; + } + } + } + + let data: unknown; + let parsedJson = false; + + if (dataLines.length) { + const rawData = dataLines.join('\n'); + try { + data = JSON.parse(rawData); + parsedJson = true; + } catch { + data = rawData; + } + } + + if (parsedJson) { + if (responseValidator) { + await responseValidator(data); + } + + if (responseTransformer) { + data = await responseTransformer(data); + } + } + + onSseEvent?.({ + data, + event: eventName, + id: lastEventId, + retry: retryDelay, + }); + + if (dataLines.length) { + yield data as any; + } + } + } + } finally { + signal.removeEventListener('abort', abortHandler); + reader.releaseLock(); + } + + break; // exit loop on normal completion + } catch (error) { + // connection failed or aborted; retry after delay + onSseError?.(error); + + if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) { + break; // stop after firing error + } + + // exponential backoff: double retry each attempt, cap at 30s + const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000); + await sleep(backoff); + } + } + }; + + const stream = createStream(); + + return { stream }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts new file mode 100644 index 0000000000..9efe71d4c1 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts @@ -0,0 +1,104 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + string | number | boolean | (string | number | boolean)[] | null | undefined | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g., converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true ? never : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts new file mode 100644 index 0000000000..9a4fec7830 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts @@ -0,0 +1,140 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace(match, serializeArrayParam({ explode, name, style, value })); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e., client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/index.ts new file mode 100644 index 0000000000..ee6d0288c0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export { callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexTypes, deleteCallWithoutParametersAndResponse, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, fooWow, getCallWithoutParametersAndResponse, headCallWithoutParametersAndResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, optionsCallWithoutParametersAndResponse, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionBody, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, serviceWithEmptyTag, testErrorCode, types } from './sdk.gen'; +export type { ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, Date, Default, DeleteCallWithoutParametersAndResponseData, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithStrings, ExternalRefA, ExternalRefB, ExternalSharedModel, FailureFailure, FooWowData, FooWowResponses, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ModelThatExtends, ModelThatExtendsExtends, ModelWithArray, ModelWithBoolean, ModelWithCircularReference, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithInteger, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableString, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, OptionsCallWithoutParametersAndResponseData, ParameterActivityParams, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyErrors, PostApiVbyApiVersionBodyResponse, PostApiVbyApiVersionBodyResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ResponsePostActivityResponse, ServiceWithEmptyTagData, SimpleBoolean, SimpleFile, SimpleInteger, SimpleReference, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses } from './types.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts new file mode 100644 index 0000000000..6776488ce6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts @@ -0,0 +1,127 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Client, Options as Options2, TDataShape } from './client'; +import { client } from './client.gen'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, FooWowResponses, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyErrors, PostApiVbyApiVersionBodyResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export const serviceWithEmptyTag = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no+tag', ...options }); + +export const patchApiVbyApiVersionNoTag = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/no+tag', ...options }); + +export const fooWow = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/no+tag', ...options }); + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/simple', ...options }); + +export const getCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple', ...options }); + +export const headCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).head({ url: '/api/v{api-version}/simple', ...options }); + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).options({ url: '/api/v{api-version}/simple', ...options }); + +export const patchCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/simple', ...options }); + +export const postCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/simple', ...options }); + +export const putCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/simple', ...options }); + +export const callWithDescriptions = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/descriptions/', ...options }); + +export const callWithParameters = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/parameters/{parameterPath}', ...options }); + +export const callWithWeirdParameterNames = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const callWithDefaultParameters = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterModel: { object: { explode: false, style: 'form' } } } }, + url: '/api/v{api-version}/defaults', + ...options +}); + +export const callWithDefaultOptionalParameters = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/defaults', ...options }); + +export const callToTestOrderOfParams = (options: Options) => (options.client ?? client).put({ url: '/api/v{api-version}/defaults', ...options }); + +export const duplicateName = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName2 = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName3 = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName4 = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/duplicate', ...options }); + +export const callWithNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no-content', ...options }); + +export const callWithResponseAndNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/response-and-no-content', ...options }); + +export const dummyA = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/a', ...options }); + +export const dummyB = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/b', ...options }); + +export const callWithResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/response', ...options }); + +export const callWithDuplicateResponses = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/response', ...options }); + +export const callWithResponses = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/response', ...options }); + +export const collectionFormat = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { + parameterArrayCSV: { array: { explode: false } }, + parameterArraySSV: { array: { explode: false } }, + parameterArrayTSV: { array: { explode: false } }, + parameterArrayPipes: { array: { explode: false } } + } }, + url: '/api/v{api-version}/collectionFormat', + ...options +}); + +export const types = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterArray: { array: { explode: false } }, parameterDictionary: { object: { explode: false, style: 'form' } } } }, + url: '/api/v{api-version}/types', + ...options +}); + +export const complexTypes = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterObject: { object: { explode: false, style: 'form' } }, parameterReference: { object: { explode: false, style: 'form' } } } }, + url: '/api/v{api-version}/complex', + ...options +}); + +export const callWithResultFromHeader = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/header', ...options }); + +export const testErrorCode = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/error', ...options }); + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', ...options }); + +/** + * Body should not be unknown + * + * Body should not be unknown + */ +export const postApiVbyApiVersionBody = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/body', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts new file mode 100644 index 0000000000..d69b074040 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts @@ -0,0 +1,1190 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +export type ExternalRefA = ExternalSharedModel; + +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + foo?: string; + bar?: string; +}>; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a type-only model that defines Date as a string + */ +export type Date = string; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp: string | null; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + test?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string; + }; + }; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +export type Default = { + name?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type ParameterActivityParams = { + description?: string; + graduate_id?: number; + organization_id?: number; + parent_activity?: number; + post_id?: number; +}; + +export type ResponsePostActivityResponse = { + description?: string; + graduate_id?: number; + organization_id?: number; + parent_activity_id?: number; + post_id?: number; +}; + +export type FailureFailure = { + error?: string; + message?: string; + reference_code?: string; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type ServiceWithEmptyTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions/'; +}; + +export type CallWithParametersData = { + body?: never; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query: { + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that is sent as request body + */ + body: string; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query: { + /** + * This is a simple string with default value + */ + parameterString: string; + /** + * This is a simple number with default value + */ + parameterNumber: number; + /** + * This is a simple boolean with default value + */ + parameterBoolean: boolean; + /** + * This is a simple enum with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a model with one string property + */ + parameterModel: { + /** + * This is a simple string property + */ + prop?: string; + }; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean; + /** + * This is an array parameter + */ + parameterArray: Array; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + }; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * This is a model with one string property + */ + parameterReference: { + /** + * This is a simple string property + */ + prop?: string; + }; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: string; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: NonAsciiStringæøåÆøÅöôêÊ字符串; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PostApiVbyApiVersionBodyData = { + /** + * Body should not be unknown + */ + body: ParameterActivityParams; + path?: never; + query?: never; + url: '/api/v{api-version}/body'; +}; + +export type PostApiVbyApiVersionBodyErrors = { + /** + * Bad Request + */ + 400: FailureFailure; + /** + * Internal Server Error + */ + 500: FailureFailure; +}; + +export type PostApiVbyApiVersionBodyError = PostApiVbyApiVersionBodyErrors[keyof PostApiVbyApiVersionBodyErrors]; + +export type PostApiVbyApiVersionBodyResponses = { + /** + * OK + */ + 200: ResponsePostActivityResponse; +}; + +export type PostApiVbyApiVersionBodyResponse = PostApiVbyApiVersionBodyResponses[keyof PostApiVbyApiVersionBodyResponses]; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/schema-unknown/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-api-key/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-basic/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-false/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/security-oauth2/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-base-path/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers-host/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/servers/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/transforms-read-write/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-binary-format/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-binary-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-binary-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-binary-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/body-response-text-plain/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default-class/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@angular/common/default/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts new file mode 100644 index 0000000000..a8bb58a21e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts @@ -0,0 +1,960 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOptions, type UseMutationOptions } from '@tanstack/react-query'; + +import { client } from '../client.gen'; +import { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from '../sdk.gen'; +import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponse, DummyBData, DummyBResponse, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponse, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, TypesResponse, UploadFileData, UploadFileResponse } from '../types.gen'; + +type ResponseResult = TStyle extends "fields" ? { + data: TData; + request: Request; + response: Response; +} : TData; + +type ResponseError = TStyle extends "fields" ? { + error: TError; + request: Request; + response: Response; +} : TError; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); + +export const exportOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await export_({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: exportQueryKey(options) +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await patchApiVbyApiVersionNoTag({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const importMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await import_({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const fooWowMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await fooWow({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); + +export const apiVVersionODataControllerCountOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await apiVVersionODataControllerCount({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: apiVVersionODataControllerCountQueryKey(options) +}); + +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await getApiVbyApiVersionSimpleOperation({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getApiVbyApiVersionSimpleOperationQueryKey(options) +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await deleteCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); + +export const getCallWithoutParametersAndResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await getCallWithoutParametersAndResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getCallWithoutParametersAndResponseQueryKey(options) +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await patchCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await putCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const deleteFooMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await deleteFoo({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithDescriptionsMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDescriptions({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +/** + * @deprecated + */ +export const deprecatedCallMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await deprecatedCall({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithParametersMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithParameters({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithWeirdParameterNames({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); + +export const getCallWithOptionalParamOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await getCallWithOptionalParam({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getCallWithOptionalParamQueryKey(options) +}); + +const createInfiniteParams = [0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey, page: K) => { + const params = { ...queryKey[0] }; + if (page.body) { + params.body = { + ...queryKey[0].body as any, + ...page.body as any + }; + } + if (page.headers) { + params.headers = { + ...queryKey[0].headers, + ...page.headers + }; + } + if (page.path) { + params.path = { + ...queryKey[0].path as any, + ...page.path as any + }; + } + if (page.query) { + params.query = { + ...queryKey[0].query as any, + ...page.query as any + }; + } + return params as unknown as typeof page; +}; + +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); + +export const getCallWithOptionalParamInfiniteOptions = (options: Options & { + responseStyle?: TStyle; +}) => infiniteQueryOptions, ResponseError, InfiniteData>, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( +// @ts-ignore +{ + queryFn: async ({ pageParam, queryKey, signal }) => { + // @ts-ignore + const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { + query: { + page: pageParam + } + }; + const params = createInfiniteParams(queryKey, page); + const result = await getCallWithOptionalParam({ + ...options, + ...params, + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getCallWithOptionalParamInfiniteQueryKey(options) +}); + +export const postCallWithOptionalParamMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postCallWithOptionalParam({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postApiVbyApiVersionRequestBody({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const postApiVbyApiVersionFormDataMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postApiVbyApiVersionFormData({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); + +export const callWithDefaultParametersOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithDefaultParameters({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithDefaultParametersQueryKey(options) +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDefaultOptionalParameters({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callToTestOrderOfParamsMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callToTestOrderOfParams({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateNameMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); + +export const duplicateName2Options = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await duplicateName2({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: duplicateName2QueryKey(options) +}); + +export const duplicateName3Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName3({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateName4Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName4({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); + +export const callWithNoContentResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithNoContentResponseQueryKey(options) +}); + +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); + +export const callWithResponseAndNoContentResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithResponseAndNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithResponseAndNoContentResponseQueryKey(options) +}); + +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); + +export const dummyAOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await dummyA({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: dummyAQueryKey(options) +}); + +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); + +export const dummyBOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await dummyB({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: dummyBQueryKey(options) +}); + +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); + +export const callWithResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithResponseQueryKey(options) +}); + +export const callWithDuplicateResponsesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDuplicateResponses({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithResponsesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithResponses({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); + +export const collectionFormatOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await collectionFormat({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: collectionFormatQueryKey(options) +}); + +export const typesQueryKey = (options: Options) => createQueryKey('types', options); + +export const typesOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await types({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: typesQueryKey(options) +}); + +export const uploadFileMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await uploadFile({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); + +export const fileResponseOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await fileResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: fileResponseQueryKey(options) +}); + +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); + +export const complexTypesOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await complexTypes({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: complexTypesQueryKey(options) +}); + +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); + +export const multipartResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await multipartResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: multipartResponseQueryKey(options) +}); + +export const multipartRequestMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await multipartRequest({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const complexParamsMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await complexParams({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithResultFromHeaderMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithResultFromHeader({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const testErrorCodeMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await testErrorCode({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +/** + * Login User + */ +export const putWithFormUrlEncodedMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await putWithFormUrlEncoded({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts new file mode 100644 index 0000000000..25cd14eafb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig({ baseUrl: 'http://localhost:3000/base' })); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts new file mode 100644 index 0000000000..ce96094c02 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts @@ -0,0 +1,296 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined as string | undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined; + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response: Response; + + try { + response = await _fetch(request); + } catch (error) { + // Handle fetch exceptions (AbortError, network errors, etc.) + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, undefined as any, request, opts)) as unknown; + } + } + + finalError = finalError || ({} as unknown); + + if (opts.throwOnError) { + throw finalError; + } + + // Return error response + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + request, + response: undefined as any, + }; + } + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if (response.status === 204 || response.headers.get('Content-Length') === '0') { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'text': + data = await response[parseAs](); + break; + case 'json': { + // Some servers return 200 with no Content-Length and empty body. + // response.json() would throw; read as text and parse if non-empty. + const text = await response.text(); + data = text ? JSON.parse(text) : {}; + break; + } + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined, + url, + }); + }; + + const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options }); + + return { + buildUrl: _buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/index.ts @@ -0,0 +1,25 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Auth } from '../core/auth.gen'; +export type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +export { + formDataBodySerializer, + jsonBodySerializer, + urlSearchParamsBodySerializer, +} from '../core/bodySerializer.gen'; +export { buildClientParams } from '../core/params.gen'; +export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'; +export { createClient } from './client.gen'; +export type { + Client, + ClientOptions, + Config, + CreateClientConfig, + Options, + RequestOptions, + RequestResult, + ResolvedRequestOptions, + ResponseStyle, + TDataShape, +} from './types.gen'; +export { createConfig, mergeHeaders } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts new file mode 100644 index 0000000000..a3f8616511 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts @@ -0,0 +1,214 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> + extends + Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onRequest' + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record ? TData[keyof TData] : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? (TData extends Record ? TData[keyof TData] : TData) | undefined + : ( + | { + data: TData extends Record ? TData[keyof TData] : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record ? TError[keyof TError] : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick>, 'method'>, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts new file mode 100644 index 0000000000..5162192d8a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts @@ -0,0 +1,316 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = (contentType: string | null): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type)) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e., their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = (request: Req, options: Options) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts new file mode 100644 index 0000000000..3ebf994788 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts @@ -0,0 +1,41 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..67daca60f8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts @@ -0,0 +1,82 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: unknown) => unknown; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: (body: unknown): FormData => { + const data = new FormData(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: unknown): string => + JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: (body: unknown): string => { + const data = new URLSearchParams(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts new file mode 100644 index 0000000000..7955601a5c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts @@ -0,0 +1,169 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = (args: ReadonlyArray, fields: FieldsConfig) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix)); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[key.slice(prefix.length)] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..994b2848c6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts @@ -0,0 +1,171 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions extends SerializePrimitiveOptions, SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..5000df606f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts @@ -0,0 +1,117 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b)); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined => { + if (value === null) { + return null; + } + + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + return value; + } + + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..6aa6cf02a4 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts @@ -0,0 +1,243 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + // Normalize line endings: CRLF -> LF, then CR -> LF + buffer = buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); + + const chunks = buffer.split('\n\n'); + buffer = chunks.pop() ?? ''; + + for (const chunk of chunks) { + const lines = chunk.split('\n'); + const dataLines: Array = []; + let eventName: string | undefined; + + for (const line of lines) { + if (line.startsWith('data:')) { + dataLines.push(line.replace(/^data:\s*/, '')); + } else if (line.startsWith('event:')) { + eventName = line.replace(/^event:\s*/, ''); + } else if (line.startsWith('id:')) { + lastEventId = line.replace(/^id:\s*/, ''); + } else if (line.startsWith('retry:')) { + const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10); + if (!Number.isNaN(parsed)) { + retryDelay = parsed; + } + } + } + + let data: unknown; + let parsedJson = false; + + if (dataLines.length) { + const rawData = dataLines.join('\n'); + try { + data = JSON.parse(rawData); + parsedJson = true; + } catch { + data = rawData; + } + } + + if (parsedJson) { + if (responseValidator) { + await responseValidator(data); + } + + if (responseTransformer) { + data = await responseTransformer(data); + } + } + + onSseEvent?.({ + data, + event: eventName, + id: lastEventId, + retry: retryDelay, + }); + + if (dataLines.length) { + yield data as any; + } + } + } + } finally { + signal.removeEventListener('abort', abortHandler); + reader.releaseLock(); + } + + break; // exit loop on normal completion + } catch (error) { + // connection failed or aborted; retry after delay + onSseError?.(error); + + if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) { + break; // stop after firing error + } + + // exponential backoff: double retry each attempt, cap at 30s + const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000); + await sleep(backoff); + } + } + }; + + const stream = createStream(); + + return { stream }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts new file mode 100644 index 0000000000..9efe71d4c1 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts @@ -0,0 +1,104 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + string | number | boolean | (string | number | boolean)[] | null | undefined | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g., converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true ? never : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts new file mode 100644 index 0000000000..9a4fec7830 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts @@ -0,0 +1,140 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace(match, serializeArrayParam({ explode, name, style, value })); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e., client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/index.ts new file mode 100644 index 0000000000..6e132194fd --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, headCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, optionsCallWithoutParametersAndResponse, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from './sdk.gen'; +export type { _3eNum1Период, _400, AdditionalPropertiesIntegerIssue, AdditionalPropertiesUnknownIssue, AdditionalPropertiesUnknownIssue2, AdditionalPropertiesUnknownIssue3, AdditionalPropertiesUnknownIssueWritable, AnyOfAnyAndNull, AnyOfArrays, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountResponses, ArrayWithAnyOfProperties, ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CamelCaseCommentWithBreaks, CharactersInDescription, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexParamsData, ComplexParamsResponse, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, CompositionBaseModel, CompositionExtendedModel, CompositionWithAllOfAndNullable, CompositionWithAnyOf, CompositionWithAnyOfAndNullable, CompositionWithAnyOfAnonymous, CompositionWithNestedAnyAndTypeNull, CompositionWithNestedAnyOfAndNull, CompositionWithOneOf, CompositionWithOneOfAndComplexArrayDictionary, CompositionWithOneOfAndNullable, CompositionWithOneOfAndProperties, CompositionWithOneOfAndSimpleArrayDictionary, CompositionWithOneOfAndSimpleDictionary, CompositionWithOneOfAnonymous, CompositionWithOneOfDiscriminator, ConstValue, Default, DeleteCallWithoutParametersAndResponseData, DeleteFooData, DeleteFooData2, DeleteFooData3, DeprecatedCallData, DeprecatedModel, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithPropertiesAndAdditionalProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponse, DummyAResponses, DummyBData, DummyBResponse, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithReplacedCharacters, EnumWithStrings, EnumWithXEnumNames, ExportData, ExternalRefA, ExternalRefB, ExternalSharedModel, File, FileResponseData, FileResponseResponse, FileResponseResponses, FileWritable, FooWowData, FooWowResponses, FreeFormObjectWithAdditionalPropertiesEqEmptyObject, FreeFormObjectWithAdditionalPropertiesEqTrue, FreeFormObjectWithoutAdditionalProperties, GenericSchemaDuplicateIssue1SystemBoolean, GenericSchemaDuplicateIssue1SystemBooleanWritable, GenericSchemaDuplicateIssue1SystemString, GenericSchemaDuplicateIssue1SystemStringWritable, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, Import, ImportData, ImportResponse, ImportResponses, IoK8sApimachineryPkgApisMetaV1DeleteOptions, IoK8sApimachineryPkgApisMetaV1Preconditions, ModelCircle, ModelFromZendesk, ModelSquare, ModelThatExtends, ModelThatExtendsExtends, ModelWithAdditionalPropertiesEqTrue, ModelWithAdditionalPropertiesRef, ModelWithAnyOfConstantSizeArray, ModelWithAnyOfConstantSizeArrayAndIntersect, ModelWithAnyOfConstantSizeArrayNullable, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable, ModelWithArray, ModelWithArrayReadOnlyAndWriteOnly, ModelWithArrayReadOnlyAndWriteOnlyWritable, ModelWithBackticksInDescription, ModelWithBoolean, ModelWithCircularReference, ModelWithConst, ModelWithConstantSizeArray, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithEnumWithHyphen, ModelWithInteger, ModelWithNestedArrayEnums, ModelWithNestedArrayEnumsData, ModelWithNestedArrayEnumsDataBar, ModelWithNestedArrayEnumsDataFoo, ModelWithNestedCompositionEnums, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableObject, ModelWithNullableString, ModelWithNumericEnumUnion, ModelWithOneOfAndProperties, ModelWithOneOfEnum, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithPrefixItemsConstantSizeArray, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnlyWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, MultipartResponseResponses, NestedAnyOfArraysNullable, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, NullableObject, OneOfAllOfIssue, OneOfAllOfIssueWritable, OptionsCallWithoutParametersAndResponseData, Pageable, ParameterSimpleParameterUnused, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PostServiceWithEmptyTagResponse, PostServiceWithEmptyTagResponse2, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, SchemaWithFormRestrictedKeys, SimpleBoolean, SimpleFile, SimpleFormData, SimpleInteger, SimpleParameter, SimpleReference, SimpleRequestBody, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses, UploadFileData, UploadFileResponse, UploadFileResponses, XFooBar } from './types.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts new file mode 100644 index 0000000000..e48dcff8cf --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts @@ -0,0 +1,206 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type Client, formDataBodySerializer, type Options as Options2, type TDataShape, urlSearchParamsBodySerializer } from './client'; +import { client } from './client.gen'; +import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponses, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponses, FooWowData, FooWowResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ImportData, ImportResponses, MultipartRequestData, MultipartResponseData, MultipartResponseResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses, UploadFileData, UploadFileResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export const export_ = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no+tag', ...options }); + +export const patchApiVbyApiVersionNoTag = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/no+tag', ...options }); + +export const import_ = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/no+tag', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const fooWow = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/no+tag', ...options }); + +export const apiVVersionODataControllerCount = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple/$count', ...options }); + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/simple:operation', ...options }); + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/simple', ...options }); + +export const getCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple', ...options }); + +export const headCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).head({ url: '/api/v{api-version}/simple', ...options }); + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).options({ url: '/api/v{api-version}/simple', ...options }); + +export const patchCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/simple', ...options }); + +export const postCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/simple', ...options }); + +export const putCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/simple', ...options }); + +export const deleteFoo = (options: Options) => (options.client ?? client).delete({ url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', ...options }); + +export const callWithDescriptions = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/descriptions', ...options }); + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/parameters/deprecated', ...options }); + +export const callWithParameters = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const callWithWeirdParameterNames = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const getCallWithOptionalParam = (options: Options) => (options.client ?? client).get({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const postCallWithOptionalParam = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const postApiVbyApiVersionRequestBody = (options?: Options) => (options?.client ?? client).post({ + url: '/api/v{api-version}/requestBody', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } +}); + +export const postApiVbyApiVersionFormData = (options?: Options) => (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/formData', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } +}); + +export const callWithDefaultParameters = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/defaults', ...options }); + +export const callWithDefaultOptionalParameters = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/defaults', ...options }); + +export const callToTestOrderOfParams = (options: Options) => (options.client ?? client).put({ url: '/api/v{api-version}/defaults', ...options }); + +export const duplicateName = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName2 = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName3 = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName4 = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/duplicate', ...options }); + +export const callWithNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no-content', ...options }); + +export const callWithResponseAndNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/response-and-no-content', ...options }); + +export const dummyA = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/a', ...options }); + +export const dummyB = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/b', ...options }); + +export const callWithResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/response', ...options }); + +export const callWithDuplicateResponses = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/response', ...options }); + +export const callWithResponses = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/response', ...options }); + +export const collectionFormat = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/collectionFormat', ...options }); + +export const types = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/types', ...options }); + +export const uploadFile = (options: Options) => (options.client ?? client).post({ + ...urlSearchParamsBodySerializer, + url: '/api/v{api-version}/upload', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } +}); + +export const fileResponse = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/file/{id}', ...options }); + +export const complexTypes = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterObject: { object: { style: 'form' } } } }, + url: '/api/v{api-version}/complex', + ...options +}); + +export const multipartResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multipart', ...options }); + +export const multipartRequest = (options?: Options) => (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/multipart', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } +}); + +export const complexParams = (options: Options) => (options.client ?? client).put({ + url: '/api/v{api-version}/complex/{id}', + ...options, + headers: { + 'Content-Type': 'application/json-patch+json', + ...options.headers + } +}); + +export const callWithResultFromHeader = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/header', ...options }); + +export const testErrorCode = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/error', ...options }); + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', ...options }); + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => (options.client ?? client).put({ + ...urlSearchParamsBodySerializer, + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts new file mode 100644 index 0000000000..3287ee8737 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts @@ -0,0 +1,2081 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +/** + * Model with number-only name + */ +export type _400 = string; + +export type ExternalRefA = ExternalSharedModel; + +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CamelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = '\'Single Quote\'' | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: CamelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type ModelFromZendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + /** + * Foo-Bar-Baz-Qux + */ + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind: 'circle'; +} & ModelCircle) | ({ + kind: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3eNum1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array<_3eNum1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type File = { + /** + * Id + */ + readonly id?: string; + /** + * Updated at + */ + readonly updated_at?: string; + /** + * Created at + */ + readonly created_at?: string; + /** + * Mime + */ + mime: string; + /** + * File + */ + readonly file?: string; +}; + +export type Default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { + [key: string]: unknown; +}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: unknown; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆøÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +/** + * An object with additional properties that can be null + */ +export type ModelWithAdditionalPropertiesRef = { + [key: string]: NullableObject | null; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = Array; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | Import, + number | Import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆøÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type Import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: IoK8sApimachineryPkgApisMetaV1Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBoolean = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemString = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnlyWritable = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type FileWritable = { + /** + * Mime + */ + mime: string; +}; + +export type ModelWithReadOnlyAndWriteOnlyWritable = { + foo: string; + baz: string; +}; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = [ + number | Import, + number | Import +]; + +export type AdditionalPropertiesUnknownIssueWritable = { + [key: string]: string | number; +}; + +export type OneOfAllOfIssueWritable = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBooleanWritable = { + item?: boolean; + error?: string | null; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemStringWritable = { + item?: string | null; + error?: string | null; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type XFooBar = ModelWithString; + +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + +export type ExportData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ImportData = { + body: ModelWithReadOnlyAndWriteOnlyWritable | ModelWithArrayReadOnlyAndWriteOnlyWritable; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type ImportResponses = { + /** + * Success + */ + 200: ModelFromZendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ApiVVersionODataControllerCountData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple/$count'; +}; + +export type ApiVVersionODataControllerCountResponses = { + /** + * Success + */ + 200: ModelFromZendesk; +}; + +export type ApiVVersionODataControllerCountResponse = ApiVVersionODataControllerCountResponses[keyof ApiVVersionODataControllerCountResponses]; + +export type GetApiVbyApiVersionSimpleOperationData = { + body?: never; + path: { + /** + * foo in method + */ + foo_param: string; + }; + query?: never; + url: '/api/v{api-version}/simple:operation'; +}; + +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type DeleteFooData3 = { + body?: never; + headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + path: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + query?: never; + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions'; +}; + +export type DeprecatedCallData = { + body?: never; + headers: { + /** + * This parameter is deprecated + * + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/parameters/deprecated'; +}; + +export type CallWithParametersData = { + /** + * This is the parameter that goes into the body + */ + body: { + [key: string]: unknown; + } | null; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that goes into the body + */ + body: ModelWithString | null; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is a required parameter + */ + body: ModelWithOneOfEnum; + path?: never; + query?: { + /** + * This is an optional parameter + */ + page?: number; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + body?: { + offset?: number | null; + }; + path?: never; + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; + +export type PostApiVbyApiVersionRequestBodyData = { + /** + * A reusable request body + */ + body?: SimpleRequestBody; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/requestBody'; +}; + +export type PostApiVbyApiVersionFormDataData = { + /** + * A reusable request body + */ + body?: SimpleFormData; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/formData'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; + +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + 200: _400; +}; + +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; + +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + default: Import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type UploadFileData = { + body: Blob | File; + path: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query?: never; + url: '/api/v{api-version}/upload'; +}; + +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; + +export type FileResponseData = { + body?: never; + path: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/file/{id}'; +}; + +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }; +}; + +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + +export type MultipartRequestData = { + body?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type ComplexParamsData = { + body?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + path: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/complex/{id}'; +}; + +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: number; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PutWithFormUrlEncodedData = { + body: ArrayWithStrings; + path?: never; + query?: never; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-api-key/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-false/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-http-bearer/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-oauth2/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/security-open-id-connect/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/servers/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-all-of/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-allof-response-wrapper/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-allof-response-wrapper/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-allof-response-wrapper/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-allof-response-wrapper/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-any-of-null/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-array/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transformers-recursive/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/transforms-read-write/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/body-response-text-plain/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-false/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-number/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-strict/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/base-url-string/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts new file mode 100644 index 0000000000..5215dd8f46 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts @@ -0,0 +1,98 @@ +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +export class ResponseError extends Error { + readonly body: T; + readonly request: Request; + readonly response: Response; + readonly status: number; + + override name = 'ResponseError' as const; + + constructor(options: { body: T; message?: string; request: Request; response: Response }) { + super(options.message ?? options.response.statusText); + this.body = options.body; + this.request = options.request; + this.response = options.response; + this.status = options.response.status; + } +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/default/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/client.gen.ts index bad71be9fa..ae500842ea 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/import-file-extension-ts/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-optional/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/sdk-client-required/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/client.gen.ts index b6a1e2832a..060f07ae8c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-node16-sdk/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/client.gen.ts index b6a1e2832a..060f07ae8c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/tsconfig-nodenext-sdk/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts new file mode 100644 index 0000000000..5215dd8f46 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts @@ -0,0 +1,98 @@ +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +export class ResponseError extends Error { + readonly body: T; + readonly request: Request; + readonly response: Response; + readonly status: number; + + override name = 'ResponseError' as const; + + constructor(options: { body: T; message?: string; request: Request; response: Response }) { + super(options.message ?? options.response.statusText); + this.body = options.body; + this.request = options.request; + this.response = options.response; + this.status = options.response.status; + } +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-false/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-number/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-strict/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/base-url-string/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts new file mode 100644 index 0000000000..5215dd8f46 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts @@ -0,0 +1,98 @@ +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +export class ResponseError extends Error { + readonly body: T; + readonly request: Request; + readonly response: Response; + readonly status: number; + + override name = 'ResponseError' as const; + + constructor(options: { body: T; message?: string; request: Request; response: Response }) { + super(options.message ?? options.response.statusText); + this.body = options.body; + this.request = options.request; + this.response = options.response; + this.status = options.response.status; + } +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/default/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/client/client.gen.ts index 8fea97c7fb..a56c5e2a7b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/import-file-extension-ts/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-optional/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/sdk-client-required/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-node16-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-node16-sdk/client/client.gen.ts index 1867ee2b0f..4381a91560 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-node16-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-node16-sdk/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/client/client.gen.ts index 1867ee2b0f..4381a91560 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/tsconfig-nodenext-sdk/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-false/client/client.gen.ts index bc973c7147..c671872595 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-false/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-number/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-number/client/client.gen.ts index bc973c7147..c671872595 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-number/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-number/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-strict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-strict/client/client.gen.ts index bc973c7147..c671872595 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-strict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-strict/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-string/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-string/client/client.gen.ts index bc973c7147..c671872595 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-string/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/base-url-string/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/client/client.gen.ts index bc973c7147..c671872595 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts new file mode 100644 index 0000000000..5215dd8f46 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts @@ -0,0 +1,98 @@ +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +export class ResponseError extends Error { + readonly body: T; + readonly request: Request; + readonly response: Response; + readonly status: number; + + override name = 'ResponseError' as const; + + constructor(options: { body: T; message?: string; request: Request; response: Response }) { + super(options.message ?? options.response.statusText); + this.body = options.body; + this.request = options.request; + this.response = options.response; + this.status = options.response.status; + } +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/default/client/client.gen.ts index bc973c7147..c671872595 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/default/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/import-file-extension-ts/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/import-file-extension-ts/client/client.gen.ts index 1d351001e7..302bb76398 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/import-file-extension-ts/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/import-file-extension-ts/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/sdk-client-optional/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/sdk-client-optional/client/client.gen.ts index bc973c7147..c671872595 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/sdk-client-optional/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/sdk-client-optional/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/sdk-client-required/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/sdk-client-required/client/client.gen.ts index bc973c7147..c671872595 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/sdk-client-required/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/sdk-client-required/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/tsconfig-node16-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/tsconfig-node16-sdk/client/client.gen.ts index ddab114f4d..cdddb353a8 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/tsconfig-node16-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/tsconfig-node16-sdk/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/tsconfig-nodenext-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/tsconfig-nodenext-sdk/client/client.gen.ts index ddab114f4d..cdddb353a8 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/tsconfig-nodenext-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/tsconfig-nodenext-sdk/client/client.gen.ts @@ -104,6 +104,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts new file mode 100644 index 0000000000..5215dd8f46 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts @@ -0,0 +1,98 @@ +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +export class ResponseError extends Error { + readonly body: T; + readonly request: Request; + readonly response: Response; + readonly status: number; + + override name = 'ResponseError' as const; + + constructor(options: { body: T; message?: string; request: Request; response: Response }) { + super(options.message ?? options.response.statusText); + this.body = options.body; + this.request = options.request; + this.response = options.response; + this.status = options.response.status; + } +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts new file mode 100644 index 0000000000..5215dd8f46 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts @@ -0,0 +1,98 @@ +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +export class ResponseError extends Error { + readonly body: T; + readonly request: Request; + readonly response: Response; + readonly status: number; + + override name = 'ResponseError' as const; + + constructor(options: { body: T; message?: string; request: Request; response: Response }) { + super(options.message ?? options.response.statusText); + this.body = options.body; + this.request = options.request; + this.response = options.response; + this.status = options.response.status; + } +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-false/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-number/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-strict/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/base-url-string/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts new file mode 100644 index 0000000000..5215dd8f46 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts @@ -0,0 +1,98 @@ +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +export class ResponseError extends Error { + readonly body: T; + readonly request: Request; + readonly response: Response; + readonly status: number; + + override name = 'ResponseError' as const; + + constructor(options: { body: T; message?: string; request: Request; response: Response }) { + super(options.message ?? options.response.statusText); + this.body = options.body; + this.request = options.request; + this.response = options.response; + this.status = options.response.status; + } +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/default/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/client/client.gen.ts index 147aeac4fd..220e1d6bee 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/import-file-extension-ts/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-optional/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/sdk-client-required/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-node16-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-node16-sdk/client/client.gen.ts index ee0175ac8c..c9f5848108 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-node16-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-node16-sdk/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/client/client.gen.ts index ee0175ac8c..c9f5848108 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/tsconfig-nodenext-sdk/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/headers/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default-class/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@angular/common/default/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/default/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/instance/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/transforms-read-write-ignore/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/preact-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts new file mode 100644 index 0000000000..a8bb58a21e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts @@ -0,0 +1,960 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOptions, type UseMutationOptions } from '@tanstack/react-query'; + +import { client } from '../client.gen'; +import { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from '../sdk.gen'; +import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponse, DummyBData, DummyBResponse, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponse, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, TypesResponse, UploadFileData, UploadFileResponse } from '../types.gen'; + +type ResponseResult = TStyle extends "fields" ? { + data: TData; + request: Request; + response: Response; +} : TData; + +type ResponseError = TStyle extends "fields" ? { + error: TError; + request: Request; + response: Response; +} : TError; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); + +export const exportOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await export_({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: exportQueryKey(options) +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await patchApiVbyApiVersionNoTag({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const importMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await import_({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const fooWowMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await fooWow({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); + +export const apiVVersionODataControllerCountOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await apiVVersionODataControllerCount({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: apiVVersionODataControllerCountQueryKey(options) +}); + +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await getApiVbyApiVersionSimpleOperation({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getApiVbyApiVersionSimpleOperationQueryKey(options) +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await deleteCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); + +export const getCallWithoutParametersAndResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await getCallWithoutParametersAndResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getCallWithoutParametersAndResponseQueryKey(options) +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await patchCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await putCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const deleteFooMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await deleteFoo({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithDescriptionsMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDescriptions({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +/** + * @deprecated + */ +export const deprecatedCallMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await deprecatedCall({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithParametersMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithParameters({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithWeirdParameterNames({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); + +export const getCallWithOptionalParamOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await getCallWithOptionalParam({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getCallWithOptionalParamQueryKey(options) +}); + +const createInfiniteParams = [0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey, page: K) => { + const params = { ...queryKey[0] }; + if (page.body) { + params.body = { + ...queryKey[0].body as any, + ...page.body as any + }; + } + if (page.headers) { + params.headers = { + ...queryKey[0].headers, + ...page.headers + }; + } + if (page.path) { + params.path = { + ...queryKey[0].path as any, + ...page.path as any + }; + } + if (page.query) { + params.query = { + ...queryKey[0].query as any, + ...page.query as any + }; + } + return params as unknown as typeof page; +}; + +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); + +export const getCallWithOptionalParamInfiniteOptions = (options: Options & { + responseStyle?: TStyle; +}) => infiniteQueryOptions, ResponseError, InfiniteData>, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( +// @ts-ignore +{ + queryFn: async ({ pageParam, queryKey, signal }) => { + // @ts-ignore + const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { + query: { + page: pageParam + } + }; + const params = createInfiniteParams(queryKey, page); + const result = await getCallWithOptionalParam({ + ...options, + ...params, + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: getCallWithOptionalParamInfiniteQueryKey(options) +}); + +export const postCallWithOptionalParamMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postCallWithOptionalParam({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postApiVbyApiVersionRequestBody({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const postApiVbyApiVersionFormDataMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await postApiVbyApiVersionFormData({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); + +export const callWithDefaultParametersOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithDefaultParameters({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithDefaultParametersQueryKey(options) +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDefaultOptionalParameters({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callToTestOrderOfParamsMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callToTestOrderOfParams({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateNameMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); + +export const duplicateName2Options = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await duplicateName2({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: duplicateName2QueryKey(options) +}); + +export const duplicateName3Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName3({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const duplicateName4Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await duplicateName4({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); + +export const callWithNoContentResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithNoContentResponseQueryKey(options) +}); + +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); + +export const callWithResponseAndNoContentResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithResponseAndNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithResponseAndNoContentResponseQueryKey(options) +}); + +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); + +export const dummyAOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await dummyA({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: dummyAQueryKey(options) +}); + +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); + +export const dummyBOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await dummyB({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: dummyBQueryKey(options) +}); + +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); + +export const callWithResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await callWithResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: callWithResponseQueryKey(options) +}); + +export const callWithDuplicateResponsesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithDuplicateResponses({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithResponsesMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithResponses({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); + +export const collectionFormatOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await collectionFormat({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: collectionFormatQueryKey(options) +}); + +export const typesQueryKey = (options: Options) => createQueryKey('types', options); + +export const typesOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await types({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: typesQueryKey(options) +}); + +export const uploadFileMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await uploadFile({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); + +export const fileResponseOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await fileResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: fileResponseQueryKey(options) +}); + +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); + +export const complexTypesOptions = (options: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await complexTypes({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: complexTypesQueryKey(options) +}); + +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); + +export const multipartResponseOptions = (options?: Options & { + responseStyle?: TStyle; +}) => queryOptions, ResponseError, ResponseResult, ReturnType>({ + queryFn: async ({ queryKey, signal }) => { + const result = await multipartResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + }, + queryKey: multipartResponseQueryKey(options) +}); + +export const multipartRequestMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await multipartRequest({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const complexParamsMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await complexParams({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const callWithResultFromHeaderMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await callWithResultFromHeader({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const testErrorCodeMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await testErrorCode({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; + +/** + * Login User + */ +export const putWithFormUrlEncodedMutation = (options?: Partial> & { + responseStyle?: TStyle; +}): UseMutationOptions, ResponseError, Options> => { + const mutationOptions: UseMutationOptions, ResponseError, Options> = { + mutationFn: async (fnOptions) => { + const result = await putWithFormUrlEncoded({ + ...options, + ...fnOptions, + throwOnError: true, + responseStyle: 'fields' + }); + const _data = options?.responseStyle === 'fields' ? result : result.data; + return _data as ResponseResult; + } + }; + return mutationOptions; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts new file mode 100644 index 0000000000..25cd14eafb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig({ baseUrl: 'http://localhost:3000/base' })); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts new file mode 100644 index 0000000000..ce96094c02 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts @@ -0,0 +1,296 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined as string | undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined; + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response: Response; + + try { + response = await _fetch(request); + } catch (error) { + // Handle fetch exceptions (AbortError, network errors, etc.) + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, undefined as any, request, opts)) as unknown; + } + } + + finalError = finalError || ({} as unknown); + + if (opts.throwOnError) { + throw finalError; + } + + // Return error response + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + request, + response: undefined as any, + }; + } + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if (response.status === 204 || response.headers.get('Content-Length') === '0') { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'text': + data = await response[parseAs](); + break; + case 'json': { + // Some servers return 200 with no Content-Length and empty body. + // response.json() would throw; read as text and parse if non-empty. + const text = await response.text(); + data = text ? JSON.parse(text) : {}; + break; + } + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined, + url, + }); + }; + + const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options }); + + return { + buildUrl: _buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/index.ts @@ -0,0 +1,25 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Auth } from '../core/auth.gen'; +export type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +export { + formDataBodySerializer, + jsonBodySerializer, + urlSearchParamsBodySerializer, +} from '../core/bodySerializer.gen'; +export { buildClientParams } from '../core/params.gen'; +export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'; +export { createClient } from './client.gen'; +export type { + Client, + ClientOptions, + Config, + CreateClientConfig, + Options, + RequestOptions, + RequestResult, + ResolvedRequestOptions, + ResponseStyle, + TDataShape, +} from './types.gen'; +export { createConfig, mergeHeaders } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts new file mode 100644 index 0000000000..a3f8616511 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts @@ -0,0 +1,214 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> + extends + Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onRequest' + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record ? TData[keyof TData] : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? (TData extends Record ? TData[keyof TData] : TData) | undefined + : ( + | { + data: TData extends Record ? TData[keyof TData] : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record ? TError[keyof TError] : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick>, 'method'>, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts new file mode 100644 index 0000000000..5162192d8a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/utils.gen.ts @@ -0,0 +1,316 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = (contentType: string | null): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type)) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e., their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = (request: Req, options: Options) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts new file mode 100644 index 0000000000..3ebf994788 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/auth.gen.ts @@ -0,0 +1,41 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..67daca60f8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/bodySerializer.gen.ts @@ -0,0 +1,82 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: unknown) => unknown; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: (body: unknown): FormData => { + const data = new FormData(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: unknown): string => + JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: (body: unknown): string => { + const data = new URLSearchParams(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts new file mode 100644 index 0000000000..7955601a5c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/params.gen.ts @@ -0,0 +1,169 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = (args: ReadonlyArray, fields: FieldsConfig) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix)); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[key.slice(prefix.length)] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..994b2848c6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/pathSerializer.gen.ts @@ -0,0 +1,171 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions extends SerializePrimitiveOptions, SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..5000df606f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/queryKeySerializer.gen.ts @@ -0,0 +1,117 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b)); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined => { + if (value === null) { + return null; + } + + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + return value; + } + + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..6aa6cf02a4 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts @@ -0,0 +1,243 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + // Normalize line endings: CRLF -> LF, then CR -> LF + buffer = buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); + + const chunks = buffer.split('\n\n'); + buffer = chunks.pop() ?? ''; + + for (const chunk of chunks) { + const lines = chunk.split('\n'); + const dataLines: Array = []; + let eventName: string | undefined; + + for (const line of lines) { + if (line.startsWith('data:')) { + dataLines.push(line.replace(/^data:\s*/, '')); + } else if (line.startsWith('event:')) { + eventName = line.replace(/^event:\s*/, ''); + } else if (line.startsWith('id:')) { + lastEventId = line.replace(/^id:\s*/, ''); + } else if (line.startsWith('retry:')) { + const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10); + if (!Number.isNaN(parsed)) { + retryDelay = parsed; + } + } + } + + let data: unknown; + let parsedJson = false; + + if (dataLines.length) { + const rawData = dataLines.join('\n'); + try { + data = JSON.parse(rawData); + parsedJson = true; + } catch { + data = rawData; + } + } + + if (parsedJson) { + if (responseValidator) { + await responseValidator(data); + } + + if (responseTransformer) { + data = await responseTransformer(data); + } + } + + onSseEvent?.({ + data, + event: eventName, + id: lastEventId, + retry: retryDelay, + }); + + if (dataLines.length) { + yield data as any; + } + } + } + } finally { + signal.removeEventListener('abort', abortHandler); + reader.releaseLock(); + } + + break; // exit loop on normal completion + } catch (error) { + // connection failed or aborted; retry after delay + onSseError?.(error); + + if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) { + break; // stop after firing error + } + + // exponential backoff: double retry each attempt, cap at 30s + const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000); + await sleep(backoff); + } + } + }; + + const stream = createStream(); + + return { stream }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts new file mode 100644 index 0000000000..9efe71d4c1 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/types.gen.ts @@ -0,0 +1,104 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + string | number | boolean | (string | number | boolean)[] | null | undefined | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g., converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true ? never : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts new file mode 100644 index 0000000000..9a4fec7830 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/utils.gen.ts @@ -0,0 +1,140 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace(match, serializeArrayParam({ explode, name, style, value })); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e., client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/index.ts new file mode 100644 index 0000000000..6e132194fd --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, headCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, optionsCallWithoutParametersAndResponse, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from './sdk.gen'; +export type { _3eNum1Период, _400, AdditionalPropertiesIntegerIssue, AdditionalPropertiesUnknownIssue, AdditionalPropertiesUnknownIssue2, AdditionalPropertiesUnknownIssue3, AdditionalPropertiesUnknownIssueWritable, AnyOfAnyAndNull, AnyOfArrays, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountResponses, ArrayWithAnyOfProperties, ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CamelCaseCommentWithBreaks, CharactersInDescription, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexParamsData, ComplexParamsResponse, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, CompositionBaseModel, CompositionExtendedModel, CompositionWithAllOfAndNullable, CompositionWithAnyOf, CompositionWithAnyOfAndNullable, CompositionWithAnyOfAnonymous, CompositionWithNestedAnyAndTypeNull, CompositionWithNestedAnyOfAndNull, CompositionWithOneOf, CompositionWithOneOfAndComplexArrayDictionary, CompositionWithOneOfAndNullable, CompositionWithOneOfAndProperties, CompositionWithOneOfAndSimpleArrayDictionary, CompositionWithOneOfAndSimpleDictionary, CompositionWithOneOfAnonymous, CompositionWithOneOfDiscriminator, ConstValue, Default, DeleteCallWithoutParametersAndResponseData, DeleteFooData, DeleteFooData2, DeleteFooData3, DeprecatedCallData, DeprecatedModel, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithPropertiesAndAdditionalProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponse, DummyAResponses, DummyBData, DummyBResponse, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithReplacedCharacters, EnumWithStrings, EnumWithXEnumNames, ExportData, ExternalRefA, ExternalRefB, ExternalSharedModel, File, FileResponseData, FileResponseResponse, FileResponseResponses, FileWritable, FooWowData, FooWowResponses, FreeFormObjectWithAdditionalPropertiesEqEmptyObject, FreeFormObjectWithAdditionalPropertiesEqTrue, FreeFormObjectWithoutAdditionalProperties, GenericSchemaDuplicateIssue1SystemBoolean, GenericSchemaDuplicateIssue1SystemBooleanWritable, GenericSchemaDuplicateIssue1SystemString, GenericSchemaDuplicateIssue1SystemStringWritable, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, Import, ImportData, ImportResponse, ImportResponses, IoK8sApimachineryPkgApisMetaV1DeleteOptions, IoK8sApimachineryPkgApisMetaV1Preconditions, ModelCircle, ModelFromZendesk, ModelSquare, ModelThatExtends, ModelThatExtendsExtends, ModelWithAdditionalPropertiesEqTrue, ModelWithAdditionalPropertiesRef, ModelWithAnyOfConstantSizeArray, ModelWithAnyOfConstantSizeArrayAndIntersect, ModelWithAnyOfConstantSizeArrayNullable, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable, ModelWithArray, ModelWithArrayReadOnlyAndWriteOnly, ModelWithArrayReadOnlyAndWriteOnlyWritable, ModelWithBackticksInDescription, ModelWithBoolean, ModelWithCircularReference, ModelWithConst, ModelWithConstantSizeArray, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithEnumWithHyphen, ModelWithInteger, ModelWithNestedArrayEnums, ModelWithNestedArrayEnumsData, ModelWithNestedArrayEnumsDataBar, ModelWithNestedArrayEnumsDataFoo, ModelWithNestedCompositionEnums, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableObject, ModelWithNullableString, ModelWithNumericEnumUnion, ModelWithOneOfAndProperties, ModelWithOneOfEnum, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithPrefixItemsConstantSizeArray, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnlyWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, MultipartResponseResponses, NestedAnyOfArraysNullable, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, NullableObject, OneOfAllOfIssue, OneOfAllOfIssueWritable, OptionsCallWithoutParametersAndResponseData, Pageable, ParameterSimpleParameterUnused, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PostServiceWithEmptyTagResponse, PostServiceWithEmptyTagResponse2, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, SchemaWithFormRestrictedKeys, SimpleBoolean, SimpleFile, SimpleFormData, SimpleInteger, SimpleParameter, SimpleReference, SimpleRequestBody, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses, UploadFileData, UploadFileResponse, UploadFileResponses, XFooBar } from './types.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts new file mode 100644 index 0000000000..e48dcff8cf --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts @@ -0,0 +1,206 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type Client, formDataBodySerializer, type Options as Options2, type TDataShape, urlSearchParamsBodySerializer } from './client'; +import { client } from './client.gen'; +import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponses, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponses, FooWowData, FooWowResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ImportData, ImportResponses, MultipartRequestData, MultipartResponseData, MultipartResponseResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses, UploadFileData, UploadFileResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export const export_ = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no+tag', ...options }); + +export const patchApiVbyApiVersionNoTag = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/no+tag', ...options }); + +export const import_ = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/no+tag', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const fooWow = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/no+tag', ...options }); + +export const apiVVersionODataControllerCount = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple/$count', ...options }); + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/simple:operation', ...options }); + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/simple', ...options }); + +export const getCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple', ...options }); + +export const headCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).head({ url: '/api/v{api-version}/simple', ...options }); + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).options({ url: '/api/v{api-version}/simple', ...options }); + +export const patchCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/simple', ...options }); + +export const postCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/simple', ...options }); + +export const putCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/simple', ...options }); + +export const deleteFoo = (options: Options) => (options.client ?? client).delete({ url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', ...options }); + +export const callWithDescriptions = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/descriptions', ...options }); + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/parameters/deprecated', ...options }); + +export const callWithParameters = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const callWithWeirdParameterNames = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const getCallWithOptionalParam = (options: Options) => (options.client ?? client).get({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const postCallWithOptionalParam = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const postApiVbyApiVersionRequestBody = (options?: Options) => (options?.client ?? client).post({ + url: '/api/v{api-version}/requestBody', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } +}); + +export const postApiVbyApiVersionFormData = (options?: Options) => (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/formData', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } +}); + +export const callWithDefaultParameters = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/defaults', ...options }); + +export const callWithDefaultOptionalParameters = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/defaults', ...options }); + +export const callToTestOrderOfParams = (options: Options) => (options.client ?? client).put({ url: '/api/v{api-version}/defaults', ...options }); + +export const duplicateName = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName2 = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName3 = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName4 = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/duplicate', ...options }); + +export const callWithNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no-content', ...options }); + +export const callWithResponseAndNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/response-and-no-content', ...options }); + +export const dummyA = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/a', ...options }); + +export const dummyB = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/b', ...options }); + +export const callWithResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/response', ...options }); + +export const callWithDuplicateResponses = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/response', ...options }); + +export const callWithResponses = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/response', ...options }); + +export const collectionFormat = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/collectionFormat', ...options }); + +export const types = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/types', ...options }); + +export const uploadFile = (options: Options) => (options.client ?? client).post({ + ...urlSearchParamsBodySerializer, + url: '/api/v{api-version}/upload', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } +}); + +export const fileResponse = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/file/{id}', ...options }); + +export const complexTypes = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterObject: { object: { style: 'form' } } } }, + url: '/api/v{api-version}/complex', + ...options +}); + +export const multipartResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multipart', ...options }); + +export const multipartRequest = (options?: Options) => (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/multipart', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } +}); + +export const complexParams = (options: Options) => (options.client ?? client).put({ + url: '/api/v{api-version}/complex/{id}', + ...options, + headers: { + 'Content-Type': 'application/json-patch+json', + ...options.headers + } +}); + +export const callWithResultFromHeader = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/header', ...options }); + +export const testErrorCode = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/error', ...options }); + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', ...options }); + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => (options.client ?? client).put({ + ...urlSearchParamsBodySerializer, + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts new file mode 100644 index 0000000000..d819316644 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts @@ -0,0 +1,2100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +/** + * Model with number-only name + */ +export type _400 = string; + +/** + * External ref to shared model (A) + */ +export type ExternalRefA = ExternalSharedModel; + +/** + * External ref to shared model (B) + */ +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CamelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = '\'Single Quote\'' | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: CamelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown | null; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type ModelFromZendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + /** + * Foo-Bar-Baz-Qux + */ + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind: 'circle'; +} & ModelCircle) | ({ + kind: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3eNum1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + /** + * Scopes + */ + propA?: Array<_3eNum1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type File = { + /** + * Id + */ + readonly id?: string; + /** + * Updated at + */ + readonly updated_at?: string; + /** + * Created at + */ + readonly created_at?: string; + /** + * Mime + */ + mime: string; + /** + * File + */ + readonly file?: string; +}; + +export type Default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { + [key: string]: unknown; +}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: null; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆøÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +/** + * An object with additional properties that can be null (anyOf ref + null) + */ +export type ModelWithAdditionalPropertiesRef = { + [key: string]: NullableObject | null; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = [ + ModelWithInteger, + number | string, + string +]; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | Import, + number | Import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆøÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type Import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: IoK8sApimachineryPkgApisMetaV1Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBoolean = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemString = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnlyWritable = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type FileWritable = { + /** + * Mime + */ + mime: string; +}; + +export type ModelWithReadOnlyAndWriteOnlyWritable = { + foo: string; + baz: string; +}; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = [ + number | Import, + number | Import +]; + +export type AdditionalPropertiesUnknownIssueWritable = { + [key: string]: string | number; +}; + +export type OneOfAllOfIssueWritable = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBooleanWritable = { + item?: boolean; + error?: string | null; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemStringWritable = { + item?: string | null; + error?: string | null; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type XFooBar = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + +export type ExportData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ImportData = { + body: ModelWithReadOnlyAndWriteOnlyWritable | ModelWithArrayReadOnlyAndWriteOnlyWritable; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type ImportResponses = { + /** + * Success + */ + 200: ModelFromZendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ApiVVersionODataControllerCountData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple/$count'; +}; + +export type ApiVVersionODataControllerCountResponses = { + /** + * Success + */ + 200: ModelFromZendesk; +}; + +export type ApiVVersionODataControllerCountResponse = ApiVVersionODataControllerCountResponses[keyof ApiVVersionODataControllerCountResponses]; + +export type GetApiVbyApiVersionSimpleOperationData = { + body?: never; + path: { + /** + * foo in method + */ + foo_param: string; + }; + query?: never; + url: '/api/v{api-version}/simple:operation'; +}; + +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type DeleteFooData3 = { + body?: never; + headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + path: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + query?: never; + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions'; +}; + +export type DeprecatedCallData = { + body?: never; + headers: { + /** + * This parameter is deprecated + * + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/parameters/deprecated'; +}; + +export type CallWithParametersData = { + /** + * This is the parameter that goes into the body + */ + body: { + [key: string]: unknown; + } | null; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that goes into the body + */ + body: ModelWithString | null; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is a required parameter + */ + body: ModelWithOneOfEnum; + path?: never; + query?: { + /** + * This is an optional parameter + */ + page?: number; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + body?: { + offset?: number | null; + }; + path?: never; + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; + +export type PostApiVbyApiVersionRequestBodyData = { + /** + * A reusable request body + */ + body?: SimpleRequestBody; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/requestBody'; +}; + +export type PostApiVbyApiVersionFormDataData = { + /** + * A reusable request body + */ + body?: SimpleFormData; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/formData'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; + +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + 200: _400; +}; + +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; + +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + default: Import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type UploadFileData = { + body: Blob | File; + path: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query?: never; + url: '/api/v{api-version}/upload'; +}; + +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; + +export type FileResponseData = { + body?: never; + path: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/file/{id}'; +}; + +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }; +}; + +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + +export type MultipartRequestData = { + body?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type ComplexParamsData = { + body?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + path: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/complex/{id}'; +}; + +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: number; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PutWithFormUrlEncodedData = { + body: ArrayWithStrings; + path?: never; + query?: never; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/useMutation/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-api-key/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-false/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-http-bearer/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-oauth2/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/security-open-id-connect/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/servers/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-angular/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-fetch/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-ofetch/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-tanstack-react-query/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-tanstack-react-query/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-tanstack-react-query/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-tanstack-react-query/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-additional-properties/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-additional-properties/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-additional-properties/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-additional-properties/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-all-of/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-allof-response-wrapper/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-allof-response-wrapper/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-allof-response-wrapper/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-allof-response-wrapper/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-any-of-null/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-array/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-one-of-discriminated/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-one-of-discriminated/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-one-of-discriminated/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-one-of-discriminated/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transformers-recursive/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/transforms-read-write/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/main/test/plugins.test.ts b/packages/openapi-ts-tests/main/test/plugins.test.ts index 426e15a52e..3b12d75297 100644 --- a/packages/openapi-ts-tests/main/test/plugins.test.ts +++ b/packages/openapi-ts-tests/main/test/plugins.test.ts @@ -332,6 +332,20 @@ for (const version of versions) { description: 'generate Fetch API client with TanStack React Query plugin with useMutation hooks', }, + { + config: createConfig({ + output: 'responseStyle', + plugins: [ + { + name: '@tanstack/react-query', + responseStyle: 'fields', + }, + '@hey-api/client-fetch', + ], + }), + description: + 'generate Fetch API client with TanStack React Query plugin with responseStyle fields', + }, { config: createConfig({ input: 'sdk-instance.yaml', diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/client.ts b/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/client.ts index 547b02dde7..4e5611e5a3 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/client.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-angular/bundle/client.ts @@ -176,6 +176,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/client.ts b/packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/client.ts index c15ee2091f..fed12cbb1c 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/client.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/client.ts @@ -228,6 +228,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-ky/bundle/client.ts b/packages/openapi-ts/src/plugins/@hey-api/client-ky/bundle/client.ts index 299538682e..fadc23f4f6 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-ky/bundle/client.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-ky/bundle/client.ts @@ -102,6 +102,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/client.ts b/packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/client.ts index e40e336bda..d39d803990 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/client.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/client.ts @@ -200,6 +200,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts b/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts index 9bdc87a121..8a4c68a85f 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts @@ -8,6 +8,7 @@ export const defaultConfig: TanStackAngularQueryPlugin['Config'] = { case: 'camelCase', comments: true, includeInEntry: false, + responseStyle: 'data', }, dependencies: ['@hey-api/sdk', '@hey-api/typescript'], handler: handler as TanStackAngularQueryPlugin['Handler'], diff --git a/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.ts b/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.ts index 8b8dc2904c..d03e06075b 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.ts @@ -284,6 +284,19 @@ export type UserConfig = Plugin.Name<'@tanstack/angular-query-experimental'> & */ name?: NameTransformer; }; + /** + * Style of response handling in generated query/mutation functions. + * + * `'data'` returns only the parsed response data (default, backwards compatible). + * `'fields'` returns `{ data, request, response }` on success and + * throws `{ error, request, response }` on errors, giving access to + * HTTP status codes, headers, and other response metadata. + * + * Can be overridden per-query by passing `responseStyle` in options. + * + * @default 'data' + */ + responseStyle?: 'data' | 'fields'; }; export type Config = Plugin.Name<'@tanstack/angular-query-experimental'> & @@ -426,6 +439,7 @@ export type Config = Plugin.Name<'@tanstack/angular-query-experimental'> & */ meta: (operation: IR.OperationObject) => Record; }; + responseStyle: 'data' | 'fields'; }; export type TanStackAngularQueryPlugin = DefinePlugin; diff --git a/packages/openapi-ts/src/plugins/@tanstack/preact-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/preact-query/config.ts index d72a8963aa..0a3f8723a8 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/preact-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/preact-query/config.ts @@ -8,6 +8,7 @@ export const defaultConfig: TanStackPreactQueryPlugin['Config'] = { case: 'camelCase', comments: true, includeInEntry: false, + responseStyle: 'data', }, dependencies: ['@hey-api/sdk', '@hey-api/typescript'], handler: handler as TanStackPreactQueryPlugin['Handler'], diff --git a/packages/openapi-ts/src/plugins/@tanstack/preact-query/types.ts b/packages/openapi-ts/src/plugins/@tanstack/preact-query/types.ts index bf48ffb24a..d0175101d5 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/preact-query/types.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/preact-query/types.ts @@ -292,6 +292,19 @@ export type UserConfig = Plugin.Name<'@tanstack/preact-query'> & */ name?: NameTransformer; }; + /** + * Style of response handling in generated query/mutation functions. + * + * `'data'` returns only the parsed response data (default, backwards compatible). + * `'fields'` returns `{ data, request, response }` on success and + * throws `{ error, request, response }` on errors, giving access to + * HTTP status codes, headers, and other response metadata. + * + * Can be overridden per-query by passing `responseStyle` in options. + * + * @default 'data' + */ + responseStyle?: 'data' | 'fields'; /** * Configuration for generated `useMutation()` function helpers. * @@ -511,6 +524,7 @@ export type Config = Plugin.Name<'@tanstack/preact-query'> & */ meta: (operation: IR.OperationObject) => Record; }; + responseStyle: 'data' | 'fields'; /** * Configuration for generated `useMutation()` function helpers. * diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts index 4b124afa23..caa8ba0fa1 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts @@ -91,6 +91,9 @@ const createInfiniteParamsFunction = ({ plugin }: { plugin: PluginInstance }) => plugin.node(fn); }; +const TStyle = 'TStyle'; +const styleUnion = () => $.type.or($.type.literal('data'), $.type.literal('fields')); + export const createInfiniteQueryOptions = ({ operation, plugin, @@ -138,6 +141,7 @@ export const createInfiniteQueryOptions = ({ const typeData = useTypeData({ operation, plugin }); const typeResponse = useTypeResponse({ operation, plugin }); + const typeError = useTypeError({ operation, plugin }); const symbolQueryKeyType = plugin.referenceSymbol({ category: 'type', @@ -169,90 +173,205 @@ export const createInfiniteQueryOptions = ({ }); plugin.node(node); - const awaitSdkFn = $.lazy((ctx) => - ctx - .access( - plugin.referenceSymbol({ - category: 'sdk', - resource: 'operation', - resourceId: operation.id, - }), - ) - .call( - $.object() - .spread('options') - .spread('params') - .prop('signal', $('signal')) - .prop('throwOnError', $.literal(true)), - ) - .await(), - ); - const symbolCreateInfiniteParams = plugin.referenceSymbol({ category: 'utility', resource: 'createInfiniteParams', tool: plugin.name, }); - const statements: Array> = [ - $.const('page') - .type(typePageObjectParam) - .hint('@ts-ignore') - .assign( - $.ternary($('pageParam').typeofExpr().eq($.literal('object'))) - .do('pageParam') - .otherwise( - $.object() - .pretty() - .prop(pagination.in, $.object().pretty().prop(pagination.name, $('pageParam'))), - ), - ), - $.const('params').assign($(symbolCreateInfiniteParams).call('queryKey', 'page')), - ]; + if (plugin.config.responseStyle === 'fields') { + // --- 'fields' code path: TStyle generic, ResponseResult/ResponseError wrappers --- + const defaultStyle = plugin.config.responseStyle; - if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { - statements.push($.return(awaitSdkFn)); - } else { - statements.push($.const().object('data').assign(awaitSdkFn), $.return('data')); - } + const symbolResponseResult = plugin.referenceSymbol({ + category: 'type', + resource: 'ResponseResult', + tool: plugin.name, + }); + const symbolResponseError = plugin.referenceSymbol({ + category: 'type', + resource: 'ResponseError', + tool: plugin.name, + }); - const symbolInfiniteQueryOptionsFn = plugin.symbol( - applyNaming(operation.id, plugin.config.infiniteQueryOptions), - ); - const statement = $.const(symbolInfiniteQueryOptionsFn) - .export() - .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) - .assign( - $.func() - .param('options', (p) => p.required(isRequiredOptions).type(typeData)) - .do( - $.return( - $(symbolInfiniteQueryOptions) - .call( - $.object() - .pretty() - .hint('@ts-ignore') - .prop( - 'queryFn', - $.func() - .async() - .param((p) => p.object('pageParam', 'queryKey', 'signal')) - .do(...statements), - ) - .prop('queryKey', $(symbolInfiniteQueryKey).call('options')) - .$if(handleMeta(plugin, operation, 'infiniteQueryOptions'), (o, v) => - o.prop('meta', v), - ), - ) - .generics( - typeResponse, - useTypeError({ operation, plugin }), - $.type(symbolInfiniteDataType).generic(typeResponse), - typeQueryKey, - $.type.or(type, typePageObjectParam), + const typeResponseResult = $.type(symbolResponseResult).generic(typeResponse).generic(TStyle); + const typeResponseError = $.type(symbolResponseError).generic(typeError).generic(TStyle); + + const awaitSdkFn = $.lazy((ctx) => + ctx + .access( + plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }), + ) + .call( + $.object() + .spread('options') + .spread('params') + .prop('signal', $('signal')) + .prop('throwOnError', $.literal(true)) + .prop('responseStyle', $.literal('fields')), + ) + .await(), + ); + + const statements: Array> = [ + $.const('page') + .type(typePageObjectParam) + .hint('@ts-ignore') + .assign( + $.ternary($('pageParam').typeofExpr().eq($.literal('object'))) + .do('pageParam') + .otherwise( + $.object() + .pretty() + .prop(pagination.in, $.object().pretty().prop(pagination.name, $('pageParam'))), + ), + ), + $.const('params').assign($(symbolCreateInfiniteParams).call('queryKey', 'page')), + ]; + + // Always assign full result, then conditionally return based on responseStyle + statements.push( + $.const('result').assign(awaitSdkFn), + $.const('_data').assign( + $.ternary($('options').attr('responseStyle').optional().eq($.literal('fields'))) + .do('result') + .otherwise($('result').attr('data')), + ), + $.return($.as($('_data'), typeResponseResult)), + ); + + const symbolInfiniteQueryOptionsFn = plugin.symbol( + applyNaming(operation.id, plugin.config.infiniteQueryOptions), + ); + const statement = $.const(symbolInfiniteQueryOptionsFn) + .export() + .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) + .assign( + $.func() + .generic(TStyle, (g) => g.extends(styleUnion()).default($.type.literal(defaultStyle))) + .param('options', (p) => + p.required(isRequiredOptions).type( + $.type.and( + typeData, + $.type.object().prop('responseStyle', (tp) => tp.optional().type(TStyle)), ), + ), + ) + .do( + $.return( + $(symbolInfiniteQueryOptions) + .call( + $.object() + .pretty() + .hint('@ts-ignore') + .prop( + 'queryFn', + $.func() + .async() + .param((p) => p.object('pageParam', 'queryKey', 'signal')) + .do(...statements), + ) + .prop('queryKey', $(symbolInfiniteQueryKey).call('options')) + .$if(handleMeta(plugin, operation, 'infiniteQueryOptions'), (o, v) => + o.prop('meta', v), + ), + ) + .generics( + typeResponseResult, + typeResponseError, + $.type(symbolInfiniteDataType).generic(typeResponseResult), + typeQueryKey, + $.type.or(type, typePageObjectParam), + ), + ), ), + ); + plugin.node(statement); + } else { + // --- 'data' code path (default): original code, no TStyle, no ResponseResult/ResponseError --- + const awaitSdkFn = $.lazy((ctx) => + ctx + .access( + plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }), + ) + .call( + $.object() + .spread('options') + .spread('params') + .prop('signal', $('signal')) + .prop('throwOnError', $.literal(true)), + ) + .await(), + ); + + const statements: Array> = [ + $.const('page') + .type(typePageObjectParam) + .hint('@ts-ignore') + .assign( + $.ternary($('pageParam').typeofExpr().eq($.literal('object'))) + .do('pageParam') + .otherwise( + $.object() + .pretty() + .prop(pagination.in, $.object().pretty().prop(pagination.name, $('pageParam'))), + ), ), + $.const('params').assign($(symbolCreateInfiniteParams).call('queryKey', 'page')), + ]; + + if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { + statements.push($.return(awaitSdkFn)); + } else { + statements.push($.const().object('data').assign(awaitSdkFn), $.return('data')); + } + + const symbolInfiniteQueryOptionsFn = plugin.symbol( + applyNaming(operation.id, plugin.config.infiniteQueryOptions), ); - plugin.node(statement); + const statement = $.const(symbolInfiniteQueryOptionsFn) + .export() + .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) + .assign( + $.func() + .param('options', (p) => p.required(isRequiredOptions).type(typeData)) + .do( + $.return( + $(symbolInfiniteQueryOptions) + .call( + $.object() + .pretty() + .hint('@ts-ignore') + .prop( + 'queryFn', + $.func() + .async() + .param((p) => p.object('pageParam', 'queryKey', 'signal')) + .do(...statements), + ) + .prop('queryKey', $(symbolInfiniteQueryKey).call('options')) + .$if(handleMeta(plugin, operation, 'infiniteQueryOptions'), (o, v) => + o.prop('meta', v), + ), + ) + .generics( + typeResponse, + useTypeError({ operation, plugin }), + $.type(symbolInfiniteDataType).generic(typeResponse), + typeQueryKey, + $.type.or(type, typePageObjectParam), + ), + ), + ), + ); + plugin.node(statement); + } }; diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts index 0b055050ab..1cff76bbca 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts @@ -11,6 +11,9 @@ import { handleMeta } from '../shared/meta'; import { useTypeData, useTypeError, useTypeResponse } from '../shared/useType'; import type { PluginInstance } from '../types'; +const TStyle = 'TStyle'; +const styleUnion = () => $.type.or($.type.literal('data'), $.type.literal('fields')); + export const createMutationOptions = ({ operation, plugin, @@ -25,70 +28,182 @@ export const createMutationOptions = ({ const symbolMutationOptionsType = plugin.external(`${plugin.name}.MutationOptions`); const typeData = useTypeData({ operation, plugin }); - const mutationType = $.type(symbolMutationOptionsType) - .generic(useTypeResponse({ operation, plugin })) - .generic(useTypeError({ operation, plugin })) - .generic(typeData); - - const fnOptions = 'fnOptions'; - - const awaitSdkFn = $.lazy((ctx) => - ctx - .access( - plugin.referenceSymbol({ - category: 'sdk', + const typeResponse = useTypeResponse({ operation, plugin }); + const typeError = useTypeError({ operation, plugin }); + + if (plugin.config.responseStyle === 'fields') { + // --- 'fields' code path: TStyle generic, ResponseResult/ResponseError wrappers --- + const defaultStyle = plugin.config.responseStyle; + + const symbolResponseResult = plugin.referenceSymbol({ + category: 'type', + resource: 'ResponseResult', + tool: plugin.name, + }); + const symbolResponseError = plugin.referenceSymbol({ + category: 'type', + resource: 'ResponseError', + tool: plugin.name, + }); + + const typeResponseResult = $.type(symbolResponseResult).generic(typeResponse).generic(TStyle); + const typeResponseError = $.type(symbolResponseError).generic(typeError).generic(TStyle); + + const mutationType = $.type(symbolMutationOptionsType) + .generic(typeResponseResult) + .generic(typeResponseError) + .generic(typeData); + + const fnOptions = 'fnOptions'; + + const awaitSdkFn = $.lazy((ctx) => + ctx + .access( + plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }), + ) + .call( + $.object() + .spread('options') + .spread(fnOptions) + .prop('throwOnError', $.literal(true)) + .prop('responseStyle', $.literal('fields')), + ) + .await(), + ); + + // Always assign full result, then conditionally return based on responseStyle + const statements: Array> = [ + $.const('result').assign(awaitSdkFn), + $.const('_data').assign( + $.ternary($('options').attr('responseStyle').optional().eq($.literal('fields'))) + .do('result') + .otherwise($('result').attr('data')), + ), + $.return($.as($('_data'), typeResponseResult)), + ]; + + const mutationOptionsFn = 'mutationOptions'; + const symbolMutationOptions = plugin.symbol( + applyNaming(operation.id, plugin.config.mutationOptions), + { + meta: { + category: 'hook', resource: 'operation', resourceId: operation.id, - }), - ) - .call($.object().spread('options').spread(fnOptions).prop('throwOnError', $.literal(true))) - .await(), - ); - - const statements: Array> = []; - if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { - statements.push($.return(awaitSdkFn)); + role: 'mutationOptions', + tool: plugin.name, + }, + }, + ); + const statement = $.const(symbolMutationOptions) + .export(plugin.config.mutationOptions.exported) + .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) + .assign( + $.func() + .generic(TStyle, (g) => g.extends(styleUnion()).default($.type.literal(defaultStyle))) + .param('options', (p) => + p.optional().type( + $.type.and( + $.type('Partial').generic(typeData), + $.type.object().prop('responseStyle', (tp) => tp.optional().type(TStyle)), + ), + ), + ) + .returns(mutationType) + .do( + $.const(mutationOptionsFn) + .type(mutationType) + .assign( + $.object() + .pretty() + .prop( + 'mutationFn', + $.func() + .async() + .param(fnOptions) + .do(...statements), + ) + .$if(handleMeta(plugin, operation, 'mutationOptions'), (c, v) => + c.prop('meta', v), + ), + ), + $(mutationOptionsFn).return(), + ), + ); + plugin.node(statement); } else { - statements.push($.const().object('data').assign(awaitSdkFn), $.return('data')); - } + // --- 'data' code path (default): original code, no TStyle, no ResponseResult/ResponseError --- + const mutationType = $.type(symbolMutationOptionsType) + .generic(typeResponse) + .generic(typeError) + .generic(typeData); + + const fnOptions = 'fnOptions'; + + const awaitSdkFn = $.lazy((ctx) => + ctx + .access( + plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }), + ) + .call($.object().spread('options').spread(fnOptions).prop('throwOnError', $.literal(true))) + .await(), + ); - const mutationOptionsFn = 'mutationOptions'; - const symbolMutationOptions = plugin.symbol( - applyNaming(operation.id, plugin.config.mutationOptions), - { - meta: { - category: 'hook', - resource: 'operation', - resourceId: operation.id, - role: 'mutationOptions', - tool: plugin.name, + const statements: Array> = []; + if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { + statements.push($.return(awaitSdkFn)); + } else { + statements.push($.const().object('data').assign(awaitSdkFn), $.return('data')); + } + + const mutationOptionsFn = 'mutationOptions'; + const symbolMutationOptions = plugin.symbol( + applyNaming(operation.id, plugin.config.mutationOptions), + { + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'mutationOptions', + tool: plugin.name, + }, }, - }, - ); - const statement = $.const(symbolMutationOptions) - .export(plugin.config.mutationOptions.exported) - .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) - .assign( - $.func() - .param('options', (p) => p.optional().type($.type('Partial').generic(typeData))) - .returns(mutationType) - .do( - $.const(mutationOptionsFn) - .type(mutationType) - .assign( - $.object() - .pretty() - .prop( - 'mutationFn', - $.func() - .async() - .param(fnOptions) - .do(...statements), - ) - .$if(handleMeta(plugin, operation, 'mutationOptions'), (c, v) => c.prop('meta', v)), - ), - $(mutationOptionsFn).return(), - ), ); - plugin.node(statement); + const statement = $.const(symbolMutationOptions) + .export() + .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) + .assign( + $.func() + .param('options', (p) => p.optional().type($.type('Partial').generic(typeData))) + .returns(mutationType) + .do( + $.const(mutationOptionsFn) + .type(mutationType) + .assign( + $.object() + .pretty() + .prop( + 'mutationFn', + $.func() + .async() + .param(fnOptions) + .do(...statements), + ) + .$if(handleMeta(plugin, operation, 'mutationOptions'), (c, v) => + c.prop('meta', v), + ), + ), + $(mutationOptionsFn).return(), + ), + ); + plugin.node(statement); + } }; diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts index 39a29e4b46..7e07aa3a9f 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts @@ -1,10 +1,132 @@ -import type { PluginHandler } from '../types'; +import ts from 'typescript'; + +import { TsDsl } from '../../../../ts-dsl'; +import { $ } from '../../../../ts-dsl'; +import type { PluginHandler, PluginInstance } from '../types'; import { createInfiniteQueryOptions } from './infiniteQueryOptions'; import { createMutationOptions } from './mutationOptions'; import { createQueryOptions } from './queryOptions'; import { createUseMutation } from './useMutation'; import { createUseQuery } from './useQuery'; +/** + * A minimal TsDsl wrapper that emits a pre-built ts.TypeNode. + * Used for conditional types which the DSL doesn't natively support. + */ +class RawTypeTsDsl extends TsDsl { + readonly '~dsl' = 'RawTypeTsDsl'; + + constructor(private readonly _node: ts.TypeNode) { + super(); + } + + override toAst() { + return this._node; + } +} + +/** + * Creates a conditional type node: + * `TStyle extends 'fields' ? trueType : falseType` + */ +const createConditionalType = ( + checkType: string, + extendsLiteral: string, + trueType: ts.TypeNode, + falseType: ts.TypeNode, +): RawTypeTsDsl => + new RawTypeTsDsl( + ts.factory.createConditionalTypeNode( + ts.factory.createTypeReferenceNode(checkType), + ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(extendsLiteral)), + trueType, + falseType, + ), + ); + +/** + * Creates a type object `{ data: TData; request: Request; response: Response }` or + * `{ error: TError; request: Request; response: Response }` as a raw ts.TypeNode. + */ +const createFieldsObjectType = (fieldName: string, typeParamName: string): ts.TypeNode => + ts.factory.createTypeLiteralNode([ + ts.factory.createPropertySignature( + undefined, + fieldName, + undefined, + ts.factory.createTypeReferenceNode(typeParamName), + ), + ts.factory.createPropertySignature( + undefined, + 'request', + undefined, + ts.factory.createTypeReferenceNode('Request'), + ), + ts.factory.createPropertySignature( + undefined, + 'response', + undefined, + ts.factory.createTypeReferenceNode('Response'), + ), + ]); + +const createResponseStyleTypes = (defaultStyle: 'data' | 'fields', plugin: PluginInstance) => { + const TData = 'TData'; + const TError = 'TError'; + const TStyle = 'TStyle'; + const styleUnion = $.type.or($.type.literal('data'), $.type.literal('fields')); + + // ResponseResult = + // TStyle extends 'fields' + // ? { data: TData; request: Request; response: Response } + // : TData; + const symbolResponseResult = plugin.symbol('ResponseResult', { + meta: { + category: 'type', + resource: 'ResponseResult', + tool: plugin.name, + }, + }); + const responseResultType = $.type + .alias(symbolResponseResult) + .generic(TData) + .generic(TStyle, (g) => g.extends(styleUnion).default($.type.literal(defaultStyle))) + .type( + createConditionalType( + TStyle, + 'fields', + createFieldsObjectType('data', TData), + ts.factory.createTypeReferenceNode(TData), + ), + ); + plugin.node(responseResultType); + + // ResponseError = + // TStyle extends 'fields' + // ? { error: TError; request: Request; response: Response } + // : TError; + const symbolResponseError = plugin.symbol('ResponseError', { + meta: { + category: 'type', + resource: 'ResponseError', + tool: plugin.name, + }, + }); + const responseErrorType = $.type + .alias(symbolResponseError) + .generic(TError) + .generic(TStyle, (g) => g.extends(styleUnion).default($.type.literal(defaultStyle))) + .type( + createConditionalType( + TStyle, + 'fields', + createFieldsObjectType('error', TError), + ts.factory.createTypeReferenceNode(TError), + ), + ); + plugin.node(responseErrorType); +}; + export const handlerV5: PluginHandler = ({ plugin }) => { plugin.symbol('DefaultError', { external: plugin.name, @@ -44,6 +166,11 @@ export const handlerV5: PluginHandler = ({ plugin }) => { kind: 'type', }); + // Generate ResponseResult and ResponseError utility types only when responseStyle is 'fields' + if (plugin.config.responseStyle === 'fields') { + createResponseStyleTypes(plugin.config.responseStyle, plugin); + } + plugin.forEach( 'operation', ({ operation }) => { diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts index 01fc9ac80e..28dca70a02 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts @@ -14,6 +14,8 @@ import { useTypeData, useTypeError, useTypeResponse } from '../shared/useType'; import type { PluginInstance } from '../types'; const optionsParamName = 'options'; +const TStyle = 'TStyle'; +const styleUnion = () => $.type.or($.type.literal('data'), $.type.literal('fields')); export const createQueryOptions = ({ operation, @@ -54,78 +56,186 @@ export const createQueryOptions = ({ plugin.node(node); const typeResponse = useTypeResponse({ operation, plugin }); + const typeError = useTypeError({ operation, plugin }); - const awaitSdkFn = $.lazy((ctx) => - ctx - .access( - plugin.referenceSymbol({ - category: 'sdk', - resource: 'operation', - resourceId: operation.id, - }), - ) - .call( - $.object() - .spread(optionsParamName) - .spread($('queryKey').attr(0)) - .prop('signal', $('signal')) - .prop('throwOnError', $.literal(true)), + if (plugin.config.responseStyle === 'fields') { + // --- 'fields' code path: TStyle generic, ResponseResult/ResponseError wrappers --- + const defaultStyle = plugin.config.responseStyle; + + const symbolResponseResult = plugin.referenceSymbol({ + category: 'type', + resource: 'ResponseResult', + tool: plugin.name, + }); + const symbolResponseError = plugin.referenceSymbol({ + category: 'type', + resource: 'ResponseError', + tool: plugin.name, + }); + + const typeResponseResult = $.type(symbolResponseResult).generic(typeResponse).generic(TStyle); + const typeResponseError = $.type(symbolResponseError).generic(typeError).generic(TStyle); + + const awaitSdkFn = $.lazy((ctx) => + ctx + .access( + plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }), + ) + .call( + $.object() + .spread(optionsParamName) + .spread($('queryKey').attr(0)) + .prop('signal', $('signal')) + .prop('throwOnError', $.literal(true)) + .prop('responseStyle', $.literal('fields')), + ) + .await(), + ); + + // Always assign full result, then conditionally return based on responseStyle + const statements: Array> = [ + $.const('result').assign(awaitSdkFn), + $.const('_data').assign( + $.ternary($(optionsParamName).attr('responseStyle').optional().eq($.literal('fields'))) + .do('result') + .otherwise($('result').attr('data')), + ), + $.return($.as($('_data'), typeResponseResult)), + ]; + + const queryOptionsObj = $.object() + .pretty() + .prop( + 'queryFn', + $.func() + .async() + .param((p) => p.object('queryKey', 'signal')) + .do(...statements), ) - .await(), - ); + .prop('queryKey', $(symbolQueryKey).call(optionsParamName)) + .$if(handleMeta(plugin, operation, 'queryOptions'), (o, v) => o.prop('meta', v)); - const statements: Array> = []; - if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { - statements.push($.return(awaitSdkFn)); - } else { - statements.push($.const().object('data').assign(awaitSdkFn), $.return('data')); - } + const typeData = useTypeData({ operation, plugin }); - const queryOptionsObj = $.object() - .pretty() - .prop( - 'queryFn', - $.func() - .async() - .param((p) => p.object('queryKey', 'signal')) - .do(...statements), - ) - .prop('queryKey', $(symbolQueryKey).call(optionsParamName)) - .$if(handleMeta(plugin, operation, 'queryOptions'), (o, v) => o.prop('meta', v)); - - const symbolQueryOptionsFn = plugin.symbol( - applyNaming(operation.id, plugin.config.queryOptions), - { - meta: { - category: 'hook', - resource: 'operation', - resourceId: operation.id, - role: 'queryOptions', - tool: plugin.name, + const symbolQueryOptionsFn = plugin.symbol( + applyNaming(operation.id, plugin.config.queryOptions), + { + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'queryOptions', + tool: plugin.name, + }, }, - }, - ); - // TODO: add type error - // TODO: AxiosError - const statement = $.const(symbolQueryOptionsFn) - .export(plugin.config.queryOptions.exported) - .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) - .assign( - $.func() - .param(optionsParamName, (p) => - p.required(isRequiredOptions).type(useTypeData({ operation, plugin })), + ); + // TODO: add type error + // TODO: AxiosError + const statement = $.const(symbolQueryOptionsFn) + .export(plugin.config.queryOptions.exported) + .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) + .assign( + $.func() + .generic(TStyle, (g) => g.extends(styleUnion()).default($.type.literal(defaultStyle))) + .param(optionsParamName, (p) => + p.required(isRequiredOptions).type( + $.type.and( + typeData, + $.type.object().prop('responseStyle', (tp) => tp.optional().type(TStyle)), + ), + ), + ) + .do( + $(symbolQueryOptions) + .call(queryOptionsObj) + .generics( + typeResponseResult, + typeResponseError, + typeResponseResult, + $(symbolQueryKey).returnType(), + ) + .return(), + ), + ); + plugin.node(statement); + } else { + // --- 'data' code path (default): original code, no TStyle, no ResponseResult/ResponseError --- + const awaitSdkFn = $.lazy((ctx) => + ctx + .access( + plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }), ) - .do( - $(symbolQueryOptions) - .call(queryOptionsObj) - .generics( - typeResponse, - useTypeError({ operation, plugin }), - typeResponse, - $(symbolQueryKey).returnType(), - ) - .return(), - ), + .call( + $.object() + .spread(optionsParamName) + .spread($('queryKey').attr(0)) + .prop('signal', $('signal')) + .prop('throwOnError', $.literal(true)), + ) + .await(), + ); + + const statements: Array> = []; + if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { + statements.push($.return(awaitSdkFn)); + } else { + statements.push($.const().object('data').assign(awaitSdkFn), $.return('data')); + } + + const queryOptionsObj = $.object() + .pretty() + .prop( + 'queryFn', + $.func() + .async() + .param((p) => p.object('queryKey', 'signal')) + .do(...statements), + ) + .prop('queryKey', $(symbolQueryKey).call(optionsParamName)) + .$if(handleMeta(plugin, operation, 'queryOptions'), (o, v) => o.prop('meta', v)); + + const symbolQueryOptionsFn = plugin.symbol( + applyNaming(operation.id, plugin.config.queryOptions), + { + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'queryOptions', + tool: plugin.name, + }, + }, ); - plugin.node(statement); + // TODO: add type error + // TODO: AxiosError + const statement = $.const(symbolQueryOptionsFn) + .export(plugin.config.queryOptions.exported) + .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) + .assign( + $.func() + .param(optionsParamName, (p) => + p.required(isRequiredOptions).type(useTypeData({ operation, plugin })), + ) + .do( + $(symbolQueryOptions) + .call(queryOptionsObj) + .generics( + typeResponse, + useTypeError({ operation, plugin }), + typeResponse, + $(symbolQueryKey).returnType(), + ) + .return(), + ), + ); + plugin.node(statement); + } }; diff --git a/packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts index 41ee1f1fa4..4b32f35bcb 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts @@ -8,6 +8,7 @@ export const defaultConfig: TanStackReactQueryPlugin['Config'] = { case: 'camelCase', comments: true, includeInEntry: false, + responseStyle: 'data', }, dependencies: ['@hey-api/sdk', '@hey-api/typescript'], handler: handler as TanStackReactQueryPlugin['Handler'], diff --git a/packages/openapi-ts/src/plugins/@tanstack/react-query/types.ts b/packages/openapi-ts/src/plugins/@tanstack/react-query/types.ts index 7022351dc2..0c82a3e57b 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/react-query/types.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/react-query/types.ts @@ -292,6 +292,19 @@ export type UserConfig = Plugin.Name<'@tanstack/react-query'> & */ name?: NameTransformer; }; + /** + * Style of response handling in generated query/mutation functions. + * + * `'data'` returns only the parsed response data (default, backwards compatible). + * `'fields'` returns `{ data, request, response }` on success and + * throws `{ error, request, response }` on errors, giving access to + * HTTP status codes, headers, and other response metadata. + * + * Can be overridden per-query by passing `responseStyle` in options. + * + * @default 'data' + */ + responseStyle?: 'data' | 'fields'; /** * Configuration for generated `useMutation()` function helpers. * @@ -511,6 +524,7 @@ export type Config = Plugin.Name<'@tanstack/react-query'> & */ meta: (operation: IR.OperationObject) => Record; }; + responseStyle: 'data' | 'fields'; /** * Configuration for generated `useMutation()` function helpers. * diff --git a/packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts index 110c3b96a9..61c9fe522b 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts @@ -8,6 +8,7 @@ export const defaultConfig: TanStackSolidQueryPlugin['Config'] = { case: 'camelCase', comments: true, includeInEntry: false, + responseStyle: 'data', }, dependencies: ['@hey-api/sdk', '@hey-api/typescript'], handler: handler as TanStackSolidQueryPlugin['Handler'], diff --git a/packages/openapi-ts/src/plugins/@tanstack/solid-query/types.ts b/packages/openapi-ts/src/plugins/@tanstack/solid-query/types.ts index 99be2349a2..a80379c3e9 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/solid-query/types.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/solid-query/types.ts @@ -291,6 +291,19 @@ export type UserConfig = Plugin.Name<'@tanstack/solid-query'> & */ name?: NameTransformer; }; + /** + * Style of response handling in generated query/mutation functions. + * + * `'data'` returns only the parsed response data (default, backwards compatible). + * `'fields'` returns `{ data, request, response }` on success and + * throws `{ error, request, response }` on errors, giving access to + * HTTP status codes, headers, and other response metadata. + * + * Can be overridden per-query by passing `responseStyle` in options. + * + * @default 'data' + */ + responseStyle?: 'data' | 'fields'; }; export type Config = Plugin.Name<'@tanstack/solid-query'> & @@ -433,6 +446,7 @@ export type Config = Plugin.Name<'@tanstack/solid-query'> & */ meta: (operation: IR.OperationObject) => Record; }; + responseStyle: 'data' | 'fields'; }; export type TanStackSolidQueryPlugin = DefinePlugin; diff --git a/packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts index c7247c4fb7..18e5e8f392 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts @@ -8,6 +8,7 @@ export const defaultConfig: TanStackSvelteQueryPlugin['Config'] = { case: 'camelCase', comments: true, includeInEntry: false, + responseStyle: 'data', }, dependencies: ['@hey-api/sdk', '@hey-api/typescript'], handler: handler as TanStackSvelteQueryPlugin['Handler'], diff --git a/packages/openapi-ts/src/plugins/@tanstack/svelte-query/types.ts b/packages/openapi-ts/src/plugins/@tanstack/svelte-query/types.ts index 1c28f535dd..bb162d5bd8 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/svelte-query/types.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/svelte-query/types.ts @@ -290,6 +290,19 @@ export type UserConfig = Plugin.Name<'@tanstack/svelte-query'> & */ name?: NameTransformer; }; + /** + * Style of response handling in generated query/mutation functions. + * + * `'data'` returns only the parsed response data (default, backwards compatible). + * `'fields'` returns `{ data, request, response }` on success and + * throws `{ error, request, response }` on errors, giving access to + * HTTP status codes, headers, and other response metadata. + * + * Can be overridden per-query by passing `responseStyle` in options. + * + * @default 'data' + */ + responseStyle?: 'data' | 'fields'; }; export type Config = Plugin.Name<'@tanstack/svelte-query'> & @@ -432,6 +445,7 @@ export type Config = Plugin.Name<'@tanstack/svelte-query'> & */ meta: (operation: IR.OperationObject) => Record; }; + responseStyle: 'data' | 'fields'; }; export type TanStackSvelteQueryPlugin = DefinePlugin; diff --git a/packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts b/packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts index 4159f65499..ef06e667c7 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts @@ -8,6 +8,7 @@ export const defaultConfig: TanStackVueQueryPlugin['Config'] = { case: 'camelCase', comments: true, includeInEntry: false, + responseStyle: 'data', }, dependencies: ['@hey-api/sdk', '@hey-api/typescript'], handler: handler as TanStackVueQueryPlugin['Handler'], diff --git a/packages/openapi-ts/src/plugins/@tanstack/vue-query/types.ts b/packages/openapi-ts/src/plugins/@tanstack/vue-query/types.ts index 9a8b8338c6..c11f1709aa 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/vue-query/types.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/vue-query/types.ts @@ -293,6 +293,19 @@ export type UserConfig = Plugin.Name<'@tanstack/vue-query'> & */ name?: NameTransformer; }; + /** + * Style of response handling in generated query/mutation functions. + * + * `'data'` returns only the parsed response data (default, backwards compatible). + * `'fields'` returns `{ data, request, response }` on success and + * throws `{ error, request, response }` on errors, giving access to + * HTTP status codes, headers, and other response metadata. + * + * Can be overridden per-query by passing `responseStyle` in options. + * + * @default 'data' + */ + responseStyle?: 'data' | 'fields'; }; export type Config = Plugin.Name<'@tanstack/vue-query'> & @@ -438,6 +451,7 @@ export type Config = Plugin.Name<'@tanstack/vue-query'> & */ meta: (operation: IR.OperationObject) => Record; }; + responseStyle: 'data' | 'fields'; }; export type TanStackVueQueryPlugin = DefinePlugin; From 0603f323f5bae754ac5614c82f13a598456ba71d Mon Sep 17 00:00:00 2001 From: Jorrin Date: Sat, 28 Mar 2026 02:01:29 +0100 Subject: [PATCH 2/8] chore: regenerate example clients Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/client/client/client.gen.ts | 6 ++++++ examples/openapi-ts-angular/src/client/client/client.gen.ts | 6 ++++++ examples/openapi-ts-fastify/src/client/client/client.gen.ts | 6 ++++++ examples/openapi-ts-fetch/src/client/client/client.gen.ts | 6 ++++++ examples/openapi-ts-ky/src/client/client/client.gen.ts | 6 ++++++ examples/openapi-ts-nestjs/src/client/client/client.gen.ts | 6 ++++++ examples/openapi-ts-ofetch/src/client/client/client.gen.ts | 6 ++++++ examples/openapi-ts-openai/src/client/client/client.gen.ts | 6 ++++++ .../openapi-ts-pinia-colada/src/client/client/client.gen.ts | 6 ++++++ .../src/client/client/client.gen.ts | 6 ++++++ .../src/client/client/client.gen.ts | 6 ++++++ .../src/client/client/client.gen.ts | 6 ++++++ .../src/client/client/client.gen.ts | 6 ++++++ 13 files changed, 78 insertions(+) diff --git a/examples/openapi-ts-angular-common/src/client/client/client.gen.ts b/examples/openapi-ts-angular-common/src/client/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/examples/openapi-ts-angular-common/src/client/client/client.gen.ts +++ b/examples/openapi-ts-angular-common/src/client/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-angular/src/client/client/client.gen.ts b/examples/openapi-ts-angular/src/client/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/examples/openapi-ts-angular/src/client/client/client.gen.ts +++ b/examples/openapi-ts-angular/src/client/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-fastify/src/client/client/client.gen.ts b/examples/openapi-ts-fastify/src/client/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/examples/openapi-ts-fastify/src/client/client/client.gen.ts +++ b/examples/openapi-ts-fastify/src/client/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-fetch/src/client/client/client.gen.ts b/examples/openapi-ts-fetch/src/client/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/examples/openapi-ts-fetch/src/client/client/client.gen.ts +++ b/examples/openapi-ts-fetch/src/client/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-ky/src/client/client/client.gen.ts b/examples/openapi-ts-ky/src/client/client/client.gen.ts index 6626a526bd..cea83c69a1 100644 --- a/examples/openapi-ts-ky/src/client/client/client.gen.ts +++ b/examples/openapi-ts-ky/src/client/client/client.gen.ts @@ -110,6 +110,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-nestjs/src/client/client/client.gen.ts b/examples/openapi-ts-nestjs/src/client/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/examples/openapi-ts-nestjs/src/client/client/client.gen.ts +++ b/examples/openapi-ts-nestjs/src/client/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-ofetch/src/client/client/client.gen.ts b/examples/openapi-ts-ofetch/src/client/client/client.gen.ts index 4007f4f4c0..b8fa85bb6a 100644 --- a/examples/openapi-ts-ofetch/src/client/client/client.gen.ts +++ b/examples/openapi-ts-ofetch/src/client/client/client.gen.ts @@ -202,6 +202,12 @@ export const createClient = (config: Config = {}): Client => { finalError = (finalError as any) || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-openai/src/client/client/client.gen.ts b/examples/openapi-ts-openai/src/client/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/examples/openapi-ts-openai/src/client/client/client.gen.ts +++ b/examples/openapi-ts-openai/src/client/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-pinia-colada/src/client/client/client.gen.ts b/examples/openapi-ts-pinia-colada/src/client/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/examples/openapi-ts-pinia-colada/src/client/client/client.gen.ts +++ b/examples/openapi-ts-pinia-colada/src/client/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/client.gen.ts b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/client.gen.ts index 20c65b3927..0f3c216400 100644 --- a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/client.gen.ts +++ b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/client/client.gen.ts @@ -178,6 +178,12 @@ export const createClient = (config: Config = {}): Client => { } if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-tanstack-react-query/src/client/client/client.gen.ts b/examples/openapi-ts-tanstack-react-query/src/client/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/examples/openapi-ts-tanstack-react-query/src/client/client/client.gen.ts +++ b/examples/openapi-ts-tanstack-react-query/src/client/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-tanstack-svelte-query/src/client/client/client.gen.ts b/examples/openapi-ts-tanstack-svelte-query/src/client/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/examples/openapi-ts-tanstack-svelte-query/src/client/client/client.gen.ts +++ b/examples/openapi-ts-tanstack-svelte-query/src/client/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/examples/openapi-ts-tanstack-vue-query/src/client/client/client.gen.ts b/examples/openapi-ts-tanstack-vue-query/src/client/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/examples/openapi-ts-tanstack-vue-query/src/client/client/client.gen.ts +++ b/examples/openapi-ts-tanstack-vue-query/src/client/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } From b5d1e9dc6cdc58964c1847f7698b86578e76ed48 Mon Sep 17 00:00:00 2001 From: Jorrin Date: Sat, 28 Mar 2026 02:07:33 +0100 Subject: [PATCH 3/8] chore: update coverage snapshots --- .../clean-false/core/response.gen.ts | 16 ++++++++++++++++ .../clean-false/core/response.gen.ts | 16 ++++++++++++++++ .../clean-false/core/response.gen.ts | 16 ++++++++++++++++ .../client-ky/clean-false/core/response.gen.ts | 16 ++++++++++++++++ .../client-next/clean-false/core/response.gen.ts | 16 ++++++++++++++++ .../client-nuxt/clean-false/core/response.gen.ts | 16 ++++++++++++++++ .../clean-false/core/response.gen.ts | 16 ++++++++++++++++ .../class/client/client.gen.ts | 6 ++++++ .../flat/client/client.gen.ts | 6 ++++++ .../instance/client/client.gen.ts | 6 ++++++ .../opencode/export-all/client/client.gen.ts | 6 ++++++ .../opencode/flat/client/client.gen.ts | 6 ++++++ .../opencode/grouped/client/client.gen.ts | 6 ++++++ .../3.1.x/type-format/client/client.gen.ts | 6 ++++++ .../2.0.x/mini/type-format/client/client.gen.ts | 6 ++++++ .../2.0.x/v3/type-format/client/client.gen.ts | 6 ++++++ .../2.0.x/v4/type-format/client/client.gen.ts | 6 ++++++ .../3.0.x/mini/type-format/client/client.gen.ts | 6 ++++++ .../3.0.x/v3/type-format/client/client.gen.ts | 6 ++++++ .../3.0.x/v4/type-format/client/client.gen.ts | 6 ++++++ .../3.1.x/mini/type-format/client/client.gen.ts | 6 ++++++ .../3.1.x/v3/type-format/client/client.gen.ts | 6 ++++++ .../3.1.x/v4/type-format/client/client.gen.ts | 6 ++++++ 23 files changed, 208 insertions(+) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts index 5215dd8f46..9b199d3c92 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts @@ -80,6 +80,22 @@ // This file is auto-generated by @hey-api/openapi-ts +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + export class ResponseError extends Error { readonly body: T; readonly request: Request; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts index 5215dd8f46..9b199d3c92 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts @@ -80,6 +80,22 @@ // This file is auto-generated by @hey-api/openapi-ts +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + export class ResponseError extends Error { readonly body: T; readonly request: Request; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts index 5215dd8f46..9b199d3c92 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts @@ -80,6 +80,22 @@ // This file is auto-generated by @hey-api/openapi-ts +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + export class ResponseError extends Error { readonly body: T; readonly request: Request; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts index 5215dd8f46..9b199d3c92 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts @@ -80,6 +80,22 @@ // This file is auto-generated by @hey-api/openapi-ts +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + export class ResponseError extends Error { readonly body: T; readonly request: Request; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts index 5215dd8f46..9b199d3c92 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts @@ -80,6 +80,22 @@ // This file is auto-generated by @hey-api/openapi-ts +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + export class ResponseError extends Error { readonly body: T; readonly request: Request; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts index 5215dd8f46..9b199d3c92 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts @@ -80,6 +80,22 @@ // This file is auto-generated by @hey-api/openapi-ts +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + export class ResponseError extends Error { readonly body: T; readonly request: Request; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts index 5215dd8f46..9b199d3c92 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts @@ -80,6 +80,22 @@ // This file is auto-generated by @hey-api/openapi-ts +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + +// This file is auto-generated by @hey-api/openapi-ts + export class ResponseError extends Error { readonly body: T; readonly request: Request; diff --git a/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/class/client/client.gen.ts b/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/class/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/class/client/client.gen.ts +++ b/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/class/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/flat/client/client.gen.ts b/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/flat/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/flat/client/client.gen.ts +++ b/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/flat/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/instance/client/client.gen.ts b/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/instance/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/instance/client/client.gen.ts +++ b/packages/openapi-ts-tests/sdks/__snapshots__/method-class-conflict/instance/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client/client.gen.ts b/packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client/client.gen.ts +++ b/packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/client/client.gen.ts b/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/client/client.gen.ts +++ b/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/sdks/__snapshots__/opencode/grouped/client/client.gen.ts b/packages/openapi-ts-tests/sdks/__snapshots__/opencode/grouped/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/sdks/__snapshots__/opencode/grouped/client/client.gen.ts +++ b/packages/openapi-ts-tests/sdks/__snapshots__/opencode/grouped/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/valibot/v1/__snapshots__/3.1.x/type-format/client/client.gen.ts b/packages/openapi-ts-tests/valibot/v1/__snapshots__/3.1.x/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/valibot/v1/__snapshots__/3.1.x/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/valibot/v1/__snapshots__/3.1.x/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/type-format/client/client.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/type-format/client/client.gen.ts index 9ec9ad887c..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/type-format/client/client.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/type-format/client/client.gen.ts @@ -230,6 +230,12 @@ export const createClient = (config: Config = {}): Client => { finalError = finalError || ({} as string); if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } throw finalError; } From 87b38bd66049002c8bb107a612618139eee5cb35 Mon Sep 17 00:00:00 2001 From: Jorrin Date: Sat, 28 Mar 2026 02:16:19 +0100 Subject: [PATCH 4/8] chore: remove stale response.gen.ts artifacts --- .../clean-false/core/response.gen.ts | 114 ------------------ .../clean-false/core/response.gen.ts | 114 ------------------ .../clean-false/core/response.gen.ts | 114 ------------------ .../clean-false/core/response.gen.ts | 114 ------------------ .../clean-false/core/response.gen.ts | 114 ------------------ .../clean-false/core/response.gen.ts | 114 ------------------ .../clean-false/core/response.gen.ts | 114 ------------------ 7 files changed, 798 deletions(-) delete mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts delete mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts delete mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts delete mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts delete mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts delete mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts delete mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts deleted file mode 100644 index 9b199d3c92..0000000000 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-angular/clean-false/core/response.gen.ts +++ /dev/null @@ -1,114 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -export class ResponseError extends Error { - readonly body: T; - readonly request: Request; - readonly response: Response; - readonly status: number; - - override name = 'ResponseError' as const; - - constructor(options: { body: T; message?: string; request: Request; response: Response }) { - super(options.message ?? options.response.statusText); - this.body = options.body; - this.request = options.request; - this.response = options.response; - this.status = options.response.status; - } -} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts deleted file mode 100644 index 9b199d3c92..0000000000 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/core/response.gen.ts +++ /dev/null @@ -1,114 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -export class ResponseError extends Error { - readonly body: T; - readonly request: Request; - readonly response: Response; - readonly status: number; - - override name = 'ResponseError' as const; - - constructor(options: { body: T; message?: string; request: Request; response: Response }) { - super(options.message ?? options.response.statusText); - this.body = options.body; - this.request = options.request; - this.response = options.response; - this.status = options.response.status; - } -} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts deleted file mode 100644 index 9b199d3c92..0000000000 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/clean-false/core/response.gen.ts +++ /dev/null @@ -1,114 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -export class ResponseError extends Error { - readonly body: T; - readonly request: Request; - readonly response: Response; - readonly status: number; - - override name = 'ResponseError' as const; - - constructor(options: { body: T; message?: string; request: Request; response: Response }) { - super(options.message ?? options.response.statusText); - this.body = options.body; - this.request = options.request; - this.response = options.response; - this.status = options.response.status; - } -} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts deleted file mode 100644 index 9b199d3c92..0000000000 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ky/clean-false/core/response.gen.ts +++ /dev/null @@ -1,114 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -export class ResponseError extends Error { - readonly body: T; - readonly request: Request; - readonly response: Response; - readonly status: number; - - override name = 'ResponseError' as const; - - constructor(options: { body: T; message?: string; request: Request; response: Response }) { - super(options.message ?? options.response.statusText); - this.body = options.body; - this.request = options.request; - this.response = options.response; - this.status = options.response.status; - } -} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts deleted file mode 100644 index 9b199d3c92..0000000000 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-next/clean-false/core/response.gen.ts +++ /dev/null @@ -1,114 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -export class ResponseError extends Error { - readonly body: T; - readonly request: Request; - readonly response: Response; - readonly status: number; - - override name = 'ResponseError' as const; - - constructor(options: { body: T; message?: string; request: Request; response: Response }) { - super(options.message ?? options.response.statusText); - this.body = options.body; - this.request = options.request; - this.response = options.response; - this.status = options.response.status; - } -} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts deleted file mode 100644 index 9b199d3c92..0000000000 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/clean-false/core/response.gen.ts +++ /dev/null @@ -1,114 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -export class ResponseError extends Error { - readonly body: T; - readonly request: Request; - readonly response: Response; - readonly status: number; - - override name = 'ResponseError' as const; - - constructor(options: { body: T; message?: string; request: Request; response: Response }) { - super(options.message ?? options.response.statusText); - this.body = options.body; - this.request = options.request; - this.response = options.response; - this.status = options.response.status; - } -} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts deleted file mode 100644 index 9b199d3c92..0000000000 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-ofetch/clean-false/core/response.gen.ts +++ /dev/null @@ -1,114 +0,0 @@ -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -// This file is auto-generated by @hey-api/openapi-ts - -export class ResponseError extends Error { - readonly body: T; - readonly request: Request; - readonly response: Response; - readonly status: number; - - override name = 'ResponseError' as const; - - constructor(options: { body: T; message?: string; request: Request; response: Response }) { - super(options.message ?? options.response.statusText); - this.body = options.body; - this.request = options.request; - this.response = options.response; - this.status = options.response.status; - } -} From 493b4590346730086f5cf2c94510fa737ee74325 Mon Sep 17 00:00:00 2001 From: Jorrin Date: Wed, 1 Apr 2026 17:30:07 +0200 Subject: [PATCH 5/8] fix: pr feedback --- .../@tanstack/react-query.gen.ts | 68 ++++++------- .../@tanstack/react-query.gen.ts | 98 +++++++++---------- .../@tanstack/react-query.gen.ts | 98 +++++++++---------- .../query-core/v5/infiniteQueryOptions.ts | 3 +- .../query-core/v5/mutationOptions.ts | 5 +- .../plugins/@tanstack/query-core/v5/plugin.ts | 6 +- .../@tanstack/query-core/v5/queryOptions.ts | 3 +- 7 files changed, 142 insertions(+), 139 deletions(-) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts index eb2dbea283..76797d6925 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts @@ -6,13 +6,13 @@ import { client } from '../client.gen'; import { callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexTypes, deleteCallWithoutParametersAndResponse, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, fooWow, getCallWithoutParametersAndResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionBody, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, serviceWithEmptyTag, testErrorCode, types } from '../sdk.gen'; import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData, TypesResponse } from '../types.gen'; -type ResponseResult = TStyle extends "fields" ? { +type ResponseResult = TStyle extends "fields" ? { data: TData; request: Request; response: Response; } : TData; -type ResponseError = TStyle extends "fields" ? { +type ResponseError = TStyle extends "fields" ? { error: TError; request: Request; response: Response; @@ -53,7 +53,7 @@ const createQueryKey = (id: string, options?: TOptions export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options & { +export const serviceWithEmptyTagOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -70,7 +70,7 @@ export const serviceWithEmptyTagOptions = (options?: Partial> & { +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -88,7 +88,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { +export const fooWowMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -106,7 +106,7 @@ export const fooWowMutation = (opti return mutationOptions; }; -export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -126,7 +126,7 @@ export const deleteCallWithoutParametersAndResponseMutation = ) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options & { +export const getCallWithoutParametersAndResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -143,7 +143,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Partial> & { +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -161,7 +161,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -179,7 +179,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -197,7 +197,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const callWithDescriptionsMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -215,7 +215,7 @@ export const callWithDescriptionsMutation = (options?: Partial> & { +export const callWithParametersMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -233,7 +233,7 @@ export const callWithParametersMutation = (options?: Partial> & { +export const callWithWeirdParameterNamesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -253,7 +253,7 @@ export const callWithWeirdParameterNamesMutation = ) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options & { +export const callWithDefaultParametersOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -270,7 +270,7 @@ export const callWithDefaultParametersOptions = (options?: Partial> & { +export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -288,7 +288,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { +export const callToTestOrderOfParamsMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -306,7 +306,7 @@ export const callToTestOrderOfParamsMutation = (options?: Partial> & { +export const duplicateNameMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -326,7 +326,7 @@ export const duplicateNameMutation = (options?: Options & { +export const duplicateName2Options = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -343,7 +343,7 @@ export const duplicateName2Options = (options?: Partial> & { +export const duplicateName3Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -361,7 +361,7 @@ export const duplicateName3Mutation = (options?: Partial> & { +export const duplicateName4Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -381,7 +381,7 @@ export const duplicateName4Mutation = (options?: Options & { +export const callWithNoContentResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -400,7 +400,7 @@ export const callWithNoContentResponseOptions = ) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options & { +export const callWithResponseAndNoContentResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -419,7 +419,7 @@ export const callWithResponseAndNoContentResponseOptions = ) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options & { +export const dummyAOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -438,7 +438,7 @@ export const dummyAOptions = (optio export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options & { +export const dummyBOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -457,7 +457,7 @@ export const dummyBOptions = (optio export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options & { +export const callWithResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -474,7 +474,7 @@ export const callWithResponseOptions = (options?: Partial> & { +export const callWithDuplicateResponsesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -492,7 +492,7 @@ export const callWithDuplicateResponsesMutation = (options?: Partial> & { +export const callWithResponsesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -512,7 +512,7 @@ export const callWithResponsesMutation = (options: Options & { +export const collectionFormatOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -531,7 +531,7 @@ export const collectionFormatOptions = (options: Options & { +export const typesOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -550,7 +550,7 @@ export const typesOptions = (option export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options & { +export const complexTypesOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -567,7 +567,7 @@ export const complexTypesOptions = queryKey: complexTypesQueryKey(options) }); -export const callWithResultFromHeaderMutation = (options?: Partial> & { +export const callWithResultFromHeaderMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -585,7 +585,7 @@ export const callWithResultFromHeaderMutation = (options?: Partial> & { +export const testErrorCodeMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -603,7 +603,7 @@ export const testErrorCodeMutation = (options?: Partial> & { +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -626,7 +626,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { +export const postApiVbyApiVersionBodyMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts index a8bb58a21e..70c9457d7b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts @@ -6,13 +6,13 @@ import { client } from '../client.gen'; import { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from '../sdk.gen'; import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponse, DummyBData, DummyBResponse, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponse, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, TypesResponse, UploadFileData, UploadFileResponse } from '../types.gen'; -type ResponseResult = TStyle extends "fields" ? { +type ResponseResult = TStyle extends "fields" ? { data: TData; request: Request; response: Response; } : TData; -type ResponseError = TStyle extends "fields" ? { +type ResponseError = TStyle extends "fields" ? { error: TError; request: Request; response: Response; @@ -53,7 +53,7 @@ const createQueryKey = (id: string, options?: TOptions export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options & { +export const exportOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -70,7 +70,7 @@ export const exportOptions = (optio queryKey: exportQueryKey(options) }); -export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -88,7 +88,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { +export const importMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -106,7 +106,7 @@ export const importMutation = (opti return mutationOptions; }; -export const fooWowMutation = (options?: Partial> & { +export const fooWowMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -126,7 +126,7 @@ export const fooWowMutation = (opti export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options & { +export const apiVVersionODataControllerCountOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -145,7 +145,7 @@ export const apiVVersionODataControllerCountOptions = ) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options & { +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -162,7 +162,7 @@ export const getApiVbyApiVersionSimpleOperationOptions = (options?: Partial> & { +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -182,7 +182,7 @@ export const deleteCallWithoutParametersAndResponseMutation = ) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options & { +export const getCallWithoutParametersAndResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -199,7 +199,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Partial> & { +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -217,7 +217,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -235,7 +235,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -253,7 +253,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const deleteFooMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -271,7 +271,7 @@ export const deleteFooMutation = (o return mutationOptions; }; -export const callWithDescriptionsMutation = (options?: Partial> & { +export const callWithDescriptionsMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -292,7 +292,7 @@ export const callWithDescriptionsMutation = (options?: Partial> & { +export const deprecatedCallMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -310,7 +310,7 @@ export const deprecatedCallMutation = (options?: Partial> & { +export const callWithParametersMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -328,7 +328,7 @@ export const callWithParametersMutation = (options?: Partial> & { +export const callWithWeirdParameterNamesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -348,7 +348,7 @@ export const callWithWeirdParameterNamesMutation = ) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options & { +export const getCallWithOptionalParamOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -396,7 +396,7 @@ const createInfiniteParams = [0], 'body' | 'hea export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); -export const getCallWithOptionalParamInfiniteOptions = (options: Options & { +export const getCallWithOptionalParamInfiniteOptions = (options: Options & { responseStyle?: TStyle; }) => infiniteQueryOptions, ResponseError, InfiniteData>, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( // @ts-ignore @@ -422,7 +422,7 @@ export const getCallWithOptionalParamInfiniteOptions = (options?: Partial> & { +export const postCallWithOptionalParamMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -440,7 +440,7 @@ export const postCallWithOptionalParamMutation = (options?: Partial> & { +export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -458,7 +458,7 @@ export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial> & { +export const postApiVbyApiVersionFormDataMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -478,7 +478,7 @@ export const postApiVbyApiVersionFormDataMutation = ) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options & { +export const callWithDefaultParametersOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -495,7 +495,7 @@ export const callWithDefaultParametersOptions = (options?: Partial> & { +export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -513,7 +513,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { +export const callToTestOrderOfParamsMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -531,7 +531,7 @@ export const callToTestOrderOfParamsMutation = (options?: Partial> & { +export const duplicateNameMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -551,7 +551,7 @@ export const duplicateNameMutation = (options?: Options & { +export const duplicateName2Options = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -568,7 +568,7 @@ export const duplicateName2Options = (options?: Partial> & { +export const duplicateName3Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -586,7 +586,7 @@ export const duplicateName3Mutation = (options?: Partial> & { +export const duplicateName4Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -606,7 +606,7 @@ export const duplicateName4Mutation = (options?: Options & { +export const callWithNoContentResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -625,7 +625,7 @@ export const callWithNoContentResponseOptions = ) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options & { +export const callWithResponseAndNoContentResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -644,7 +644,7 @@ export const callWithResponseAndNoContentResponseOptions = ) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options & { +export const dummyAOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -663,7 +663,7 @@ export const dummyAOptions = (optio export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options & { +export const dummyBOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -682,7 +682,7 @@ export const dummyBOptions = (optio export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options & { +export const callWithResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -699,7 +699,7 @@ export const callWithResponseOptions = (options?: Partial> & { +export const callWithDuplicateResponsesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -717,7 +717,7 @@ export const callWithDuplicateResponsesMutation = (options?: Partial> & { +export const callWithResponsesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -737,7 +737,7 @@ export const callWithResponsesMutation = (options: Options & { +export const collectionFormatOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -756,7 +756,7 @@ export const collectionFormatOptions = (options: Options & { +export const typesOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -773,7 +773,7 @@ export const typesOptions = (option queryKey: typesQueryKey(options) }); -export const uploadFileMutation = (options?: Partial> & { +export const uploadFileMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -793,7 +793,7 @@ export const uploadFileMutation = ( export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options & { +export const fileResponseOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -812,7 +812,7 @@ export const fileResponseOptions = export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options & { +export const complexTypesOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -831,7 +831,7 @@ export const complexTypesOptions = export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options & { +export const multipartResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -848,7 +848,7 @@ export const multipartResponseOptions = (options?: Partial> & { +export const multipartRequestMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -866,7 +866,7 @@ export const multipartRequestMutation = (options?: Partial> & { +export const complexParamsMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -884,7 +884,7 @@ export const complexParamsMutation = (options?: Partial> & { +export const callWithResultFromHeaderMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -902,7 +902,7 @@ export const callWithResultFromHeaderMutation = (options?: Partial> & { +export const testErrorCodeMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -920,7 +920,7 @@ export const testErrorCodeMutation = (options?: Partial> & { +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -941,7 +941,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { +export const putWithFormUrlEncodedMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts index a8bb58a21e..70c9457d7b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/@tanstack/react-query.gen.ts @@ -6,13 +6,13 @@ import { client } from '../client.gen'; import { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from '../sdk.gen'; import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponse, DummyBData, DummyBResponse, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponse, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, TypesResponse, UploadFileData, UploadFileResponse } from '../types.gen'; -type ResponseResult = TStyle extends "fields" ? { +type ResponseResult = TStyle extends "fields" ? { data: TData; request: Request; response: Response; } : TData; -type ResponseError = TStyle extends "fields" ? { +type ResponseError = TStyle extends "fields" ? { error: TError; request: Request; response: Response; @@ -53,7 +53,7 @@ const createQueryKey = (id: string, options?: TOptions export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options & { +export const exportOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -70,7 +70,7 @@ export const exportOptions = (optio queryKey: exportQueryKey(options) }); -export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -88,7 +88,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Partial> & { +export const importMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -106,7 +106,7 @@ export const importMutation = (opti return mutationOptions; }; -export const fooWowMutation = (options?: Partial> & { +export const fooWowMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -126,7 +126,7 @@ export const fooWowMutation = (opti export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options & { +export const apiVVersionODataControllerCountOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -145,7 +145,7 @@ export const apiVVersionODataControllerCountOptions = ) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options & { +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -162,7 +162,7 @@ export const getApiVbyApiVersionSimpleOperationOptions = (options?: Partial> & { +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -182,7 +182,7 @@ export const deleteCallWithoutParametersAndResponseMutation = ) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options & { +export const getCallWithoutParametersAndResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -199,7 +199,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Partial> & { +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -217,7 +217,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -235,7 +235,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -253,7 +253,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial> & { +export const deleteFooMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -271,7 +271,7 @@ export const deleteFooMutation = (o return mutationOptions; }; -export const callWithDescriptionsMutation = (options?: Partial> & { +export const callWithDescriptionsMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -292,7 +292,7 @@ export const callWithDescriptionsMutation = (options?: Partial> & { +export const deprecatedCallMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -310,7 +310,7 @@ export const deprecatedCallMutation = (options?: Partial> & { +export const callWithParametersMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -328,7 +328,7 @@ export const callWithParametersMutation = (options?: Partial> & { +export const callWithWeirdParameterNamesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -348,7 +348,7 @@ export const callWithWeirdParameterNamesMutation = ) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options & { +export const getCallWithOptionalParamOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -396,7 +396,7 @@ const createInfiniteParams = [0], 'body' | 'hea export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); -export const getCallWithOptionalParamInfiniteOptions = (options: Options & { +export const getCallWithOptionalParamInfiniteOptions = (options: Options & { responseStyle?: TStyle; }) => infiniteQueryOptions, ResponseError, InfiniteData>, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( // @ts-ignore @@ -422,7 +422,7 @@ export const getCallWithOptionalParamInfiniteOptions = (options?: Partial> & { +export const postCallWithOptionalParamMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -440,7 +440,7 @@ export const postCallWithOptionalParamMutation = (options?: Partial> & { +export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -458,7 +458,7 @@ export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial> & { +export const postApiVbyApiVersionFormDataMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -478,7 +478,7 @@ export const postApiVbyApiVersionFormDataMutation = ) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options & { +export const callWithDefaultParametersOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -495,7 +495,7 @@ export const callWithDefaultParametersOptions = (options?: Partial> & { +export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -513,7 +513,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Partial> & { +export const callToTestOrderOfParamsMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -531,7 +531,7 @@ export const callToTestOrderOfParamsMutation = (options?: Partial> & { +export const duplicateNameMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -551,7 +551,7 @@ export const duplicateNameMutation = (options?: Options & { +export const duplicateName2Options = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -568,7 +568,7 @@ export const duplicateName2Options = (options?: Partial> & { +export const duplicateName3Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -586,7 +586,7 @@ export const duplicateName3Mutation = (options?: Partial> & { +export const duplicateName4Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -606,7 +606,7 @@ export const duplicateName4Mutation = (options?: Options & { +export const callWithNoContentResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -625,7 +625,7 @@ export const callWithNoContentResponseOptions = ) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options & { +export const callWithResponseAndNoContentResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -644,7 +644,7 @@ export const callWithResponseAndNoContentResponseOptions = ) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options & { +export const dummyAOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -663,7 +663,7 @@ export const dummyAOptions = (optio export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options & { +export const dummyBOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -682,7 +682,7 @@ export const dummyBOptions = (optio export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options & { +export const callWithResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -699,7 +699,7 @@ export const callWithResponseOptions = (options?: Partial> & { +export const callWithDuplicateResponsesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -717,7 +717,7 @@ export const callWithDuplicateResponsesMutation = (options?: Partial> & { +export const callWithResponsesMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -737,7 +737,7 @@ export const callWithResponsesMutation = (options: Options & { +export const collectionFormatOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -756,7 +756,7 @@ export const collectionFormatOptions = (options: Options & { +export const typesOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -773,7 +773,7 @@ export const typesOptions = (option queryKey: typesQueryKey(options) }); -export const uploadFileMutation = (options?: Partial> & { +export const uploadFileMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -793,7 +793,7 @@ export const uploadFileMutation = ( export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options & { +export const fileResponseOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -812,7 +812,7 @@ export const fileResponseOptions = export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options & { +export const complexTypesOptions = (options: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -831,7 +831,7 @@ export const complexTypesOptions = export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options & { +export const multipartResponseOptions = (options?: Options & { responseStyle?: TStyle; }) => queryOptions, ResponseError, ResponseResult, ReturnType>({ queryFn: async ({ queryKey, signal }) => { @@ -848,7 +848,7 @@ export const multipartResponseOptions = (options?: Partial> & { +export const multipartRequestMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -866,7 +866,7 @@ export const multipartRequestMutation = (options?: Partial> & { +export const complexParamsMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -884,7 +884,7 @@ export const complexParamsMutation = (options?: Partial> & { +export const callWithResultFromHeaderMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -902,7 +902,7 @@ export const callWithResultFromHeaderMutation = (options?: Partial> & { +export const testErrorCodeMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -920,7 +920,7 @@ export const testErrorCodeMutation = (options?: Partial> & { +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { @@ -941,7 +941,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial> & { +export const putWithFormUrlEncodedMutation = (options?: Partial> & { responseStyle?: TStyle; }): UseMutationOptions, ResponseError, Options> => { const mutationOptions: UseMutationOptions, ResponseError, Options> = { diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts index caa8ba0fa1..b37c7819fe 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/infiniteQueryOptions.ts @@ -181,7 +181,8 @@ export const createInfiniteQueryOptions = ({ if (plugin.config.responseStyle === 'fields') { // --- 'fields' code path: TStyle generic, ResponseResult/ResponseError wrappers --- - const defaultStyle = plugin.config.responseStyle; + // Default to 'data' so omitting responseStyle preserves backward-compatible behavior + const defaultStyle = 'data' as const; const symbolResponseResult = plugin.referenceSymbol({ category: 'type', diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts index 1cff76bbca..893d2ca7f1 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts @@ -33,7 +33,8 @@ export const createMutationOptions = ({ if (plugin.config.responseStyle === 'fields') { // --- 'fields' code path: TStyle generic, ResponseResult/ResponseError wrappers --- - const defaultStyle = plugin.config.responseStyle; + // Default to 'data' so omitting responseStyle preserves backward-compatible behavior + const defaultStyle = 'data' as const; const symbolResponseResult = plugin.referenceSymbol({ category: 'type', @@ -178,7 +179,7 @@ export const createMutationOptions = ({ }, ); const statement = $.const(symbolMutationOptions) - .export() + .export(plugin.config.mutationOptions.exported) .$if(plugin.config.comments && createOperationComment(operation), (c, v) => c.doc(v)) .assign( $.func() diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts index 7e07aa3a9f..c68f3bff12 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts @@ -1,7 +1,6 @@ import ts from 'typescript'; -import { TsDsl } from '../../../../ts-dsl'; -import { $ } from '../../../../ts-dsl'; +import { $, TsDsl } from '../../../../ts-dsl'; import type { PluginHandler, PluginInstance } from '../types'; import { createInfiniteQueryOptions } from './infiniteQueryOptions'; import { createMutationOptions } from './mutationOptions'; @@ -168,7 +167,8 @@ export const handlerV5: PluginHandler = ({ plugin }) => { // Generate ResponseResult and ResponseError utility types only when responseStyle is 'fields' if (plugin.config.responseStyle === 'fields') { - createResponseStyleTypes(plugin.config.responseStyle, plugin); + // Default to 'data' so omitting responseStyle preserves backward-compatible behavior + createResponseStyleTypes('data', plugin); } plugin.forEach( diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts index 28dca70a02..0ca120665b 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/v5/queryOptions.ts @@ -60,7 +60,8 @@ export const createQueryOptions = ({ if (plugin.config.responseStyle === 'fields') { // --- 'fields' code path: TStyle generic, ResponseResult/ResponseError wrappers --- - const defaultStyle = plugin.config.responseStyle; + // Default to 'data' so omitting responseStyle preserves backward-compatible behavior + const defaultStyle = 'data' as const; const symbolResponseResult = plugin.referenceSymbol({ category: 'type', From 9086190dc9a5a36f0e5271ad524ea9b84b18affb Mon Sep 17 00:00:00 2001 From: Jorrin Date: Wed, 1 Apr 2026 17:45:10 +0200 Subject: [PATCH 6/8] fix with master rebase --- .../responseStyle/client/client.gen.ts | 16 ++++++++++++---- .../responseStyle/client/types.gen.ts | 2 +- .../react-query/responseStyle/sdk.gen.ts | 2 +- .../responseStyle/client/client.gen.ts | 16 ++++++++++++---- .../responseStyle/client/types.gen.ts | 2 +- .../react-query/responseStyle/sdk.gen.ts | 2 +- .../responseStyle/client/client.gen.ts | 16 ++++++++++++---- .../responseStyle/client/types.gen.ts | 2 +- .../react-query/responseStyle/sdk.gen.ts | 2 +- 9 files changed, 42 insertions(+), 18 deletions(-) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts index ce96094c02..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts @@ -31,7 +31,14 @@ export const createClient = (config: Config = {}): Client => { const interceptors = createInterceptors(); - const beforeRequest = async (options: RequestOptions) => { + const beforeRequest = async < + TData = unknown, + TResponseStyle extends 'data' | 'fields' = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, + >( + options: RequestOptions, + ) => { const opts = { ..._config, ...options, @@ -60,13 +67,14 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } - const url = buildUrl(opts); + const resolvedOpts = opts as typeof opts & + ResolvedRequestOptions; + const url = buildUrl(resolvedOpts); - return { opts, url }; + return { opts: resolvedOpts, url }; }; const request: Client['request'] = async (options) => { - // @ts-expect-error const { opts, url } = await beforeRequest(options); const requestInit: ReqInit = { redirect: 'follow', diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts index a3f8616511..9813eeaba6 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts @@ -152,7 +152,7 @@ type SseFn = < ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields', >( - options: Omit, 'method'>, + options: Omit, 'method'>, ) => Promise>; type RequestFn = < diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts index 6776488ce6..0f0e66cba9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts @@ -4,7 +4,7 @@ import type { Client, Options as Options2, TDataShape } from './client'; import { client } from './client.gen'; import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, FooWowResponses, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyErrors, PostApiVbyApiVersionBodyResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses } from './types.gen'; -export type Options = Options2 & { +export type Options = Options2 & { /** * You can provide a client instance returned by `createClient()` instead of * individual options. This might be also useful if you want to implement a diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts index ce96094c02..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts @@ -31,7 +31,14 @@ export const createClient = (config: Config = {}): Client => { const interceptors = createInterceptors(); - const beforeRequest = async (options: RequestOptions) => { + const beforeRequest = async < + TData = unknown, + TResponseStyle extends 'data' | 'fields' = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, + >( + options: RequestOptions, + ) => { const opts = { ..._config, ...options, @@ -60,13 +67,14 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } - const url = buildUrl(opts); + const resolvedOpts = opts as typeof opts & + ResolvedRequestOptions; + const url = buildUrl(resolvedOpts); - return { opts, url }; + return { opts: resolvedOpts, url }; }; const request: Client['request'] = async (options) => { - // @ts-expect-error const { opts, url } = await beforeRequest(options); const requestInit: ReqInit = { redirect: 'follow', diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts index a3f8616511..9813eeaba6 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts @@ -152,7 +152,7 @@ type SseFn = < ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields', >( - options: Omit, 'method'>, + options: Omit, 'method'>, ) => Promise>; type RequestFn = < diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts index e48dcff8cf..fbc4ca77fb 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts @@ -4,7 +4,7 @@ import { type Client, formDataBodySerializer, type Options as Options2, type TDa import { client } from './client.gen'; import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponses, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponses, FooWowData, FooWowResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ImportData, ImportResponses, MultipartRequestData, MultipartResponseData, MultipartResponseResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses, UploadFileData, UploadFileResponses } from './types.gen'; -export type Options = Options2 & { +export type Options = Options2 & { /** * You can provide a client instance returned by `createClient()` instead of * individual options. This might be also useful if you want to implement a diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts index ce96094c02..4fd22d49b2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/client.gen.ts @@ -31,7 +31,14 @@ export const createClient = (config: Config = {}): Client => { const interceptors = createInterceptors(); - const beforeRequest = async (options: RequestOptions) => { + const beforeRequest = async < + TData = unknown, + TResponseStyle extends 'data' | 'fields' = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, + >( + options: RequestOptions, + ) => { const opts = { ..._config, ...options, @@ -60,13 +67,14 @@ export const createClient = (config: Config = {}): Client => { opts.headers.delete('Content-Type'); } - const url = buildUrl(opts); + const resolvedOpts = opts as typeof opts & + ResolvedRequestOptions; + const url = buildUrl(resolvedOpts); - return { opts, url }; + return { opts: resolvedOpts, url }; }; const request: Client['request'] = async (options) => { - // @ts-expect-error const { opts, url } = await beforeRequest(options); const requestInit: ReqInit = { redirect: 'follow', diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts index a3f8616511..9813eeaba6 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/client/types.gen.ts @@ -152,7 +152,7 @@ type SseFn = < ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields', >( - options: Omit, 'method'>, + options: Omit, 'method'>, ) => Promise>; type RequestFn = < diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts index e48dcff8cf..fbc4ca77fb 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/sdk.gen.ts @@ -4,7 +4,7 @@ import { type Client, formDataBodySerializer, type Options as Options2, type TDa import { client } from './client.gen'; import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponses, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponses, FooWowData, FooWowResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ImportData, ImportResponses, MultipartRequestData, MultipartResponseData, MultipartResponseResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses, UploadFileData, UploadFileResponses } from './types.gen'; -export type Options = Options2 & { +export type Options = Options2 & { /** * You can provide a client instance returned by `createClient()` instead of * individual options. This might be also useful if you want to implement a From 3b9a1b8660ef1d04c075548bfec9345e868736bc Mon Sep 17 00:00:00 2001 From: Jorrin Date: Thu, 9 Apr 2026 22:41:48 +0200 Subject: [PATCH 7/8] fix test --- .../@tanstack/react-query.gen.ts | 505 ++++ .../responseStyle-data/client.gen.ts | 16 + .../responseStyle-data/client/client.gen.ts | 304 +++ .../responseStyle-data/client/index.ts | 25 + .../responseStyle-data/client/types.gen.ts | 214 ++ .../responseStyle-data/client/utils.gen.ts | 316 +++ .../responseStyle-data/core/auth.gen.ts | 41 + .../core/bodySerializer.gen.ts | 82 + .../responseStyle-data/core/params.gen.ts | 169 ++ .../core/pathSerializer.gen.ts | 171 ++ .../core/queryKeySerializer.gen.ts | 117 + .../core/serverSentEvents.gen.ts | 242 ++ .../responseStyle-data/core/types.gen.ts | 104 + .../responseStyle-data/core/utils.gen.ts | 140 ++ .../react-query/responseStyle-data/index.ts | 4 + .../react-query/responseStyle-data/sdk.gen.ts | 127 + .../responseStyle-data/types.gen.ts | 1190 ++++++++++ .../core/serverSentEvents.gen.ts | 9 +- .../@tanstack/react-query.gen.ts | 760 ++++++ .../responseStyle-data/client.gen.ts | 16 + .../responseStyle-data/client/client.gen.ts | 304 +++ .../responseStyle-data/client/index.ts | 25 + .../responseStyle-data/client/types.gen.ts | 214 ++ .../responseStyle-data/client/utils.gen.ts | 316 +++ .../responseStyle-data/core/auth.gen.ts | 41 + .../core/bodySerializer.gen.ts | 82 + .../responseStyle-data/core/params.gen.ts | 169 ++ .../core/pathSerializer.gen.ts | 171 ++ .../core/queryKeySerializer.gen.ts | 117 + .../core/serverSentEvents.gen.ts | 242 ++ .../responseStyle-data/core/types.gen.ts | 104 + .../responseStyle-data/core/utils.gen.ts | 140 ++ .../react-query/responseStyle-data/index.ts | 4 + .../react-query/responseStyle-data/sdk.gen.ts | 206 ++ .../responseStyle-data/types.gen.ts | 2081 ++++++++++++++++ .../core/serverSentEvents.gen.ts | 9 +- .../@tanstack/react-query.gen.ts | 760 ++++++ .../responseStyle-data/client.gen.ts | 16 + .../responseStyle-data/client/client.gen.ts | 304 +++ .../responseStyle-data/client/index.ts | 25 + .../responseStyle-data/client/types.gen.ts | 214 ++ .../responseStyle-data/client/utils.gen.ts | 316 +++ .../responseStyle-data/core/auth.gen.ts | 41 + .../core/bodySerializer.gen.ts | 82 + .../responseStyle-data/core/params.gen.ts | 169 ++ .../core/pathSerializer.gen.ts | 171 ++ .../core/queryKeySerializer.gen.ts | 117 + .../core/serverSentEvents.gen.ts | 242 ++ .../responseStyle-data/core/types.gen.ts | 104 + .../responseStyle-data/core/utils.gen.ts | 140 ++ .../react-query/responseStyle-data/index.ts | 4 + .../react-query/responseStyle-data/sdk.gen.ts | 206 ++ .../responseStyle-data/types.gen.ts | 2100 +++++++++++++++++ .../core/serverSentEvents.gen.ts | 9 +- .../main/test/plugins.test.ts | 14 + 55 files changed, 13796 insertions(+), 15 deletions(-) create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts new file mode 100644 index 0000000000..ef023fe2c6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts @@ -0,0 +1,505 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanstack/react-query'; + +import { client } from '../client.gen'; +import { callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexTypes, deleteCallWithoutParametersAndResponse, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, fooWow, getCallWithoutParametersAndResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionBody, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, serviceWithEmptyTag, testErrorCode, types } from '../sdk.gen'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData, TypesResponse } from '../types.gen'; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); + +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await serviceWithEmptyTag({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: serviceWithEmptyTagQueryKey(options) +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const fooWowMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await fooWow({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getCallWithoutParametersAndResponseQueryKey(options) +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithDescriptionsMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDescriptions({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithParametersMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithParameters({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); + +export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithDefaultParameters({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithDefaultParametersQueryKey(options) +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callToTestOrderOfParamsMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateNameMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); + +export const duplicateName2Options = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await duplicateName2({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: duplicateName2QueryKey(options) +}); + +export const duplicateName3Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName3({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateName4Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName4({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); + +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithNoContentResponseQueryKey(options) +}); + +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithResponseAndNoContentResponseQueryKey(options) +}); + +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); + +export const dummyAOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await dummyA({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: dummyAQueryKey(options) +}); + +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); + +export const dummyBOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await dummyB({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: dummyBQueryKey(options) +}); + +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); + +export const callWithResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithResponseQueryKey(options) +}); + +export const callWithDuplicateResponsesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithResponsesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithResponses({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); + +export const collectionFormatOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await collectionFormat({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: collectionFormatQueryKey(options) +}); + +export const typesQueryKey = (options: Options) => createQueryKey('types', options); + +export const typesOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await types({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: typesQueryKey(options) +}); + +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); + +export const complexTypesOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await complexTypes({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: complexTypesQueryKey(options) +}); + +export const callWithResultFromHeaderMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const testErrorCodeMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await testErrorCode({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +/** + * Body should not be unknown + * + * Body should not be unknown + */ +export const postApiVbyApiVersionBodyMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postApiVbyApiVersionBody({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts new file mode 100644 index 0000000000..25cd14eafb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig({ baseUrl: 'http://localhost:3000/base' })); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts new file mode 100644 index 0000000000..4fd22d49b2 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts @@ -0,0 +1,304 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors(); + + const beforeRequest = async < + TData = unknown, + TResponseStyle extends 'data' | 'fields' = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, + >( + options: RequestOptions, + ) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined as string | undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined; + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const resolvedOpts = opts as typeof opts & + ResolvedRequestOptions; + const url = buildUrl(resolvedOpts); + + return { opts: resolvedOpts, url }; + }; + + const request: Client['request'] = async (options) => { + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response: Response; + + try { + response = await _fetch(request); + } catch (error) { + // Handle fetch exceptions (AbortError, network errors, etc.) + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, undefined as any, request, opts)) as unknown; + } + } + + finalError = finalError || ({} as unknown); + + if (opts.throwOnError) { + throw finalError; + } + + // Return error response + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + request, + response: undefined as any, + }; + } + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if (response.status === 204 || response.headers.get('Content-Length') === '0') { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'text': + data = await response[parseAs](); + break; + case 'json': { + // Some servers return 200 with no Content-Length and empty body. + // response.json() would throw; read as text and parse if non-empty. + const text = await response.text(); + data = text ? JSON.parse(text) : {}; + break; + } + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined, + url, + }); + }; + + const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options }); + + return { + buildUrl: _buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts @@ -0,0 +1,25 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Auth } from '../core/auth.gen'; +export type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +export { + formDataBodySerializer, + jsonBodySerializer, + urlSearchParamsBodySerializer, +} from '../core/bodySerializer.gen'; +export { buildClientParams } from '../core/params.gen'; +export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'; +export { createClient } from './client.gen'; +export type { + Client, + ClientOptions, + Config, + CreateClientConfig, + Options, + RequestOptions, + RequestResult, + ResolvedRequestOptions, + ResponseStyle, + TDataShape, +} from './types.gen'; +export { createConfig, mergeHeaders } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts new file mode 100644 index 0000000000..9813eeaba6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts @@ -0,0 +1,214 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> + extends + Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onRequest' + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record ? TData[keyof TData] : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? (TData extends Record ? TData[keyof TData] : TData) | undefined + : ( + | { + data: TData extends Record ? TData[keyof TData] : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record ? TError[keyof TError] : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick>, 'method'>, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts new file mode 100644 index 0000000000..5162192d8a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts @@ -0,0 +1,316 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = (contentType: string | null): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type)) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e., their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = (request: Req, options: Options) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts new file mode 100644 index 0000000000..3ebf994788 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts @@ -0,0 +1,41 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..67daca60f8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts @@ -0,0 +1,82 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: unknown) => unknown; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: (body: unknown): FormData => { + const data = new FormData(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: unknown): string => + JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: (body: unknown): string => { + const data = new URLSearchParams(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts new file mode 100644 index 0000000000..7955601a5c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts @@ -0,0 +1,169 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = (args: ReadonlyArray, fields: FieldsConfig) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix)); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[key.slice(prefix.length)] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..994b2848c6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts @@ -0,0 +1,171 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions extends SerializePrimitiveOptions, SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..5000df606f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts @@ -0,0 +1,117 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b)); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined => { + if (value === null) { + return null; + } + + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + return value; + } + + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..ddf3c4d13a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts @@ -0,0 +1,242 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export function createSseClient({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult { + let lastEventId: string | undefined; + + const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings + + const chunks = buffer.split('\n\n'); + buffer = chunks.pop() ?? ''; + + for (const chunk of chunks) { + const lines = chunk.split('\n'); + const dataLines: Array = []; + let eventName: string | undefined; + + for (const line of lines) { + if (line.startsWith('data:')) { + dataLines.push(line.replace(/^data:\s*/, '')); + } else if (line.startsWith('event:')) { + eventName = line.replace(/^event:\s*/, ''); + } else if (line.startsWith('id:')) { + lastEventId = line.replace(/^id:\s*/, ''); + } else if (line.startsWith('retry:')) { + const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10); + if (!Number.isNaN(parsed)) { + retryDelay = parsed; + } + } + } + + let data: unknown; + let parsedJson = false; + + if (dataLines.length) { + const rawData = dataLines.join('\n'); + try { + data = JSON.parse(rawData); + parsedJson = true; + } catch { + data = rawData; + } + } + + if (parsedJson) { + if (responseValidator) { + await responseValidator(data); + } + + if (responseTransformer) { + data = await responseTransformer(data); + } + } + + onSseEvent?.({ + data, + event: eventName, + id: lastEventId, + retry: retryDelay, + }); + + if (dataLines.length) { + yield data as any; + } + } + } + } finally { + signal.removeEventListener('abort', abortHandler); + reader.releaseLock(); + } + + break; // exit loop on normal completion + } catch (error) { + // connection failed or aborted; retry after delay + onSseError?.(error); + + if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) { + break; // stop after firing error + } + + // exponential backoff: double retry each attempt, cap at 30s + const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000); + await sleep(backoff); + } + } + }; + + const stream = createStream(); + + return { stream }; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts new file mode 100644 index 0000000000..9efe71d4c1 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts @@ -0,0 +1,104 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + string | number | boolean | (string | number | boolean)[] | null | undefined | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g., converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true ? never : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts new file mode 100644 index 0000000000..9a4fec7830 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts @@ -0,0 +1,140 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace(match, serializeArrayParam({ explode, name, style, value })); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e., client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/index.ts new file mode 100644 index 0000000000..ee6d0288c0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export { callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexTypes, deleteCallWithoutParametersAndResponse, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, fooWow, getCallWithoutParametersAndResponse, headCallWithoutParametersAndResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, optionsCallWithoutParametersAndResponse, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionBody, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, serviceWithEmptyTag, testErrorCode, types } from './sdk.gen'; +export type { ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, Date, Default, DeleteCallWithoutParametersAndResponseData, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithStrings, ExternalRefA, ExternalRefB, ExternalSharedModel, FailureFailure, FooWowData, FooWowResponses, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ModelThatExtends, ModelThatExtendsExtends, ModelWithArray, ModelWithBoolean, ModelWithCircularReference, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithInteger, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableString, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, OptionsCallWithoutParametersAndResponseData, ParameterActivityParams, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyErrors, PostApiVbyApiVersionBodyResponse, PostApiVbyApiVersionBodyResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ResponsePostActivityResponse, ServiceWithEmptyTagData, SimpleBoolean, SimpleFile, SimpleInteger, SimpleReference, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses } from './types.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts new file mode 100644 index 0000000000..0f0e66cba9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts @@ -0,0 +1,127 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Client, Options as Options2, TDataShape } from './client'; +import { client } from './client.gen'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, FooWowResponses, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyErrors, PostApiVbyApiVersionBodyResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export const serviceWithEmptyTag = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no+tag', ...options }); + +export const patchApiVbyApiVersionNoTag = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/no+tag', ...options }); + +export const fooWow = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/no+tag', ...options }); + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/simple', ...options }); + +export const getCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple', ...options }); + +export const headCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).head({ url: '/api/v{api-version}/simple', ...options }); + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).options({ url: '/api/v{api-version}/simple', ...options }); + +export const patchCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/simple', ...options }); + +export const postCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/simple', ...options }); + +export const putCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/simple', ...options }); + +export const callWithDescriptions = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/descriptions/', ...options }); + +export const callWithParameters = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/parameters/{parameterPath}', ...options }); + +export const callWithWeirdParameterNames = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const callWithDefaultParameters = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterModel: { object: { explode: false, style: 'form' } } } }, + url: '/api/v{api-version}/defaults', + ...options +}); + +export const callWithDefaultOptionalParameters = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/defaults', ...options }); + +export const callToTestOrderOfParams = (options: Options) => (options.client ?? client).put({ url: '/api/v{api-version}/defaults', ...options }); + +export const duplicateName = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName2 = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName3 = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName4 = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/duplicate', ...options }); + +export const callWithNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no-content', ...options }); + +export const callWithResponseAndNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/response-and-no-content', ...options }); + +export const dummyA = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/a', ...options }); + +export const dummyB = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/b', ...options }); + +export const callWithResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/response', ...options }); + +export const callWithDuplicateResponses = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/response', ...options }); + +export const callWithResponses = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/response', ...options }); + +export const collectionFormat = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { + parameterArrayCSV: { array: { explode: false } }, + parameterArraySSV: { array: { explode: false } }, + parameterArrayTSV: { array: { explode: false } }, + parameterArrayPipes: { array: { explode: false } } + } }, + url: '/api/v{api-version}/collectionFormat', + ...options +}); + +export const types = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterArray: { array: { explode: false } }, parameterDictionary: { object: { explode: false, style: 'form' } } } }, + url: '/api/v{api-version}/types', + ...options +}); + +export const complexTypes = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterObject: { object: { explode: false, style: 'form' } }, parameterReference: { object: { explode: false, style: 'form' } } } }, + url: '/api/v{api-version}/complex', + ...options +}); + +export const callWithResultFromHeader = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/header', ...options }); + +export const testErrorCode = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/error', ...options }); + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', ...options }); + +/** + * Body should not be unknown + * + * Body should not be unknown + */ +export const postApiVbyApiVersionBody = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/body', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts new file mode 100644 index 0000000000..d69b074040 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts @@ -0,0 +1,1190 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +export type ExternalRefA = ExternalSharedModel; + +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + foo?: string; + bar?: string; +}>; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a type-only model that defines Date as a string + */ +export type Date = string; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp: string | null; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + test?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string; + }; + }; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +export type Default = { + name?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type ParameterActivityParams = { + description?: string; + graduate_id?: number; + organization_id?: number; + parent_activity?: number; + post_id?: number; +}; + +export type ResponsePostActivityResponse = { + description?: string; + graduate_id?: number; + organization_id?: number; + parent_activity_id?: number; + post_id?: number; +}; + +export type FailureFailure = { + error?: string; + message?: string; + reference_code?: string; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type ServiceWithEmptyTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions/'; +}; + +export type CallWithParametersData = { + body?: never; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query: { + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that is sent as request body + */ + body: string; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query: { + /** + * This is a simple string with default value + */ + parameterString: string; + /** + * This is a simple number with default value + */ + parameterNumber: number; + /** + * This is a simple boolean with default value + */ + parameterBoolean: boolean; + /** + * This is a simple enum with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a model with one string property + */ + parameterModel: { + /** + * This is a simple string property + */ + prop?: string; + }; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: unknown; +}; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithString; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean; + /** + * This is an array parameter + */ + parameterArray: Array; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + }; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * This is a model with one string property + */ + parameterReference: { + /** + * This is a simple string property + */ + prop?: string; + }; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: string; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: NonAsciiStringæøåÆøÅöôêÊ字符串; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PostApiVbyApiVersionBodyData = { + /** + * Body should not be unknown + */ + body: ParameterActivityParams; + path?: never; + query?: never; + url: '/api/v{api-version}/body'; +}; + +export type PostApiVbyApiVersionBodyErrors = { + /** + * Bad Request + */ + 400: FailureFailure; + /** + * Internal Server Error + */ + 500: FailureFailure; +}; + +export type PostApiVbyApiVersionBodyError = PostApiVbyApiVersionBodyErrors[keyof PostApiVbyApiVersionBodyErrors]; + +export type PostApiVbyApiVersionBodyResponses = { + /** + * OK + */ + 200: ResponsePostActivityResponse; +}; + +export type PostApiVbyApiVersionBodyResponse = PostApiVbyApiVersionBodyResponses[keyof PostApiVbyApiVersionBodyResponses]; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts index 6aa6cf02a4..ddf3c4d13a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts @@ -79,7 +79,7 @@ export type ServerSentEventsResult; }; -export const createSseClient = ({ +export function createSseClient({ onRequest, onSseError, onSseEvent, @@ -91,7 +91,7 @@ export const createSseClient = ({ sseSleepFn, url, ...options -}: ServerSentEventsOptions): ServerSentEventsResult => { +}: ServerSentEventsOptions): ServerSentEventsResult { let lastEventId: string | undefined; const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); @@ -155,8 +155,7 @@ export const createSseClient = ({ const { done, value } = await reader.read(); if (done) break; buffer += value; - // Normalize line endings: CRLF -> LF, then CR -> LF - buffer = buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); + buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings const chunks = buffer.split('\n\n'); buffer = chunks.pop() ?? ''; @@ -240,4 +239,4 @@ export const createSseClient = ({ const stream = createStream(); return { stream }; -}; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts new file mode 100644 index 0000000000..378082bd09 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts @@ -0,0 +1,760 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOptions, type UseMutationOptions } from '@tanstack/react-query'; + +import { client } from '../client.gen'; +import { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from '../sdk.gen'; +import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponse, DummyBData, DummyBResponse, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponse, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, TypesResponse, UploadFileData, UploadFileResponse } from '../types.gen'; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); + +export const exportOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await export_({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: exportQueryKey(options) +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const importMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await import_({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const fooWowMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await fooWow({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); + +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await apiVVersionODataControllerCount({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: apiVVersionODataControllerCountQueryKey(options) +}); + +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getApiVbyApiVersionSimpleOperation({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getApiVbyApiVersionSimpleOperationQueryKey(options) +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getCallWithoutParametersAndResponseQueryKey(options) +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const deleteFooMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await deleteFoo({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithDescriptionsMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDescriptions({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +/** + * @deprecated + */ +export const deprecatedCallMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await deprecatedCall({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithParametersMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithParameters({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); + +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getCallWithOptionalParam({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getCallWithOptionalParamQueryKey(options) +}); + +const createInfiniteParams = [0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey, page: K) => { + const params = { ...queryKey[0] }; + if (page.body) { + params.body = { + ...queryKey[0].body as any, + ...page.body as any + }; + } + if (page.headers) { + params.headers = { + ...queryKey[0].headers, + ...page.headers + }; + } + if (page.path) { + params.path = { + ...queryKey[0].path as any, + ...page.path as any + }; + } + if (page.query) { + params.query = { + ...queryKey[0].query as any, + ...page.query as any + }; + } + return params as unknown as typeof page; +}; + +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); + +export const getCallWithOptionalParamInfiniteOptions = (options: Options) => infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( +// @ts-ignore +{ + queryFn: async ({ pageParam, queryKey, signal }) => { + // @ts-ignore + const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { + query: { + page: pageParam + } + }; + const params = createInfiniteParams(queryKey, page); + const { data } = await getCallWithOptionalParam({ + ...options, + ...params, + signal, + throwOnError: true + }); + return data; + }, + queryKey: getCallWithOptionalParamInfiniteQueryKey(options) +}); + +export const postCallWithOptionalParamMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const postApiVbyApiVersionFormDataMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); + +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithDefaultParameters({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithDefaultParametersQueryKey(options) +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callToTestOrderOfParamsMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateNameMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); + +export const duplicateName2Options = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await duplicateName2({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: duplicateName2QueryKey(options) +}); + +export const duplicateName3Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName3({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateName4Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName4({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); + +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithNoContentResponseQueryKey(options) +}); + +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithResponseAndNoContentResponseQueryKey(options) +}); + +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); + +export const dummyAOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await dummyA({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: dummyAQueryKey(options) +}); + +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); + +export const dummyBOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await dummyB({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: dummyBQueryKey(options) +}); + +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); + +export const callWithResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithResponseQueryKey(options) +}); + +export const callWithDuplicateResponsesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithResponsesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithResponses({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); + +export const collectionFormatOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await collectionFormat({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: collectionFormatQueryKey(options) +}); + +export const typesQueryKey = (options: Options) => createQueryKey('types', options); + +export const typesOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await types({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: typesQueryKey(options) +}); + +export const uploadFileMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await uploadFile({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); + +export const fileResponseOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await fileResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: fileResponseQueryKey(options) +}); + +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); + +export const complexTypesOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await complexTypes({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: complexTypesQueryKey(options) +}); + +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); + +export const multipartResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await multipartResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: multipartResponseQueryKey(options) +}); + +export const multipartRequestMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await multipartRequest({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const complexParamsMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await complexParams({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithResultFromHeaderMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const testErrorCodeMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await testErrorCode({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +/** + * Login User + */ +export const putWithFormUrlEncodedMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts new file mode 100644 index 0000000000..25cd14eafb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig({ baseUrl: 'http://localhost:3000/base' })); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts new file mode 100644 index 0000000000..4fd22d49b2 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts @@ -0,0 +1,304 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors(); + + const beforeRequest = async < + TData = unknown, + TResponseStyle extends 'data' | 'fields' = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, + >( + options: RequestOptions, + ) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined as string | undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined; + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const resolvedOpts = opts as typeof opts & + ResolvedRequestOptions; + const url = buildUrl(resolvedOpts); + + return { opts: resolvedOpts, url }; + }; + + const request: Client['request'] = async (options) => { + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response: Response; + + try { + response = await _fetch(request); + } catch (error) { + // Handle fetch exceptions (AbortError, network errors, etc.) + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, undefined as any, request, opts)) as unknown; + } + } + + finalError = finalError || ({} as unknown); + + if (opts.throwOnError) { + throw finalError; + } + + // Return error response + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + request, + response: undefined as any, + }; + } + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if (response.status === 204 || response.headers.get('Content-Length') === '0') { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'text': + data = await response[parseAs](); + break; + case 'json': { + // Some servers return 200 with no Content-Length and empty body. + // response.json() would throw; read as text and parse if non-empty. + const text = await response.text(); + data = text ? JSON.parse(text) : {}; + break; + } + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined, + url, + }); + }; + + const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options }); + + return { + buildUrl: _buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts @@ -0,0 +1,25 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Auth } from '../core/auth.gen'; +export type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +export { + formDataBodySerializer, + jsonBodySerializer, + urlSearchParamsBodySerializer, +} from '../core/bodySerializer.gen'; +export { buildClientParams } from '../core/params.gen'; +export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'; +export { createClient } from './client.gen'; +export type { + Client, + ClientOptions, + Config, + CreateClientConfig, + Options, + RequestOptions, + RequestResult, + ResolvedRequestOptions, + ResponseStyle, + TDataShape, +} from './types.gen'; +export { createConfig, mergeHeaders } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts new file mode 100644 index 0000000000..9813eeaba6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts @@ -0,0 +1,214 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> + extends + Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onRequest' + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record ? TData[keyof TData] : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? (TData extends Record ? TData[keyof TData] : TData) | undefined + : ( + | { + data: TData extends Record ? TData[keyof TData] : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record ? TError[keyof TError] : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick>, 'method'>, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts new file mode 100644 index 0000000000..5162192d8a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts @@ -0,0 +1,316 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = (contentType: string | null): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type)) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e., their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = (request: Req, options: Options) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts new file mode 100644 index 0000000000..3ebf994788 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts @@ -0,0 +1,41 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..67daca60f8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts @@ -0,0 +1,82 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: unknown) => unknown; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: (body: unknown): FormData => { + const data = new FormData(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: unknown): string => + JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: (body: unknown): string => { + const data = new URLSearchParams(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts new file mode 100644 index 0000000000..7955601a5c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts @@ -0,0 +1,169 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = (args: ReadonlyArray, fields: FieldsConfig) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix)); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[key.slice(prefix.length)] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..994b2848c6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts @@ -0,0 +1,171 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions extends SerializePrimitiveOptions, SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..5000df606f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts @@ -0,0 +1,117 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b)); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined => { + if (value === null) { + return null; + } + + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + return value; + } + + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..ddf3c4d13a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts @@ -0,0 +1,242 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export function createSseClient({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult { + let lastEventId: string | undefined; + + const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings + + const chunks = buffer.split('\n\n'); + buffer = chunks.pop() ?? ''; + + for (const chunk of chunks) { + const lines = chunk.split('\n'); + const dataLines: Array = []; + let eventName: string | undefined; + + for (const line of lines) { + if (line.startsWith('data:')) { + dataLines.push(line.replace(/^data:\s*/, '')); + } else if (line.startsWith('event:')) { + eventName = line.replace(/^event:\s*/, ''); + } else if (line.startsWith('id:')) { + lastEventId = line.replace(/^id:\s*/, ''); + } else if (line.startsWith('retry:')) { + const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10); + if (!Number.isNaN(parsed)) { + retryDelay = parsed; + } + } + } + + let data: unknown; + let parsedJson = false; + + if (dataLines.length) { + const rawData = dataLines.join('\n'); + try { + data = JSON.parse(rawData); + parsedJson = true; + } catch { + data = rawData; + } + } + + if (parsedJson) { + if (responseValidator) { + await responseValidator(data); + } + + if (responseTransformer) { + data = await responseTransformer(data); + } + } + + onSseEvent?.({ + data, + event: eventName, + id: lastEventId, + retry: retryDelay, + }); + + if (dataLines.length) { + yield data as any; + } + } + } + } finally { + signal.removeEventListener('abort', abortHandler); + reader.releaseLock(); + } + + break; // exit loop on normal completion + } catch (error) { + // connection failed or aborted; retry after delay + onSseError?.(error); + + if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) { + break; // stop after firing error + } + + // exponential backoff: double retry each attempt, cap at 30s + const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000); + await sleep(backoff); + } + } + }; + + const stream = createStream(); + + return { stream }; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts new file mode 100644 index 0000000000..9efe71d4c1 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts @@ -0,0 +1,104 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + string | number | boolean | (string | number | boolean)[] | null | undefined | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g., converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true ? never : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts new file mode 100644 index 0000000000..9a4fec7830 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts @@ -0,0 +1,140 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace(match, serializeArrayParam({ explode, name, style, value })); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e., client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/index.ts new file mode 100644 index 0000000000..6e132194fd --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, headCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, optionsCallWithoutParametersAndResponse, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from './sdk.gen'; +export type { _3eNum1Период, _400, AdditionalPropertiesIntegerIssue, AdditionalPropertiesUnknownIssue, AdditionalPropertiesUnknownIssue2, AdditionalPropertiesUnknownIssue3, AdditionalPropertiesUnknownIssueWritable, AnyOfAnyAndNull, AnyOfArrays, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountResponses, ArrayWithAnyOfProperties, ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CamelCaseCommentWithBreaks, CharactersInDescription, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexParamsData, ComplexParamsResponse, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, CompositionBaseModel, CompositionExtendedModel, CompositionWithAllOfAndNullable, CompositionWithAnyOf, CompositionWithAnyOfAndNullable, CompositionWithAnyOfAnonymous, CompositionWithNestedAnyAndTypeNull, CompositionWithNestedAnyOfAndNull, CompositionWithOneOf, CompositionWithOneOfAndComplexArrayDictionary, CompositionWithOneOfAndNullable, CompositionWithOneOfAndProperties, CompositionWithOneOfAndSimpleArrayDictionary, CompositionWithOneOfAndSimpleDictionary, CompositionWithOneOfAnonymous, CompositionWithOneOfDiscriminator, ConstValue, Default, DeleteCallWithoutParametersAndResponseData, DeleteFooData, DeleteFooData2, DeleteFooData3, DeprecatedCallData, DeprecatedModel, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithPropertiesAndAdditionalProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponse, DummyAResponses, DummyBData, DummyBResponse, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithReplacedCharacters, EnumWithStrings, EnumWithXEnumNames, ExportData, ExternalRefA, ExternalRefB, ExternalSharedModel, File, FileResponseData, FileResponseResponse, FileResponseResponses, FileWritable, FooWowData, FooWowResponses, FreeFormObjectWithAdditionalPropertiesEqEmptyObject, FreeFormObjectWithAdditionalPropertiesEqTrue, FreeFormObjectWithoutAdditionalProperties, GenericSchemaDuplicateIssue1SystemBoolean, GenericSchemaDuplicateIssue1SystemBooleanWritable, GenericSchemaDuplicateIssue1SystemString, GenericSchemaDuplicateIssue1SystemStringWritable, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, Import, ImportData, ImportResponse, ImportResponses, IoK8sApimachineryPkgApisMetaV1DeleteOptions, IoK8sApimachineryPkgApisMetaV1Preconditions, ModelCircle, ModelFromZendesk, ModelSquare, ModelThatExtends, ModelThatExtendsExtends, ModelWithAdditionalPropertiesEqTrue, ModelWithAdditionalPropertiesRef, ModelWithAnyOfConstantSizeArray, ModelWithAnyOfConstantSizeArrayAndIntersect, ModelWithAnyOfConstantSizeArrayNullable, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable, ModelWithArray, ModelWithArrayReadOnlyAndWriteOnly, ModelWithArrayReadOnlyAndWriteOnlyWritable, ModelWithBackticksInDescription, ModelWithBoolean, ModelWithCircularReference, ModelWithConst, ModelWithConstantSizeArray, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithEnumWithHyphen, ModelWithInteger, ModelWithNestedArrayEnums, ModelWithNestedArrayEnumsData, ModelWithNestedArrayEnumsDataBar, ModelWithNestedArrayEnumsDataFoo, ModelWithNestedCompositionEnums, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableObject, ModelWithNullableString, ModelWithNumericEnumUnion, ModelWithOneOfAndProperties, ModelWithOneOfEnum, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithPrefixItemsConstantSizeArray, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnlyWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, MultipartResponseResponses, NestedAnyOfArraysNullable, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, NullableObject, OneOfAllOfIssue, OneOfAllOfIssueWritable, OptionsCallWithoutParametersAndResponseData, Pageable, ParameterSimpleParameterUnused, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PostServiceWithEmptyTagResponse, PostServiceWithEmptyTagResponse2, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, SchemaWithFormRestrictedKeys, SimpleBoolean, SimpleFile, SimpleFormData, SimpleInteger, SimpleParameter, SimpleReference, SimpleRequestBody, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses, UploadFileData, UploadFileResponse, UploadFileResponses, XFooBar } from './types.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts new file mode 100644 index 0000000000..fbc4ca77fb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts @@ -0,0 +1,206 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type Client, formDataBodySerializer, type Options as Options2, type TDataShape, urlSearchParamsBodySerializer } from './client'; +import { client } from './client.gen'; +import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponses, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponses, FooWowData, FooWowResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ImportData, ImportResponses, MultipartRequestData, MultipartResponseData, MultipartResponseResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses, UploadFileData, UploadFileResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export const export_ = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no+tag', ...options }); + +export const patchApiVbyApiVersionNoTag = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/no+tag', ...options }); + +export const import_ = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/no+tag', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const fooWow = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/no+tag', ...options }); + +export const apiVVersionODataControllerCount = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple/$count', ...options }); + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/simple:operation', ...options }); + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/simple', ...options }); + +export const getCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple', ...options }); + +export const headCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).head({ url: '/api/v{api-version}/simple', ...options }); + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).options({ url: '/api/v{api-version}/simple', ...options }); + +export const patchCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/simple', ...options }); + +export const postCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/simple', ...options }); + +export const putCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/simple', ...options }); + +export const deleteFoo = (options: Options) => (options.client ?? client).delete({ url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', ...options }); + +export const callWithDescriptions = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/descriptions', ...options }); + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/parameters/deprecated', ...options }); + +export const callWithParameters = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const callWithWeirdParameterNames = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const getCallWithOptionalParam = (options: Options) => (options.client ?? client).get({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const postCallWithOptionalParam = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const postApiVbyApiVersionRequestBody = (options?: Options) => (options?.client ?? client).post({ + url: '/api/v{api-version}/requestBody', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } +}); + +export const postApiVbyApiVersionFormData = (options?: Options) => (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/formData', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } +}); + +export const callWithDefaultParameters = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/defaults', ...options }); + +export const callWithDefaultOptionalParameters = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/defaults', ...options }); + +export const callToTestOrderOfParams = (options: Options) => (options.client ?? client).put({ url: '/api/v{api-version}/defaults', ...options }); + +export const duplicateName = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName2 = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName3 = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName4 = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/duplicate', ...options }); + +export const callWithNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no-content', ...options }); + +export const callWithResponseAndNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/response-and-no-content', ...options }); + +export const dummyA = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/a', ...options }); + +export const dummyB = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/b', ...options }); + +export const callWithResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/response', ...options }); + +export const callWithDuplicateResponses = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/response', ...options }); + +export const callWithResponses = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/response', ...options }); + +export const collectionFormat = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/collectionFormat', ...options }); + +export const types = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/types', ...options }); + +export const uploadFile = (options: Options) => (options.client ?? client).post({ + ...urlSearchParamsBodySerializer, + url: '/api/v{api-version}/upload', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } +}); + +export const fileResponse = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/file/{id}', ...options }); + +export const complexTypes = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterObject: { object: { style: 'form' } } } }, + url: '/api/v{api-version}/complex', + ...options +}); + +export const multipartResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multipart', ...options }); + +export const multipartRequest = (options?: Options) => (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/multipart', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } +}); + +export const complexParams = (options: Options) => (options.client ?? client).put({ + url: '/api/v{api-version}/complex/{id}', + ...options, + headers: { + 'Content-Type': 'application/json-patch+json', + ...options.headers + } +}); + +export const callWithResultFromHeader = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/header', ...options }); + +export const testErrorCode = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/error', ...options }); + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', ...options }); + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => (options.client ?? client).put({ + ...urlSearchParamsBodySerializer, + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts new file mode 100644 index 0000000000..3287ee8737 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts @@ -0,0 +1,2081 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +/** + * Model with number-only name + */ +export type _400 = string; + +export type ExternalRefA = ExternalSharedModel; + +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CamelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = '\'Single Quote\'' | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: CamelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type ModelFromZendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + /** + * Foo-Bar-Baz-Qux + */ + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind: 'circle'; +} & ModelCircle) | ({ + kind: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3eNum1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + propA?: Array<_3eNum1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type File = { + /** + * Id + */ + readonly id?: string; + /** + * Updated at + */ + readonly updated_at?: string; + /** + * Created at + */ + readonly created_at?: string; + /** + * Mime + */ + mime: string; + /** + * File + */ + readonly file?: string; +}; + +export type Default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { + [key: string]: unknown; +}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: unknown; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆøÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +/** + * An object with additional properties that can be null + */ +export type ModelWithAdditionalPropertiesRef = { + [key: string]: NullableObject | null; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = Array; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | Import, + number | Import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆøÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type Import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: IoK8sApimachineryPkgApisMetaV1Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBoolean = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemString = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnlyWritable = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type FileWritable = { + /** + * Mime + */ + mime: string; +}; + +export type ModelWithReadOnlyAndWriteOnlyWritable = { + foo: string; + baz: string; +}; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = [ + number | Import, + number | Import +]; + +export type AdditionalPropertiesUnknownIssueWritable = { + [key: string]: string | number; +}; + +export type OneOfAllOfIssueWritable = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBooleanWritable = { + item?: boolean; + error?: string | null; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemStringWritable = { + item?: string | null; + error?: string | null; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type XFooBar = ModelWithString; + +export type SimpleRequestBody = ModelWithString; + +export type SimpleFormData = ModelWithString; + +export type ExportData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ImportData = { + body: ModelWithReadOnlyAndWriteOnlyWritable | ModelWithArrayReadOnlyAndWriteOnlyWritable; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type ImportResponses = { + /** + * Success + */ + 200: ModelFromZendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ApiVVersionODataControllerCountData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple/$count'; +}; + +export type ApiVVersionODataControllerCountResponses = { + /** + * Success + */ + 200: ModelFromZendesk; +}; + +export type ApiVVersionODataControllerCountResponse = ApiVVersionODataControllerCountResponses[keyof ApiVVersionODataControllerCountResponses]; + +export type GetApiVbyApiVersionSimpleOperationData = { + body?: never; + path: { + /** + * foo in method + */ + foo_param: string; + }; + query?: never; + url: '/api/v{api-version}/simple:operation'; +}; + +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type DeleteFooData3 = { + body?: never; + headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + path: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + query?: never; + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions'; +}; + +export type DeprecatedCallData = { + body?: never; + headers: { + /** + * This parameter is deprecated + * + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/parameters/deprecated'; +}; + +export type CallWithParametersData = { + /** + * This is the parameter that goes into the body + */ + body: { + [key: string]: unknown; + } | null; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that goes into the body + */ + body: ModelWithString | null; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is a required parameter + */ + body: ModelWithOneOfEnum; + path?: never; + query?: { + /** + * This is an optional parameter + */ + page?: number; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + body?: { + offset?: number | null; + }; + path?: never; + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; + +export type PostApiVbyApiVersionRequestBodyData = { + /** + * A reusable request body + */ + body?: SimpleRequestBody; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/requestBody'; +}; + +export type PostApiVbyApiVersionFormDataData = { + /** + * A reusable request body + */ + body?: SimpleFormData; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/formData'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; + +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + 200: _400; +}; + +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; + +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + default: Import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type UploadFileData = { + body: Blob | File; + path: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query?: never; + url: '/api/v{api-version}/upload'; +}; + +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; + +export type FileResponseData = { + body?: never; + path: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/file/{id}'; +}; + +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }; +}; + +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + +export type MultipartRequestData = { + body?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type ComplexParamsData = { + body?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + path: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/complex/{id}'; +}; + +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: number; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PutWithFormUrlEncodedData = { + body: ArrayWithStrings; + path?: never; + query?: never; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts index 6aa6cf02a4..ddf3c4d13a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts @@ -79,7 +79,7 @@ export type ServerSentEventsResult; }; -export const createSseClient = ({ +export function createSseClient({ onRequest, onSseError, onSseEvent, @@ -91,7 +91,7 @@ export const createSseClient = ({ sseSleepFn, url, ...options -}: ServerSentEventsOptions): ServerSentEventsResult => { +}: ServerSentEventsOptions): ServerSentEventsResult { let lastEventId: string | undefined; const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); @@ -155,8 +155,7 @@ export const createSseClient = ({ const { done, value } = await reader.read(); if (done) break; buffer += value; - // Normalize line endings: CRLF -> LF, then CR -> LF - buffer = buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); + buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings const chunks = buffer.split('\n\n'); buffer = chunks.pop() ?? ''; @@ -240,4 +239,4 @@ export const createSseClient = ({ const stream = createStream(); return { stream }; -}; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts new file mode 100644 index 0000000000..378082bd09 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/@tanstack/react-query.gen.ts @@ -0,0 +1,760 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOptions, type UseMutationOptions } from '@tanstack/react-query'; + +import { client } from '../client.gen'; +import { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from '../sdk.gen'; +import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseData, CallWithResponseResponse, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, ComplexTypesResponse, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponse, DummyBData, DummyBResponse, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponse, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, TypesResponse, UploadFileData, UploadFileResponse } from '../types.gen'; + +export type QueryKey = [ + Pick & { + _id: string; + _infinite?: boolean; + tags?: ReadonlyArray; + } +]; + +const createQueryKey = (id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray): [ + QueryKey[0] +] => { + const params: QueryKey[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey[0]; + if (infinite) { + params._infinite = infinite; + } + if (tags) { + params.tags = tags; + } + if (options?.body) { + params.body = options.body; + } + if (options?.headers) { + params.headers = options.headers; + } + if (options?.path) { + params.path = options.path; + } + if (options?.query) { + params.query = options.query; + } + return [params]; +}; + +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); + +export const exportOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await export_({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: exportQueryKey(options) +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const importMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await import_({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const fooWowMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await fooWow({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); + +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await apiVVersionODataControllerCount({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: apiVVersionODataControllerCountQueryKey(options) +}); + +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getApiVbyApiVersionSimpleOperation({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getApiVbyApiVersionSimpleOperationQueryKey(options) +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getCallWithoutParametersAndResponseQueryKey(options) +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const deleteFooMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await deleteFoo({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithDescriptionsMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDescriptions({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +/** + * @deprecated + */ +export const deprecatedCallMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await deprecatedCall({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithParametersMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithParameters({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); + +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await getCallWithOptionalParam({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: getCallWithOptionalParamQueryKey(options) +}); + +const createInfiniteParams = [0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey, page: K) => { + const params = { ...queryKey[0] }; + if (page.body) { + params.body = { + ...queryKey[0].body as any, + ...page.body as any + }; + } + if (page.headers) { + params.headers = { + ...queryKey[0].headers, + ...page.headers + }; + } + if (page.path) { + params.path = { + ...queryKey[0].path as any, + ...page.path as any + }; + } + if (page.query) { + params.query = { + ...queryKey[0].query as any, + ...page.query as any + }; + } + return params as unknown as typeof page; +}; + +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); + +export const getCallWithOptionalParamInfiniteOptions = (options: Options) => infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( +// @ts-ignore +{ + queryFn: async ({ pageParam, queryKey, signal }) => { + // @ts-ignore + const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { + query: { + page: pageParam + } + }; + const params = createInfiniteParams(queryKey, page); + const { data } = await getCallWithOptionalParam({ + ...options, + ...params, + signal, + throwOnError: true + }); + return data; + }, + queryKey: getCallWithOptionalParamInfiniteQueryKey(options) +}); + +export const postCallWithOptionalParamMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const postApiVbyApiVersionFormDataMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); + +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithDefaultParameters({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithDefaultParametersQueryKey(options) +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callToTestOrderOfParamsMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateNameMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); + +export const duplicateName2Options = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await duplicateName2({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: duplicateName2QueryKey(options) +}); + +export const duplicateName3Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName3({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const duplicateName4Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await duplicateName4({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); + +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithNoContentResponseQueryKey(options) +}); + +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithResponseAndNoContentResponseQueryKey(options) +}); + +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); + +export const dummyAOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await dummyA({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: dummyAQueryKey(options) +}); + +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); + +export const dummyBOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await dummyB({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: dummyBQueryKey(options) +}); + +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); + +export const callWithResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await callWithResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: callWithResponseQueryKey(options) +}); + +export const callWithDuplicateResponsesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithResponsesMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithResponses({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); + +export const collectionFormatOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await collectionFormat({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: collectionFormatQueryKey(options) +}); + +export const typesQueryKey = (options: Options) => createQueryKey('types', options); + +export const typesOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await types({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: typesQueryKey(options) +}); + +export const uploadFileMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await uploadFile({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); + +export const fileResponseOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await fileResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: fileResponseQueryKey(options) +}); + +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); + +export const complexTypesOptions = (options: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await complexTypes({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: complexTypesQueryKey(options) +}); + +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); + +export const multipartResponseOptions = (options?: Options) => queryOptions>({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await multipartResponse({ + ...options, + ...queryKey[0], + signal, + throwOnError: true + }); + return data; + }, + queryKey: multipartResponseQueryKey(options) +}); + +export const multipartRequestMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await multipartRequest({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const complexParamsMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await complexParams({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const callWithResultFromHeaderMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const testErrorCodeMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await testErrorCode({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +/** + * Login User + */ +export const putWithFormUrlEncodedMutation = (options?: Partial>): UseMutationOptions> => { + const mutationOptions: UseMutationOptions> = { + mutationFn: async (fnOptions) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...fnOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts new file mode 100644 index 0000000000..25cd14eafb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig({ baseUrl: 'http://localhost:3000/base' })); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts new file mode 100644 index 0000000000..4fd22d49b2 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/client.gen.ts @@ -0,0 +1,304 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors(); + + const beforeRequest = async < + TData = unknown, + TResponseStyle extends 'data' | 'fields' = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, + >( + options: RequestOptions, + ) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined as string | undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined; + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const resolvedOpts = opts as typeof opts & + ResolvedRequestOptions; + const url = buildUrl(resolvedOpts); + + return { opts: resolvedOpts, url }; + }; + + const request: Client['request'] = async (options) => { + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response: Response; + + try { + response = await _fetch(request); + } catch (error) { + // Handle fetch exceptions (AbortError, network errors, etc.) + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, undefined as any, request, opts)) as unknown; + } + } + + finalError = finalError || ({} as unknown); + + if (opts.throwOnError) { + throw finalError; + } + + // Return error response + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + request, + response: undefined as any, + }; + } + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if (response.status === 204 || response.headers.get('Content-Length') === '0') { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'text': + data = await response[parseAs](); + break; + case 'json': { + // Some servers return 200 with no Content-Length and empty body. + // response.json() would throw; read as text and parse if non-empty. + const text = await response.text(); + data = text ? JSON.parse(text) : {}; + break; + } + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + if (opts.responseStyle === 'fields') { + throw { + error: finalError, + ...result, + }; + } + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined, + url, + }); + }; + + const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options }); + + return { + buildUrl: _buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/index.ts @@ -0,0 +1,25 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type { Auth } from '../core/auth.gen'; +export type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +export { + formDataBodySerializer, + jsonBodySerializer, + urlSearchParamsBodySerializer, +} from '../core/bodySerializer.gen'; +export { buildClientParams } from '../core/params.gen'; +export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'; +export { createClient } from './client.gen'; +export type { + Client, + ClientOptions, + Config, + CreateClientConfig, + Options, + RequestOptions, + RequestResult, + ResolvedRequestOptions, + ResponseStyle, + TDataShape, +} from './types.gen'; +export { createConfig, mergeHeaders } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts new file mode 100644 index 0000000000..9813eeaba6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/types.gen.ts @@ -0,0 +1,214 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> + extends + Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onRequest' + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record ? TData[keyof TData] : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? (TData extends Record ? TData[keyof TData] : TData) | undefined + : ( + | { + data: TData extends Record ? TData[keyof TData] : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record ? TError[keyof TError] : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick>, 'method'>, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts new file mode 100644 index 0000000000..5162192d8a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/client/utils.gen.ts @@ -0,0 +1,316 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = (contentType: string | null): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type)) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e., their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = (request: Req, options: Options) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts new file mode 100644 index 0000000000..3ebf994788 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/auth.gen.ts @@ -0,0 +1,41 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..67daca60f8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/bodySerializer.gen.ts @@ -0,0 +1,82 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: unknown) => unknown; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: (body: unknown): FormData => { + const data = new FormData(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: unknown): string => + JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: (body: unknown): string => { + const data = new URLSearchParams(); + + Object.entries(body as Record).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts new file mode 100644 index 0000000000..7955601a5c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/params.gen.ts @@ -0,0 +1,169 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = (args: ReadonlyArray, fields: FieldsConfig) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix)); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[key.slice(prefix.length)] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..994b2848c6 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/pathSerializer.gen.ts @@ -0,0 +1,171 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions extends SerializePrimitiveOptions, SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..5000df606f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/queryKeySerializer.gen.ts @@ -0,0 +1,117 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b)); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined => { + if (value === null) { + return null; + } + + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + return value; + } + + if (value === undefined || typeof value === 'function' || typeof value === 'symbol') { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..ddf3c4d13a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/serverSentEvents.gen.ts @@ -0,0 +1,242 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export function createSseClient({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult { + let lastEventId: string | undefined; + + const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings + + const chunks = buffer.split('\n\n'); + buffer = chunks.pop() ?? ''; + + for (const chunk of chunks) { + const lines = chunk.split('\n'); + const dataLines: Array = []; + let eventName: string | undefined; + + for (const line of lines) { + if (line.startsWith('data:')) { + dataLines.push(line.replace(/^data:\s*/, '')); + } else if (line.startsWith('event:')) { + eventName = line.replace(/^event:\s*/, ''); + } else if (line.startsWith('id:')) { + lastEventId = line.replace(/^id:\s*/, ''); + } else if (line.startsWith('retry:')) { + const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10); + if (!Number.isNaN(parsed)) { + retryDelay = parsed; + } + } + } + + let data: unknown; + let parsedJson = false; + + if (dataLines.length) { + const rawData = dataLines.join('\n'); + try { + data = JSON.parse(rawData); + parsedJson = true; + } catch { + data = rawData; + } + } + + if (parsedJson) { + if (responseValidator) { + await responseValidator(data); + } + + if (responseTransformer) { + data = await responseTransformer(data); + } + } + + onSseEvent?.({ + data, + event: eventName, + id: lastEventId, + retry: retryDelay, + }); + + if (dataLines.length) { + yield data as any; + } + } + } + } finally { + signal.removeEventListener('abort', abortHandler); + reader.releaseLock(); + } + + break; // exit loop on normal completion + } catch (error) { + // connection failed or aborted; retry after delay + onSseError?.(error); + + if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) { + break; // stop after firing error + } + + // exponential backoff: double retry each attempt, cap at 30s + const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000); + await sleep(backoff); + } + } + }; + + const stream = createStream(); + + return { stream }; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts new file mode 100644 index 0000000000..9efe71d4c1 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/types.gen.ts @@ -0,0 +1,104 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + string | number | boolean | (string | number | boolean)[] | null | undefined | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g., converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true ? never : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts new file mode 100644 index 0000000000..9a4fec7830 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/core/utils.gen.ts @@ -0,0 +1,140 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace(match, serializeArrayParam({ explode, name, style, value })); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e., client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/index.ts new file mode 100644 index 0000000000..6e132194fd --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export { apiVVersionODataControllerCount, callToTestOrderOfParams, callWithDefaultOptionalParameters, callWithDefaultParameters, callWithDescriptions, callWithDuplicateResponses, callWithNoContentResponse, callWithParameters, callWithResponse, callWithResponseAndNoContentResponse, callWithResponses, callWithResultFromHeader, callWithWeirdParameterNames, collectionFormat, complexParams, complexTypes, deleteCallWithoutParametersAndResponse, deleteFoo, deprecatedCall, dummyA, dummyB, duplicateName, duplicateName2, duplicateName3, duplicateName4, export_, fileResponse, fooWow, getApiVbyApiVersionSimpleOperation, getCallWithOptionalParam, getCallWithoutParametersAndResponse, headCallWithoutParametersAndResponse, import_, multipartRequest, multipartResponse, nonAsciiæøåÆøÅöôêÊ字符串, type Options, optionsCallWithoutParametersAndResponse, patchApiVbyApiVersionNoTag, patchCallWithoutParametersAndResponse, postApiVbyApiVersionFormData, postApiVbyApiVersionRequestBody, postCallWithOptionalParam, postCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, putWithFormUrlEncoded, testErrorCode, types, uploadFile } from './sdk.gen'; +export type { _3eNum1Период, _400, AdditionalPropertiesIntegerIssue, AdditionalPropertiesUnknownIssue, AdditionalPropertiesUnknownIssue2, AdditionalPropertiesUnknownIssue3, AdditionalPropertiesUnknownIssueWritable, AnyOfAnyAndNull, AnyOfArrays, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountResponses, ArrayWithAnyOfProperties, ArrayWithArray, ArrayWithBooleans, ArrayWithNumbers, ArrayWithProperties, ArrayWithReferences, ArrayWithStrings, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponse, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesError, CallWithResponsesErrors, CallWithResponsesResponse, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CamelCaseCommentWithBreaks, CharactersInDescription, ClientOptions, CollectionFormatData, CommentWithBackticks, CommentWithBackticksAndQuotes, CommentWithBreaks, CommentWithExpressionPlaceholders, CommentWithQuotes, CommentWithReservedCharacters, CommentWithSlashes, ComplexParamsData, ComplexParamsResponse, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponse, ComplexTypesResponses, CompositionBaseModel, CompositionExtendedModel, CompositionWithAllOfAndNullable, CompositionWithAnyOf, CompositionWithAnyOfAndNullable, CompositionWithAnyOfAnonymous, CompositionWithNestedAnyAndTypeNull, CompositionWithNestedAnyOfAndNull, CompositionWithOneOf, CompositionWithOneOfAndComplexArrayDictionary, CompositionWithOneOfAndNullable, CompositionWithOneOfAndProperties, CompositionWithOneOfAndSimpleArrayDictionary, CompositionWithOneOfAndSimpleDictionary, CompositionWithOneOfAnonymous, CompositionWithOneOfDiscriminator, ConstValue, Default, DeleteCallWithoutParametersAndResponseData, DeleteFooData, DeleteFooData2, DeleteFooData3, DeprecatedCallData, DeprecatedModel, DictionaryWithArray, DictionaryWithDictionary, DictionaryWithProperties, DictionaryWithPropertiesAndAdditionalProperties, DictionaryWithReference, DictionaryWithString, DummyAData, DummyAResponse, DummyAResponses, DummyBData, DummyBResponse, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, EnumFromDescription, EnumWithExtensions, EnumWithNumbers, EnumWithReplacedCharacters, EnumWithStrings, EnumWithXEnumNames, ExportData, ExternalRefA, ExternalRefB, ExternalSharedModel, File, FileResponseData, FileResponseResponse, FileResponseResponses, FileWritable, FooWowData, FooWowResponses, FreeFormObjectWithAdditionalPropertiesEqEmptyObject, FreeFormObjectWithAdditionalPropertiesEqTrue, FreeFormObjectWithoutAdditionalProperties, GenericSchemaDuplicateIssue1SystemBoolean, GenericSchemaDuplicateIssue1SystemBooleanWritable, GenericSchemaDuplicateIssue1SystemString, GenericSchemaDuplicateIssue1SystemStringWritable, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, Import, ImportData, ImportResponse, ImportResponses, IoK8sApimachineryPkgApisMetaV1DeleteOptions, IoK8sApimachineryPkgApisMetaV1Preconditions, ModelCircle, ModelFromZendesk, ModelSquare, ModelThatExtends, ModelThatExtendsExtends, ModelWithAdditionalPropertiesEqTrue, ModelWithAdditionalPropertiesRef, ModelWithAnyOfConstantSizeArray, ModelWithAnyOfConstantSizeArrayAndIntersect, ModelWithAnyOfConstantSizeArrayNullable, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions, ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable, ModelWithArray, ModelWithArrayReadOnlyAndWriteOnly, ModelWithArrayReadOnlyAndWriteOnlyWritable, ModelWithBackticksInDescription, ModelWithBoolean, ModelWithCircularReference, ModelWithConst, ModelWithConstantSizeArray, ModelWithDictionary, ModelWithDuplicateImports, ModelWithDuplicateProperties, ModelWithEnum, ModelWithEnumFromDescription, ModelWithEnumWithHyphen, ModelWithInteger, ModelWithNestedArrayEnums, ModelWithNestedArrayEnumsData, ModelWithNestedArrayEnumsDataBar, ModelWithNestedArrayEnumsDataFoo, ModelWithNestedCompositionEnums, ModelWithNestedEnums, ModelWithNestedProperties, ModelWithNullableObject, ModelWithNullableString, ModelWithNumericEnumUnion, ModelWithOneOfAndProperties, ModelWithOneOfEnum, ModelWithOrderedProperties, ModelWithPattern, ModelWithPatternWritable, ModelWithPrefixItemsConstantSizeArray, ModelWithProperties, ModelWithPropertiesWritable, ModelWithReadOnlyAndWriteOnly, ModelWithReadOnlyAndWriteOnlyWritable, ModelWithReference, ModelWithReferenceWritable, ModelWithString, ModelWithStringError, MultipartRequestData, MultipartResponseData, MultipartResponseResponse, MultipartResponseResponses, NestedAnyOfArraysNullable, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Responses, NonAsciiStringæøåÆøÅöôêÊ字符串, NullableObject, OneOfAllOfIssue, OneOfAllOfIssueWritable, OptionsCallWithoutParametersAndResponseData, Pageable, ParameterSimpleParameterUnused, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PostServiceWithEmptyTagResponse, PostServiceWithEmptyTagResponse2, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, SchemaWithFormRestrictedKeys, SimpleBoolean, SimpleFile, SimpleFormData, SimpleInteger, SimpleParameter, SimpleReference, SimpleRequestBody, SimpleString, SimpleStringWithPattern, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponse, TypesResponses, UploadFileData, UploadFileResponse, UploadFileResponses, XFooBar } from './types.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts new file mode 100644 index 0000000000..fbc4ca77fb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/sdk.gen.ts @@ -0,0 +1,206 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type Client, formDataBodySerializer, type Options as Options2, type TDataShape, urlSearchParamsBodySerializer } from './client'; +import { client } from './client.gen'; +import type { ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponses, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesErrors, CallWithDuplicateResponsesResponses, CallWithNoContentResponseData, CallWithNoContentResponseResponses, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponses, CallWithResponseData, CallWithResponseResponses, CallWithResponsesData, CallWithResponsesErrors, CallWithResponsesResponses, CallWithResultFromHeaderData, CallWithResultFromHeaderErrors, CallWithResultFromHeaderResponses, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponses, ComplexTypesData, ComplexTypesErrors, ComplexTypesResponses, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyAResponses, DummyBData, DummyBResponses, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FileResponseResponses, FooWowData, FooWowResponses, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationErrors, GetApiVbyApiVersionSimpleOperationResponses, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, ImportData, ImportResponses, MultipartRequestData, MultipartResponseData, MultipartResponseResponses, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Responses, OptionsCallWithoutParametersAndResponseData, PatchApiVbyApiVersionNoTagData, PatchApiVbyApiVersionNoTagResponses, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponses, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TestErrorCodeErrors, TestErrorCodeResponses, TypesData, TypesResponses, UploadFileData, UploadFileResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export const export_ = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no+tag', ...options }); + +export const patchApiVbyApiVersionNoTag = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/no+tag', ...options }); + +export const import_ = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/no+tag', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const fooWow = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/no+tag', ...options }); + +export const apiVVersionODataControllerCount = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple/$count', ...options }); + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/simple:operation', ...options }); + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/simple', ...options }); + +export const getCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/simple', ...options }); + +export const headCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).head({ url: '/api/v{api-version}/simple', ...options }); + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).options({ url: '/api/v{api-version}/simple', ...options }); + +export const patchCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).patch({ url: '/api/v{api-version}/simple', ...options }); + +export const postCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/simple', ...options }); + +export const putCallWithoutParametersAndResponse = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/simple', ...options }); + +export const deleteFoo = (options: Options) => (options.client ?? client).delete({ url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', ...options }); + +export const callWithDescriptions = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/descriptions', ...options }); + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/parameters/deprecated', ...options }); + +export const callWithParameters = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const callWithWeirdParameterNames = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const getCallWithOptionalParam = (options: Options) => (options.client ?? client).get({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const postCallWithOptionalParam = (options: Options) => (options.client ?? client).post({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } +}); + +export const postApiVbyApiVersionRequestBody = (options?: Options) => (options?.client ?? client).post({ + url: '/api/v{api-version}/requestBody', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } +}); + +export const postApiVbyApiVersionFormData = (options?: Options) => (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/formData', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } +}); + +export const callWithDefaultParameters = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/defaults', ...options }); + +export const callWithDefaultOptionalParameters = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/defaults', ...options }); + +export const callToTestOrderOfParams = (options: Options) => (options.client ?? client).put({ url: '/api/v{api-version}/defaults', ...options }); + +export const duplicateName = (options?: Options) => (options?.client ?? client).delete({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName2 = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName3 = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/duplicate', ...options }); + +export const duplicateName4 = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/duplicate', ...options }); + +export const callWithNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/no-content', ...options }); + +export const callWithResponseAndNoContentResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/response-and-no-content', ...options }); + +export const dummyA = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/a', ...options }); + +export const dummyB = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multiple-tags/b', ...options }); + +export const callWithResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/response', ...options }); + +export const callWithDuplicateResponses = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/response', ...options }); + +export const callWithResponses = (options?: Options) => (options?.client ?? client).put({ url: '/api/v{api-version}/response', ...options }); + +export const collectionFormat = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/collectionFormat', ...options }); + +export const types = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/types', ...options }); + +export const uploadFile = (options: Options) => (options.client ?? client).post({ + ...urlSearchParamsBodySerializer, + url: '/api/v{api-version}/upload', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } +}); + +export const fileResponse = (options: Options) => (options.client ?? client).get({ url: '/api/v{api-version}/file/{id}', ...options }); + +export const complexTypes = (options: Options) => (options.client ?? client).get({ + querySerializer: { parameters: { parameterObject: { object: { style: 'form' } } } }, + url: '/api/v{api-version}/complex', + ...options +}); + +export const multipartResponse = (options?: Options) => (options?.client ?? client).get({ url: '/api/v{api-version}/multipart', ...options }); + +export const multipartRequest = (options?: Options) => (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/multipart', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } +}); + +export const complexParams = (options: Options) => (options.client ?? client).put({ + url: '/api/v{api-version}/complex/{id}', + ...options, + headers: { + 'Content-Type': 'application/json-patch+json', + ...options.headers + } +}); + +export const callWithResultFromHeader = (options?: Options) => (options?.client ?? client).post({ url: '/api/v{api-version}/header', ...options }); + +export const testErrorCode = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/error', ...options }); + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => (options.client ?? client).post({ url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', ...options }); + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => (options.client ?? client).put({ + ...urlSearchParamsBodySerializer, + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts new file mode 100644 index 0000000000..d819316644 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts @@ -0,0 +1,2100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +/** + * Model with number-only name + */ +export type _400 = string; + +/** + * External ref to shared model (A) + */ +export type ExternalRefA = ExternalSharedModel; + +/** + * External ref to shared model (B) + */ +export type ExternalRefB = ExternalSharedModel; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CamelCaseCommentWithBreaks = number; + +/** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ +export type CommentWithBreaks = number; + +/** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ +export type CommentWithBackticks = number; + +/** + * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work + */ +export type CommentWithBackticksAndQuotes = number; + +/** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ +export type CommentWithSlashes = number; + +/** + * Testing expression placeholders in string: ${expression} should work + */ +export type CommentWithExpressionPlaceholders = number; + +/** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ +export type CommentWithQuotes = number; + +/** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ +export type CommentWithReservedCharacters = number; + +/** + * This is a simple number + */ +export type SimpleInteger = number; + +/** + * This is a simple boolean + */ +export type SimpleBoolean = boolean; + +/** + * This is a simple string + */ +export type SimpleString = string; + +/** + * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) + */ +export type NonAsciiStringæøåÆøÅöôêÊ字符串 = string; + +/** + * This is a simple file + */ +export type SimpleFile = Blob | File; + +/** + * This is a simple reference + */ +export type SimpleReference = ModelWithString; + +/** + * This is a simple string + */ +export type SimpleStringWithPattern = string | null; + +/** + * This is a simple enum with strings + */ +export type EnumWithStrings = 'Success' | 'Warning' | 'Error' | '\'Single Quote\'' | '"Double Quotes"' | 'Non-ascii: øæåôöØÆÅÔÖ字符串'; + +export type EnumWithReplacedCharacters = '\'Single Quote\'' | '"Double Quotes"' | 'øæåôöØÆÅÔÖ字符串' | 3.1 | ''; + +/** + * This is a simple enum with numbers + */ +export type EnumWithNumbers = 1 | 2 | 3 | 1.1 | 1.2 | 1.3 | 100 | 200 | 300 | -100 | -200 | -300 | -1.1 | -1.2 | -1.3; + +/** + * Success=1,Warning=2,Error=3 + */ +export type EnumFromDescription = number; + +/** + * This is a simple enum with numbers + */ +export type EnumWithExtensions = 200 | 400 | 500; + +export type EnumWithXEnumNames = 0 | 1 | 2; + +/** + * This is a simple array with numbers + */ +export type ArrayWithNumbers = Array; + +/** + * This is a simple array with booleans + */ +export type ArrayWithBooleans = Array; + +/** + * This is a simple array with strings + */ +export type ArrayWithStrings = Array; + +/** + * This is a simple array with references + */ +export type ArrayWithReferences = Array; + +/** + * This is a simple array containing an array + */ +export type ArrayWithArray = Array>; + +/** + * This is a simple array with properties + */ +export type ArrayWithProperties = Array<{ + '16x16'?: CamelCaseCommentWithBreaks; + bar?: string; +}>; + +/** + * This is a simple array with any of properties + */ +export type ArrayWithAnyOfProperties = Array<{ + foo?: string; +} | { + bar?: string; +}>; + +export type AnyOfAnyAndNull = { + data?: unknown | null; +}; + +/** + * This is a simple array with any of properties + */ +export type AnyOfArrays = { + results?: Array<{ + foo?: string; + } | { + bar?: string; + }>; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithString = { + [key: string]: string; +}; + +export type DictionaryWithPropertiesAndAdditionalProperties = { + foo?: number; + bar?: boolean; + [key: string]: string | number | boolean | undefined; +}; + +/** + * This is a string reference + */ +export type DictionaryWithReference = { + [key: string]: ModelWithString; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithArray = { + [key: string]: Array; +}; + +/** + * This is a string dictionary + */ +export type DictionaryWithDictionary = { + [key: string]: { + [key: string]: string; + }; +}; + +/** + * This is a complex dictionary + */ +export type DictionaryWithProperties = { + [key: string]: { + foo?: string; + bar?: string; + }; +}; + +/** + * This is a model with one number property + */ +export type ModelWithInteger = { + /** + * This is a simple number property + */ + prop?: number; +}; + +/** + * This is a model with one boolean property + */ +export type ModelWithBoolean = { + /** + * This is a simple boolean property + */ + prop?: boolean; +}; + +/** + * This is a model with one string property + */ +export type ModelWithString = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * This is a model with one string property + */ +export type ModelWithStringError = { + /** + * This is a simple string property + */ + prop?: string; +}; + +/** + * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) + */ +export type ModelFromZendesk = string; + +/** + * This is a model with one string property + */ +export type ModelWithNullableString = { + /** + * This is a simple string property + */ + nullableProp1?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp1: string | null; + /** + * This is a simple string property + */ + nullableProp2?: string | null; + /** + * This is a simple string property + */ + nullableRequiredProp2: string | null; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnum = { + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; + /** + * These are the HTTP error code enums + */ + statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; + /** + * Simple boolean enum + */ + bool?: true; +}; + +/** + * This is a model with one enum with escaped name + */ +export type ModelWithEnumWithHyphen = { + /** + * Foo-Bar-Baz-Qux + */ + 'foo-bar-baz-qux'?: '3.0'; +}; + +/** + * This is a model with one enum + */ +export type ModelWithEnumFromDescription = { + /** + * Success=1,Warning=2,Error=3 + */ + test?: number; +}; + +/** + * This is a model with nested enums + */ +export type ModelWithNestedEnums = { + dictionaryWithEnum?: { + [key: string]: 'Success' | 'Warning' | 'Error'; + }; + dictionaryWithEnumFromDescription?: { + [key: string]: number; + }; + arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; + arrayWithDescription?: Array; + /** + * This is a simple enum with strings + */ + 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReference = { + prop?: ModelWithProperties; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnly = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArray = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one property containing a dictionary + */ +export type ModelWithDictionary = { + prop?: { + [key: string]: string; + }; +}; + +/** + * This is a deprecated model with a deprecated property + * + * @deprecated + */ +export type DeprecatedModel = { + /** + * This is a deprecated property + * + * @deprecated + */ + prop?: string; +}; + +/** + * This is a model with one property containing a circular reference + */ +export type ModelWithCircularReference = { + prop?: ModelWithCircularReference; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * Circle + */ +export type ModelCircle = { + kind: string; + radius?: number; +}; + +/** + * Square + */ +export type ModelSquare = { + kind: string; + sideLength?: number; +}; + +/** + * This is a model with one property with a 'one of' relationship where the options are not $ref + */ +export type CompositionWithOneOfDiscriminator = ({ + kind: 'circle'; +} & ModelCircle) | ({ + kind: 'square'; +} & ModelSquare); + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOf = { + propA?: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; +}; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithAnyOfAnonymous = { + propA?: { + propA?: string; + } | string | number; +}; + +/** + * This is a model with nested 'any of' property with a type null + */ +export type CompositionWithNestedAnyAndTypeNull = { + propA?: Array | Array; +}; + +export type _3eNum1Период = 'Bird' | 'Dog'; + +export type ConstValue = 'ConstValue'; + +/** + * This is a model with one property with a 'any of' relationship where the options are not $ref + */ +export type CompositionWithNestedAnyOfAndNull = { + /** + * Scopes + */ + propA?: Array<_3eNum1Период | ConstValue> | null; +}; + +/** + * This is a model with one property with a 'one of' relationship + */ +export type CompositionWithOneOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a model that contains a simple dictionary within composition + */ +export type CompositionWithOneOfAndSimpleDictionary = { + propA?: boolean | { + [key: string]: number; + }; +}; + +/** + * This is a model that contains a dictionary of simple arrays within composition + */ +export type CompositionWithOneOfAndSimpleArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model that contains a dictionary of complex arrays (composited) within composition + */ +export type CompositionWithOneOfAndComplexArrayDictionary = { + propA?: boolean | { + [key: string]: Array; + }; +}; + +/** + * This is a model with one property with a 'all of' relationship + */ +export type CompositionWithAllOfAndNullable = { + propA?: ({ + boolean?: boolean; + } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null; +}; + +/** + * This is a model with one property with a 'any of' relationship + */ +export type CompositionWithAnyOfAndNullable = { + propA?: { + boolean?: boolean; + } | ModelWithEnum | ModelWithArray | ModelWithDictionary | null; +}; + +/** + * This is a base model with two simple optional properties + */ +export type CompositionBaseModel = { + firstName?: string; + lastname?: string; +}; + +/** + * This is a model that extends the base model + */ +export type CompositionExtendedModel = CompositionBaseModel & { + age: number; + firstName: string; + lastname: string; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithProperties = { + required: string; + readonly requiredAndReadOnly: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithNestedProperties = { + readonly first: { + readonly second: { + readonly third: string | null; + } | null; + } | null; +}; + +/** + * This is a model with duplicated properties + */ +export type ModelWithDuplicateProperties = { + prop?: ModelWithString; +}; + +/** + * This is a model with ordered properties + */ +export type ModelWithOrderedProperties = { + zebra?: string; + apple?: string; + hawaii?: string; +}; + +/** + * This is a model with duplicated imports + */ +export type ModelWithDuplicateImports = { + propA?: ModelWithString; + propB?: ModelWithString; + propC?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtends = ModelWithString & { + propExtendsA?: string; + propExtendsB?: ModelWithString; +}; + +/** + * This is a model that extends another model + */ +export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { + propExtendsC?: string; + propExtendsD?: ModelWithString; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPattern = { + key: string; + name: string; + readonly enabled?: boolean; + readonly modified?: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type File = { + /** + * Id + */ + readonly id?: string; + /** + * Updated at + */ + readonly updated_at?: string; + /** + * Created at + */ + readonly created_at?: string; + /** + * Mime + */ + mime: string; + /** + * File + */ + readonly file?: string; +}; + +export type Default = { + name?: string; +}; + +export type Pageable = { + page?: number; + size?: number; + sort?: Array; +}; + +/** + * This is a free-form object without additionalProperties. + */ +export type FreeFormObjectWithoutAdditionalProperties = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: true. + */ +export type FreeFormObjectWithAdditionalPropertiesEqTrue = { + [key: string]: unknown; +}; + +/** + * This is a free-form object with additionalProperties: {}. + */ +export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { + [key: string]: unknown; +}; + +export type ModelWithConst = { + String?: 'String'; + number?: 0; + null?: null; + withType?: 'Some string'; +}; + +/** + * This is a model with one property and additionalProperties: true + */ +export type ModelWithAdditionalPropertiesEqTrue = { + /** + * This is a simple string property + */ + prop?: string; + [key: string]: unknown; +}; + +export type NestedAnyOfArraysNullable = { + nullableArray?: Array | null; +}; + +export type CompositionWithOneOfAndProperties = ({ + foo: SimpleParameter; +} | { + bar: NonAsciiStringæøåÆøÅöôêÊ字符串; +}) & { + baz: number | null; + qux: number; +}; + +/** + * An object that can be null + */ +export type NullableObject = { + foo?: string; +} | null; + +/** + * Some % character + */ +export type CharactersInDescription = string; + +export type ModelWithNullableObject = { + data?: NullableObject; +}; + +/** + * An object with additional properties that can be null (anyOf ref + null) + */ +export type ModelWithAdditionalPropertiesRef = { + [key: string]: NullableObject | null; +}; + +export type ModelWithOneOfEnum = { + foo: 'Bar'; +} | { + foo: 'Baz'; +} | { + foo: 'Qux'; +} | { + content: string; + foo: 'Quux'; +} | { + content: [ + string, + string + ]; + foo: 'Corge'; +}; + +export type ModelWithNestedArrayEnumsDataFoo = 'foo' | 'bar'; + +export type ModelWithNestedArrayEnumsDataBar = 'baz' | 'qux'; + +export type ModelWithNestedArrayEnumsData = { + foo?: Array; + bar?: Array; +}; + +export type ModelWithNestedArrayEnums = { + array_strings?: Array; + data?: ModelWithNestedArrayEnumsData; +}; + +export type ModelWithNestedCompositionEnums = { + foo?: ModelWithNestedArrayEnumsDataFoo; +}; + +export type ModelWithReadOnlyAndWriteOnly = { + foo: string; + readonly bar: string; +}; + +export type ModelWithConstantSizeArray = [ + number, + number +]; + +export type ModelWithAnyOfConstantSizeArray = [ + number | string, + number | string, + number | string +]; + +export type ModelWithPrefixItemsConstantSizeArray = [ + ModelWithInteger, + number | string, + string +]; + +export type ModelWithAnyOfConstantSizeArrayNullable = [ + number | null | string, + number | null | string, + number | null | string +]; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ + number | Import, + number | Import +]; + +export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ + number & string, + number & string +]; + +export type ModelWithNumericEnumUnion = { + /** + * Период + */ + value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; +}; + +/** + * Some description with `back ticks` + */ +export type ModelWithBackticksInDescription = { + /** + * The template `that` should be used for parsing and importing the contents of the CSV file. + * + *

There is one placeholder currently supported:

  • ${x} - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)

Example of a correct JSON template:

+ *
+     * [
+     * {
+     * "resourceType": "Asset",
+     * "identifier": {
+     * "name": "${1}",
+     * "domain": {
+     * "name": "${2}",
+     * "community": {
+     * "name": "Some Community"
+     * }
+     * }
+     * },
+     * "attributes" : {
+     * "00000000-0000-0000-0000-000000003115" : [ {
+     * "value" : "${3}"
+     * } ],
+     * "00000000-0000-0000-0000-000000000222" : [ {
+     * "value" : "${4}"
+     * } ]
+     * }
+     * }
+     * ]
+     * 
+ */ + template?: string; +}; + +export type ModelWithOneOfAndProperties = (SimpleParameter | NonAsciiStringæøåÆøÅöôêÊ字符串) & { + baz: number | null; + qux: number; +}; + +/** + * Model used to test deduplication strategy (unused) + */ +export type ParameterSimpleParameterUnused = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse = string; + +/** + * Model used to test deduplication strategy + */ +export type PostServiceWithEmptyTagResponse2 = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData = string; + +/** + * Model used to test deduplication strategy + */ +export type DeleteFooData2 = string; + +/** + * Model with restricted keyword name + */ +export type Import = string; + +export type SchemaWithFormRestrictedKeys = { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + object?: { + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }; + array?: Array<{ + description?: string; + 'x-enum-descriptions'?: string; + 'x-enum-varnames'?: string; + 'x-enumNames'?: string; + title?: string; + }>; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1DeleteOptions = { + /** + * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. + */ + preconditions?: IoK8sApimachineryPkgApisMetaV1Preconditions; +}; + +/** + * This schema was giving PascalCase transformations a hard time + */ +export type IoK8sApimachineryPkgApisMetaV1Preconditions = { + /** + * Specifies the target ResourceVersion + */ + resourceVersion?: string; + /** + * Specifies the target UID. + */ + uid?: string; +}; + +export type AdditionalPropertiesUnknownIssue = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue2 = { + [key: string]: string | number; +}; + +export type AdditionalPropertiesUnknownIssue3 = string & { + entries: { + [key: string]: AdditionalPropertiesUnknownIssue; + }; +}; + +export type AdditionalPropertiesIntegerIssue = { + value: number; + [key: string]: number; +}; + +export type OneOfAllOfIssue = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBoolean = { + item?: boolean; + error?: string | null; + readonly hasError?: boolean; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemString = { + item?: string | null; + error?: string | null; + readonly hasError?: boolean; +}; + +export type ExternalSharedModel = { + id: string; + name?: string; +}; + +/** + * This is a model with one property containing a reference + */ +export type ModelWithReferenceWritable = { + prop?: ModelWithPropertiesWritable; +}; + +/** + * This is a model with one property containing an array + */ +export type ModelWithArrayReadOnlyAndWriteOnlyWritable = { + prop?: Array; + propWithFile?: Array; + propWithNumber?: Array; +}; + +/** + * This is a model with one nested property + */ +export type ModelWithPropertiesWritable = { + required: string; + requiredAndNullable: string | null; + string?: string; + number?: number; + boolean?: boolean; + reference?: ModelWithString; + 'property with space'?: string; + default?: string; + try?: string; +}; + +/** + * This is a model that contains a some patterns + */ +export type ModelWithPatternWritable = { + key: string; + name: string; + id?: string; + text?: string; + patternWithSingleQuotes?: string; + patternWithNewline?: string; + patternWithBacktick?: string; + patternWithUnicode?: string; +}; + +export type FileWritable = { + /** + * Mime + */ + mime: string; +}; + +export type ModelWithReadOnlyAndWriteOnlyWritable = { + foo: string; + baz: string; +}; + +export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = [ + number | Import, + number | Import +]; + +export type AdditionalPropertiesUnknownIssueWritable = { + [key: string]: string | number; +}; + +export type OneOfAllOfIssueWritable = ((ConstValue | GenericSchemaDuplicateIssue1SystemBoolean) & _3eNum1Период) | GenericSchemaDuplicateIssue1SystemString; + +export type GenericSchemaDuplicateIssue1SystemBooleanWritable = { + item?: boolean; + error?: string | null; + data?: { + [key: string]: never; + }; +}; + +export type GenericSchemaDuplicateIssue1SystemStringWritable = { + item?: string | null; + error?: string | null; +}; + +/** + * This is a reusable parameter + */ +export type SimpleParameter = string; + +/** + * Parameter with illegal characters + */ +export type XFooBar = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleRequestBody = ModelWithString; + +/** + * A reusable request body + */ +export type SimpleFormData = ModelWithString; + +export type ExportData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type PatchApiVbyApiVersionNoTagResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ImportData = { + body: ModelWithReadOnlyAndWriteOnlyWritable | ModelWithArrayReadOnlyAndWriteOnlyWritable; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type ImportResponses = { + /** + * Success + */ + 200: ModelFromZendesk; + /** + * Default success response + */ + default: ModelWithReadOnlyAndWriteOnly; +}; + +export type ImportResponse = ImportResponses[keyof ImportResponses]; + +export type FooWowData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no+tag'; +}; + +export type FooWowResponses = { + /** + * OK + */ + default: unknown; +}; + +export type ApiVVersionODataControllerCountData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple/$count'; +}; + +export type ApiVVersionODataControllerCountResponses = { + /** + * Success + */ + 200: ModelFromZendesk; +}; + +export type ApiVVersionODataControllerCountResponse = ApiVVersionODataControllerCountResponses[keyof ApiVVersionODataControllerCountResponses]; + +export type GetApiVbyApiVersionSimpleOperationData = { + body?: never; + path: { + /** + * foo in method + */ + foo_param: string; + }; + query?: never; + url: '/api/v{api-version}/simple:operation'; +}; + +export type GetApiVbyApiVersionSimpleOperationErrors = { + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type GetApiVbyApiVersionSimpleOperationError = GetApiVbyApiVersionSimpleOperationErrors[keyof GetApiVbyApiVersionSimpleOperationErrors]; + +export type GetApiVbyApiVersionSimpleOperationResponses = { + /** + * Response is a simple number + */ + 200: number; +}; + +export type GetApiVbyApiVersionSimpleOperationResponse = GetApiVbyApiVersionSimpleOperationResponses[keyof GetApiVbyApiVersionSimpleOperationResponses]; + +export type DeleteCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type GetCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type HeadCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type OptionsCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PatchCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PostCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type PutCallWithoutParametersAndResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/simple'; +}; + +export type DeleteFooData3 = { + body?: never; + headers: { + /** + * Parameter with illegal characters + */ + 'x-Foo-Bar': ModelWithString; + }; + path: { + /** + * foo in method + */ + foo_param: string; + /** + * bar in method + */ + BarParam: string; + }; + query?: never; + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}'; +}; + +export type CallWithDescriptionsData = { + body?: never; + path?: never; + query?: { + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + }; + url: '/api/v{api-version}/descriptions'; +}; + +export type DeprecatedCallData = { + body?: never; + headers: { + /** + * This parameter is deprecated + * + * @deprecated + */ + parameter: DeprecatedModel | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/parameters/deprecated'; +}; + +export type CallWithParametersData = { + /** + * This is the parameter that goes into the body + */ + body: { + [key: string]: unknown; + } | null; + headers: { + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + foo_ref_enum?: ModelWithNestedArrayEnumsDataFoo; + foo_all_of_enum: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the query params + */ + cursor: string | null; + }; + url: '/api/v{api-version}/parameters/{parameterPath}'; +}; + +export type CallWithWeirdParameterNamesData = { + /** + * This is the parameter that goes into the body + */ + body: ModelWithString | null; + headers: { + /** + * This is the parameter that goes into the request header + */ + 'parameter.header': string | null; + }; + path: { + /** + * This is the parameter that goes into the path + */ + 'parameter.path.1'?: string; + /** + * This is the parameter that goes into the path + */ + 'parameter-path-2'?: string; + /** + * This is the parameter that goes into the path + */ + 'PARAMETER-PATH-3'?: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query: { + /** + * This is the parameter with a reserved keyword + */ + default?: string; + /** + * This is the parameter that goes into the request query params + */ + 'parameter-query': string | null; + }; + url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}'; +}; + +export type GetCallWithOptionalParamData = { + /** + * This is a required parameter + */ + body: ModelWithOneOfEnum; + path?: never; + query?: { + /** + * This is an optional parameter + */ + page?: number; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + body?: { + offset?: number | null; + }; + path?: never; + query: { + /** + * This is a required parameter + */ + parameter: Pageable; + }; + url: '/api/v{api-version}/parameters'; +}; + +export type PostCallWithOptionalParamResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type PostCallWithOptionalParamResponse = PostCallWithOptionalParamResponses[keyof PostCallWithOptionalParamResponses]; + +export type PostApiVbyApiVersionRequestBodyData = { + /** + * A reusable request body + */ + body?: SimpleRequestBody; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/requestBody'; +}; + +export type PostApiVbyApiVersionFormDataData = { + /** + * A reusable request body + */ + body?: SimpleFormData; + path?: never; + query?: { + /** + * This is a reusable parameter + */ + parameter?: string; + }; + url: '/api/v{api-version}/formData'; +}; + +export type CallWithDefaultParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string with default value + */ + parameterString?: string | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallWithDefaultOptionalParametersData = { + body?: never; + path?: never; + query?: { + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type CallToTestOrderOfParamsData = { + body?: never; + path?: never; + query: { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + }; + url: '/api/v{api-version}/defaults'; +}; + +export type DuplicateNameData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName2Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName3Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type DuplicateName4Data = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/duplicate'; +}; + +export type CallWithNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/no-content'; +}; + +export type CallWithNoContentResponseResponses = { + /** + * Success + */ + 204: void; +}; + +export type CallWithNoContentResponseResponse = CallWithNoContentResponseResponses[keyof CallWithNoContentResponseResponses]; + +export type CallWithResponseAndNoContentResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/response-and-no-content'; +}; + +export type CallWithResponseAndNoContentResponseResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Success + */ + 204: void; +}; + +export type CallWithResponseAndNoContentResponseResponse = CallWithResponseAndNoContentResponseResponses[keyof CallWithResponseAndNoContentResponseResponses]; + +export type DummyAData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/a'; +}; + +export type DummyAResponses = { + 200: _400; +}; + +export type DummyAResponse = DummyAResponses[keyof DummyAResponses]; + +export type DummyBData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multiple-tags/b'; +}; + +export type DummyBResponses = { + /** + * Success + */ + 204: void; +}; + +export type DummyBResponse = DummyBResponses[keyof DummyBResponses]; + +export type CallWithResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponseResponses = { + default: Import; +}; + +export type CallWithResponseResponse = CallWithResponseResponses[keyof CallWithResponseResponses]; + +export type CallWithDuplicateResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithDuplicateResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for 4XX errors + */ + '4XX': DictionaryWithArray; + /** + * Default error response + */ + default: ModelWithBoolean; +}; + +export type CallWithDuplicateResponsesError = CallWithDuplicateResponsesErrors[keyof CallWithDuplicateResponsesErrors]; + +export type CallWithDuplicateResponsesResponses = { + /** + * Message for 200 response + */ + 200: ModelWithBoolean & ModelWithInteger; + /** + * Message for 201 response + */ + 201: ModelWithString; + /** + * Message for 202 response + */ + 202: ModelWithString; +}; + +export type CallWithDuplicateResponsesResponse = CallWithDuplicateResponsesResponses[keyof CallWithDuplicateResponsesResponses]; + +export type CallWithResponsesData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/response'; +}; + +export type CallWithResponsesErrors = { + /** + * Message for 500 error + */ + 500: ModelWithStringError; + /** + * Message for 501 error + */ + 501: ModelWithStringError; + /** + * Message for 502 error + */ + 502: ModelWithStringError; + /** + * Message for default response + */ + default: ModelWithStringError; +}; + +export type CallWithResponsesError = CallWithResponsesErrors[keyof CallWithResponsesErrors]; + +export type CallWithResponsesResponses = { + /** + * Message for 200 response + */ + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; + /** + * Message for 201 response + */ + 201: ModelThatExtends; + /** + * Message for 202 response + */ + 202: ModelThatExtendsExtends; +}; + +export type CallWithResponsesResponse = CallWithResponsesResponses[keyof CallWithResponsesResponses]; + +export type CollectionFormatData = { + body?: never; + path?: never; + query: { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCSV: Array | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySSV: Array | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTSV: Array | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array | null; + }; + url: '/api/v{api-version}/collectionFormat'; +}; + +export type TypesData = { + body?: never; + path?: { + /** + * This is a number parameter + */ + id?: number; + }; + query: { + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is a string parameter + */ + parameterString: string | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is an array parameter + */ + parameterArray: Array | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + }; + url: '/api/v{api-version}/types'; +}; + +export type TypesResponses = { + /** + * Response is a simple number + */ + 200: number; + /** + * Response is a simple string + */ + 201: string; + /** + * Response is a simple boolean + */ + 202: boolean; + /** + * Response is a simple object + */ + 203: { + [key: string]: unknown; + }; +}; + +export type TypesResponse = TypesResponses[keyof TypesResponses]; + +export type UploadFileData = { + body: Blob | File; + path: { + /** + * api-version should be required in standalone clients + */ + 'api-version': string | null; + }; + query?: never; + url: '/api/v{api-version}/upload'; +}; + +export type UploadFileResponses = { + 200: boolean; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; + +export type FileResponseData = { + body?: never; + path: { + id: string; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/file/{id}'; +}; + +export type FileResponseResponses = { + /** + * Success + */ + 200: Blob | File; +}; + +export type FileResponseResponse = FileResponseResponses[keyof FileResponseResponses]; + +export type ComplexTypesData = { + body?: never; + path?: never; + query: { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; + }; + url: '/api/v{api-version}/complex'; +}; + +export type ComplexTypesErrors = { + /** + * 400 `server` error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type ComplexTypesResponses = { + /** + * Successful response + */ + 200: Array; +}; + +export type ComplexTypesResponse = ComplexTypesResponses[keyof ComplexTypesResponses]; + +export type MultipartResponseData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type MultipartResponseResponses = { + /** + * OK + */ + 200: { + file?: Blob | File; + metadata?: { + foo?: string; + bar?: string; + }; + }; +}; + +export type MultipartResponseResponse = MultipartResponseResponses[keyof MultipartResponseResponses]; + +export type MultipartRequestData = { + body?: { + content?: Blob | File; + data?: ModelWithString | null; + }; + path?: never; + query?: never; + url: '/api/v{api-version}/multipart'; +}; + +export type ComplexParamsData = { + body?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; + path: { + id: number; + /** + * api-version should be required in standalone clients + */ + 'api-version': string; + }; + query?: never; + url: '/api/v{api-version}/complex/{id}'; +}; + +export type ComplexParamsResponses = { + /** + * Success + */ + 200: ModelWithString; +}; + +export type ComplexParamsResponse = ComplexParamsResponses[keyof ComplexParamsResponses]; + +export type CallWithResultFromHeaderData = { + body?: never; + path?: never; + query?: never; + url: '/api/v{api-version}/header'; +}; + +export type CallWithResultFromHeaderErrors = { + /** + * 400 server error + */ + 400: unknown; + /** + * 500 server error + */ + 500: unknown; +}; + +export type CallWithResultFromHeaderResponses = { + /** + * Successful response + */ + 200: unknown; +}; + +export type TestErrorCodeData = { + body?: never; + path?: never; + query: { + /** + * Status code to return + */ + status: number; + }; + url: '/api/v{api-version}/error'; +}; + +export type TestErrorCodeErrors = { + /** + * Custom message: Internal Server Error + */ + 500: unknown; + /** + * Custom message: Not Implemented + */ + 501: unknown; + /** + * Custom message: Bad Gateway + */ + 502: unknown; + /** + * Custom message: Service Unavailable + */ + 503: unknown; +}; + +export type TestErrorCodeResponses = { + /** + * Custom message: Successful response + */ + 200: unknown; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Data = { + body?: never; + path?: never; + query: { + /** + * Dummy input param + */ + nonAsciiParamæøåÆØÅöôêÊ: number; + }; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Responses = { + /** + * Successful response + */ + 200: Array; +}; + +export type NonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiæøåÆøÅöôêÊ字符串Responses[keyof NonAsciiæøåÆøÅöôêÊ字符串Responses]; + +export type PutWithFormUrlEncodedData = { + body: ArrayWithStrings; + path?: never; + query?: never; + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串'; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts index 6aa6cf02a4..ddf3c4d13a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/core/serverSentEvents.gen.ts @@ -79,7 +79,7 @@ export type ServerSentEventsResult; }; -export const createSseClient = ({ +export function createSseClient({ onRequest, onSseError, onSseEvent, @@ -91,7 +91,7 @@ export const createSseClient = ({ sseSleepFn, url, ...options -}: ServerSentEventsOptions): ServerSentEventsResult => { +}: ServerSentEventsOptions): ServerSentEventsResult { let lastEventId: string | undefined; const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); @@ -155,8 +155,7 @@ export const createSseClient = ({ const { done, value } = await reader.read(); if (done) break; buffer += value; - // Normalize line endings: CRLF -> LF, then CR -> LF - buffer = buffer.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); + buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings const chunks = buffer.split('\n\n'); buffer = chunks.pop() ?? ''; @@ -240,4 +239,4 @@ export const createSseClient = ({ const stream = createStream(); return { stream }; -}; +} diff --git a/packages/openapi-ts-tests/main/test/plugins.test.ts b/packages/openapi-ts-tests/main/test/plugins.test.ts index 3b12d75297..7b4eccf790 100644 --- a/packages/openapi-ts-tests/main/test/plugins.test.ts +++ b/packages/openapi-ts-tests/main/test/plugins.test.ts @@ -346,6 +346,20 @@ for (const version of versions) { description: 'generate Fetch API client with TanStack React Query plugin with responseStyle fields', }, + { + config: createConfig({ + output: 'responseStyle-data', + plugins: [ + { + name: '@tanstack/react-query', + responseStyle: 'data', + }, + '@hey-api/client-fetch', + ], + }), + description: + 'generate Fetch API client with TanStack React Query plugin with responseStyle data', + }, { config: createConfig({ input: 'sdk-instance.yaml', From 3f10422ad0876a89a0454f8bed33a38bda2d1ef6 Mon Sep 17 00:00:00 2001 From: Jorrin Date: Thu, 9 Apr 2026 23:06:38 +0200 Subject: [PATCH 8/8] fix snapshot --- .../@tanstack/react-query/responseStyle-data/types.gen.ts | 2 +- .../plugins/@tanstack/react-query/responseStyle/types.gen.ts | 2 +- .../@tanstack/react-query/responseStyle-data/types.gen.ts | 2 +- .../plugins/@tanstack/react-query/responseStyle/types.gen.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts index 3287ee8737..1b553ea1ed 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts @@ -1960,7 +1960,7 @@ export type ComplexParamsData = { readonly key: string | null; name: string | null; enabled?: boolean; - type: 'Monkey' | 'Horse' | 'Bird'; + readonly type: 'Monkey' | 'Horse' | 'Bird'; listOfModels?: Array | null; listOfStrings?: Array | null; parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts index 3287ee8737..1b553ea1ed 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts @@ -1960,7 +1960,7 @@ export type ComplexParamsData = { readonly key: string | null; name: string | null; enabled?: boolean; - type: 'Monkey' | 'Horse' | 'Bird'; + readonly type: 'Monkey' | 'Horse' | 'Bird'; listOfModels?: Array | null; listOfStrings?: Array | null; parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts index d819316644..916fd3b949 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle-data/types.gen.ts @@ -1979,7 +1979,7 @@ export type ComplexParamsData = { readonly key: string | null; name: string | null; enabled?: boolean; - type: 'Monkey' | 'Horse' | 'Bird'; + readonly type: 'Monkey' | 'Horse' | 'Bird'; listOfModels?: Array | null; listOfStrings?: Array | null; parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts index d819316644..916fd3b949 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/responseStyle/types.gen.ts @@ -1979,7 +1979,7 @@ export type ComplexParamsData = { readonly key: string | null; name: string | null; enabled?: boolean; - type: 'Monkey' | 'Horse' | 'Bird'; + readonly type: 'Monkey' | 'Horse' | 'Bird'; listOfModels?: Array | null; listOfStrings?: Array | null; parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary;