From 437c1ad237619ab132f71ce91957eef4d2edc76c Mon Sep 17 00:00:00 2001 From: Pewww Date: Mon, 10 Nov 2025 16:52:47 +0900 Subject: [PATCH 1/9] feat: add openapi-ts swr plugin --- examples/openapi-ts-swr/.gitignore | 24 + examples/openapi-ts-swr/index.html | 13 + examples/openapi-ts-swr/openapi-ts.config.ts | 21 + examples/openapi-ts-swr/package.json | 40 + examples/openapi-ts-swr/postcss.config.js | 6 + examples/openapi-ts-swr/src/App.css | 3 + examples/openapi-ts-swr/src/App.tsx | 305 ++++++++ .../openapi-ts-swr/src/client/client.gen.ts | 27 + .../src/client/client/client.gen.ts | 268 +++++++ .../openapi-ts-swr/src/client/client/index.ts | 25 + .../src/client/client/types.gen.ts | 241 ++++++ .../src/client/client/utils.gen.ts | 337 +++++++++ .../src/client/core/auth.gen.ts | 42 ++ .../src/client/core/bodySerializer.gen.ts | 100 +++ .../src/client/core/params.gen.ts | 176 +++++ .../src/client/core/pathSerializer.gen.ts | 181 +++++ .../src/client/core/queryKeySerializer.gen.ts | 136 ++++ .../src/client/core/serverSentEvents.gen.ts | 264 +++++++ .../src/client/core/types.gen.ts | 118 +++ .../src/client/core/utils.gen.ts | 143 ++++ examples/openapi-ts-swr/src/client/index.ts | 4 + .../openapi-ts-swr/src/client/schemas.gen.ts | 188 +++++ examples/openapi-ts-swr/src/client/sdk.gen.ts | 486 ++++++++++++ examples/openapi-ts-swr/src/client/swr.gen.ts | 557 ++++++++++++++ .../openapi-ts-swr/src/client/types.gen.ts | 699 ++++++++++++++++++ examples/openapi-ts-swr/src/main.tsx | 36 + examples/openapi-ts-swr/src/vite-env.d.ts | 1 + examples/openapi-ts-swr/tailwind.config.js | 8 + examples/openapi-ts-swr/tsconfig.json | 25 + examples/openapi-ts-swr/tsconfig.node.json | 11 + examples/openapi-ts-swr/vite.config.ts | 7 + .../main/test/plugins.test.ts | 38 +- .../test/plugins/swr/basic-generation.test.ts | 228 ++++++ .../main/test/plugins/swr/edge-cases.test.ts | 290 ++++++++ .../main/test/plugins/swr/infinite.test.ts | 98 +++ packages/openapi-ts/src/plugins/swr/config.ts | 67 +- packages/openapi-ts/src/plugins/swr/plugin.ts | 88 ++- .../src/plugins/swr/swrInfiniteOptions.ts | 352 +++++++++ packages/openapi-ts/src/plugins/swr/swrKey.ts | 214 ++++++ .../src/plugins/swr/swrMutationOptions.ts | 172 +++++ .../openapi-ts/src/plugins/swr/swrOptions.ts | 162 ++++ .../openapi-ts/src/plugins/swr/types.d.ts | 416 ++--------- .../openapi-ts/src/plugins/swr/useType.ts | 63 ++ .../openapi-ts/src/plugins/swr/v2/plugin.ts | 82 -- .../openapi-ts/src/plugins/swr/v2/useSwr.ts | 70 -- pnpm-lock.yaml | 81 ++ 46 files changed, 6345 insertions(+), 568 deletions(-) create mode 100644 examples/openapi-ts-swr/.gitignore create mode 100644 examples/openapi-ts-swr/index.html create mode 100644 examples/openapi-ts-swr/openapi-ts.config.ts create mode 100644 examples/openapi-ts-swr/package.json create mode 100644 examples/openapi-ts-swr/postcss.config.js create mode 100644 examples/openapi-ts-swr/src/App.css create mode 100644 examples/openapi-ts-swr/src/App.tsx create mode 100644 examples/openapi-ts-swr/src/client/client.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/client/client.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/client/index.ts create mode 100644 examples/openapi-ts-swr/src/client/client/types.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/client/utils.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/core/auth.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/core/bodySerializer.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/core/params.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/core/pathSerializer.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/core/queryKeySerializer.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/core/serverSentEvents.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/core/types.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/core/utils.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/index.ts create mode 100644 examples/openapi-ts-swr/src/client/schemas.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/sdk.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/swr.gen.ts create mode 100644 examples/openapi-ts-swr/src/client/types.gen.ts create mode 100644 examples/openapi-ts-swr/src/main.tsx create mode 100644 examples/openapi-ts-swr/src/vite-env.d.ts create mode 100644 examples/openapi-ts-swr/tailwind.config.js create mode 100644 examples/openapi-ts-swr/tsconfig.json create mode 100644 examples/openapi-ts-swr/tsconfig.node.json create mode 100644 examples/openapi-ts-swr/vite.config.ts create mode 100644 packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts create mode 100644 packages/openapi-ts-tests/main/test/plugins/swr/edge-cases.test.ts create mode 100644 packages/openapi-ts-tests/main/test/plugins/swr/infinite.test.ts create mode 100644 packages/openapi-ts/src/plugins/swr/swrInfiniteOptions.ts create mode 100644 packages/openapi-ts/src/plugins/swr/swrKey.ts create mode 100644 packages/openapi-ts/src/plugins/swr/swrMutationOptions.ts create mode 100644 packages/openapi-ts/src/plugins/swr/swrOptions.ts create mode 100644 packages/openapi-ts/src/plugins/swr/useType.ts delete mode 100644 packages/openapi-ts/src/plugins/swr/v2/plugin.ts delete mode 100644 packages/openapi-ts/src/plugins/swr/v2/useSwr.ts diff --git a/examples/openapi-ts-swr/.gitignore b/examples/openapi-ts-swr/.gitignore new file mode 100644 index 0000000000..a547bf36d8 --- /dev/null +++ b/examples/openapi-ts-swr/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/examples/openapi-ts-swr/index.html b/examples/openapi-ts-swr/index.html new file mode 100644 index 0000000000..b1cc18d0b6 --- /dev/null +++ b/examples/openapi-ts-swr/index.html @@ -0,0 +1,13 @@ + + + + + + + Hey API + SWR Demo + + +
+ + + diff --git a/examples/openapi-ts-swr/openapi-ts.config.ts b/examples/openapi-ts-swr/openapi-ts.config.ts new file mode 100644 index 0000000000..4ecd69aad8 --- /dev/null +++ b/examples/openapi-ts-swr/openapi-ts.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from '@hey-api/openapi-ts'; + +export default defineConfig({ + input: + 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', + output: { + format: 'prettier', + lint: 'eslint', + path: './src/client', + }, + plugins: [ + '@hey-api/client-fetch', + '@hey-api/schemas', + '@hey-api/sdk', + { + enums: 'javascript', + name: '@hey-api/typescript', + }, + 'swr', + ], +}); diff --git a/examples/openapi-ts-swr/package.json b/examples/openapi-ts-swr/package.json new file mode 100644 index 0000000000..1f74261914 --- /dev/null +++ b/examples/openapi-ts-swr/package.json @@ -0,0 +1,40 @@ +{ + "name": "@example/openapi-ts-swr", + "private": true, + "version": "0.0.1", + "type": "module", + "scripts": { + "build": "tsc && vite build", + "dev": "vite", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "openapi-ts": "openapi-ts", + "preview": "vite preview", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@radix-ui/react-form": "0.1.1", + "@radix-ui/react-icons": "1.3.2", + "@radix-ui/themes": "3.1.6", + "react": "19.0.0", + "react-dom": "19.0.0", + "swr": "2.3.2" + }, + "devDependencies": { + "@config/vite-base": "workspace:*", + "@hey-api/openapi-ts": "workspace:*", + "@types/react": "19.0.1", + "@types/react-dom": "19.0.1", + "@typescript-eslint/eslint-plugin": "8.29.1", + "@typescript-eslint/parser": "8.29.1", + "@vitejs/plugin-react": "4.4.0-beta.1", + "autoprefixer": "10.4.19", + "eslint": "9.17.0", + "eslint-plugin-react-hooks": "5.2.0", + "eslint-plugin-react-refresh": "0.4.7", + "postcss": "8.4.41", + "prettier": "3.4.2", + "tailwindcss": "3.4.9", + "typescript": "5.8.3", + "vite": "7.1.2" + } +} diff --git a/examples/openapi-ts-swr/postcss.config.js b/examples/openapi-ts-swr/postcss.config.js new file mode 100644 index 0000000000..9eef821c48 --- /dev/null +++ b/examples/openapi-ts-swr/postcss.config.js @@ -0,0 +1,6 @@ +export default { + plugins: { + autoprefixer: {}, + tailwindcss: {}, + }, +}; diff --git a/examples/openapi-ts-swr/src/App.css b/examples/openapi-ts-swr/src/App.css new file mode 100644 index 0000000000..b5c61c9567 --- /dev/null +++ b/examples/openapi-ts-swr/src/App.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/examples/openapi-ts-swr/src/App.tsx b/examples/openapi-ts-swr/src/App.tsx new file mode 100644 index 0000000000..7e31788892 --- /dev/null +++ b/examples/openapi-ts-swr/src/App.tsx @@ -0,0 +1,305 @@ +import './App.css'; + +import * as Form from '@radix-ui/react-form'; +import { DownloadIcon, PlusIcon, ReloadIcon } from '@radix-ui/react-icons'; +import { + Avatar, + Box, + Button, + Card, + Container, + Flex, + Heading, + Section, + Text, + TextField, +} from '@radix-ui/themes'; +import { useEffect, useState } from 'react'; +import useSWR from 'swr'; +// import useSWRInfinite from 'swr/infinite'; +import useSWRMutation from 'swr/mutation'; + +import { createClient } from './client/client'; +import { PetSchema } from './client/schemas.gen'; +import { + addPetMutation, + getPetByIdOptions, + updatePetMutation, +} from './client/swr.gen'; +import type { Pet } from './client/types.gen'; + +const localClient = createClient({ + // set default base url for requests made by this client + baseUrl: 'https://petstore3.swagger.io/api/v3', + /** + * Set default headers only for requests made by this client. This is to + * demonstrate local clients and their configuration taking precedence over + * internal service client. + */ + headers: { + Authorization: 'Bearer ', + }, +}); + +localClient.interceptors.request.use((request, options) => { + // Middleware is great for adding authorization tokens to requests made to + // protected paths. Headers are set randomly here to allow surfacing the + // default headers, too. + if ( + options.url === '/pet/{petId}' && + options.method === 'GET' && + Math.random() < 0.5 + ) { + request.headers.set('Authorization', 'Bearer '); + } + return request; +}); + +function App() { + const [pet, setPet] = useState(); + const [petId, setPetId] = useState(); + const [isRequiredNameError, setIsRequiredNameError] = useState(false); + + // Mutations + const { fetcher: addPetFetcher, key: addPetKey } = addPetMutation(); + const addPet = useSWRMutation(addPetKey, addPetFetcher, { + onError: (error) => { + console.log(error); + setIsRequiredNameError(false); + }, + onSuccess: (data) => { + setPet(data); + setIsRequiredNameError(false); + }, + }); + + const { fetcher: updatePetFetcher, key: updatePetKey } = updatePetMutation(); + const updatePet = useSWRMutation(updatePetKey, updatePetFetcher, { + onError: (error) => { + console.log(error); + }, + onSuccess: (data) => { + setPet(data); + }, + }); + + // Query - only fetch if petId is set + const petOptions = petId + ? getPetByIdOptions({ + client: localClient, + path: { + petId: petId!, + }, + }) + : null; + + const { data, error } = useSWR( + petOptions?.key ?? null, + petOptions?.fetcher ?? null, + ); + + const onAddPet = async (formData: FormData) => { + // simple form field validation to demonstrate using schemas + if (PetSchema.required.includes('name') && !formData.get('name')) { + setIsRequiredNameError(true); + return; + } + + addPet.trigger({ + body: { + category: { + id: 0, + name: formData.get('category') as string, + }, + id: 0, + name: formData.get('name') as string, + photoUrls: ['string'], + status: 'available', + tags: [ + { + id: 0, + name: 'string', + }, + ], + }, + }); + }; + + const onGetPetById = async () => { + // random id 1-10 + setPetId(Math.floor(Math.random() * (10 - 1 + 1) + 1)); + }; + + const onUpdatePet = async () => { + updatePet.trigger({ + body: { + category: { + id: 0, + name: 'Cats', + }, + id: 2, + name: 'Updated Kitty', + photoUrls: ['string'], + status: 'available', + tags: [ + { + id: 0, + name: 'string', + }, + ], + }, + // setting headers per request + headers: { + Authorization: 'Bearer ', + }, + }); + }; + + useEffect(() => { + if (error) { + console.log(error); + return; + } + setPet(data!); + }, [data, error]); + + return ( + + +
+ + + Hey API logo + + @hey-api/openapi-ts 🤝 SWR + +
+ + + + + + + + Name: {pet?.name ?? 'N/A'} + + + Category: {pet?.category?.name ?? 'N/A'} + + + + + + + +
+ + { + event.preventDefault(); + onAddPet(new FormData(event.currentTarget)); + }} + > + +
+ + Name + + {isRequiredNameError && ( + + Please enter a name + + )} +
+ + + +
+ +
+ + Category + + + Please enter a category + +
+ + + +
+ + + + + + +
+
+
+ {/* + useSWRInfinite Example (for paginated endpoints): + + If your OpenAPI spec has pagination configured, you can use useSWRInfinite: + + import useSWRInfinite from 'swr/infinite'; + import { getPetsInfinite } from './client/swr.gen'; + + function InfinitePetList() { + const { getKey, fetcher } = getPetsInfinite(); + const { data, size, setSize, isLoading } = useSWRInfinite(getKey, fetcher); + + const pets = data ? data.flat() : []; + const isLoadingMore = isLoading || (size > 0 && data && typeof data[size - 1] === 'undefined'); + const isEmpty = data?.[0]?.length === 0; + const isReachingEnd = isEmpty || (data && data[data.length - 1]?.length < 20); + + return ( +
+ {pets.map((pet) => ( + + {pet.name} + + ))} + +
+ ); + } + */} + + + ); +} + +export default App; diff --git a/examples/openapi-ts-swr/src/client/client.gen.ts b/examples/openapi-ts-swr/src/client/client.gen.ts new file mode 100644 index 0000000000..069f4dabab --- /dev/null +++ b/examples/openapi-ts-swr/src/client/client.gen.ts @@ -0,0 +1,27 @@ +// 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: 'https://petstore3.swagger.io/api/v3', + }), +); diff --git a/examples/openapi-ts-swr/src/client/client/client.gen.ts b/examples/openapi-ts-swr/src/client/client/client.gen.ts new file mode 100644 index 0000000000..a439d2748f --- /dev/null +++ b/examples/openapi-ts-swr/src/client/client/client.gen.ts @@ -0,0 +1,268 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { + Client, + Config, + RequestOptions, + ResolvedRequestOptions, +} from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors< + Request, + Response, + unknown, + ResolvedRequestOptions + >(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body); + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response = await _fetch(request); + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if ( + response.status === 204 || + response.headers.get('Content-Length') === '0' + ) { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'json': + case 'text': + data = await response[parseAs](); + break; + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = + (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = + (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/examples/openapi-ts-swr/src/client/client/index.ts b/examples/openapi-ts-swr/src/client/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/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/examples/openapi-ts-swr/src/client/client/types.gen.ts b/examples/openapi-ts-swr/src/client/client/types.gen.ts new file mode 100644 index 0000000000..b4a499cc03 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/client/types.gen.ts @@ -0,0 +1,241 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { + Client as CoreClient, + Config as CoreConfig, +} from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: + | 'arrayBuffer' + | 'auto' + | 'blob' + | 'formData' + | 'json' + | 'stream' + | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record + ? TData[keyof TData] + : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? + | (TData extends Record + ? TData[keyof TData] + : TData) + | undefined + : ( + | { + data: TData extends Record + ? TData[keyof TData] + : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick< + Required>, + 'method' + >, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/examples/openapi-ts-swr/src/client/client/utils.gen.ts b/examples/openapi-ts-swr/src/client/client/utils.gen.ts new file mode 100644 index 0000000000..89416454b6 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/client/utils.gen.ts @@ -0,0 +1,337 @@ +// 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/examples/openapi-ts-swr/src/client/core/auth.gen.ts b/examples/openapi-ts-swr/src/client/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/examples/openapi-ts-swr/src/client/core/bodySerializer.gen.ts b/examples/openapi-ts-swr/src/client/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/examples/openapi-ts-swr/src/client/core/params.gen.ts b/examples/openapi-ts-swr/src/client/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/examples/openapi-ts-swr/src/client/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/examples/openapi-ts-swr/src/client/core/pathSerializer.gen.ts b/examples/openapi-ts-swr/src/client/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/examples/openapi-ts-swr/src/client/core/queryKeySerializer.gen.ts b/examples/openapi-ts-swr/src/client/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/examples/openapi-ts-swr/src/client/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/examples/openapi-ts-swr/src/client/core/serverSentEvents.gen.ts b/examples/openapi-ts-swr/src/client/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/examples/openapi-ts-swr/src/client/core/types.gen.ts b/examples/openapi-ts-swr/src/client/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/examples/openapi-ts-swr/src/client/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/examples/openapi-ts-swr/src/client/core/utils.gen.ts b/examples/openapi-ts-swr/src/client/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/examples/openapi-ts-swr/src/client/index.ts b/examples/openapi-ts-swr/src/client/index.ts new file mode 100644 index 0000000000..57ed02bf5f --- /dev/null +++ b/examples/openapi-ts-swr/src/client/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export * from './sdk.gen'; +export type * from './types.gen'; diff --git a/examples/openapi-ts-swr/src/client/schemas.gen.ts b/examples/openapi-ts-swr/src/client/schemas.gen.ts new file mode 100644 index 0000000000..646632e830 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/schemas.gen.ts @@ -0,0 +1,188 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export const OrderSchema = { + properties: { + complete: { + type: 'boolean', + }, + id: { + example: 10, + format: 'int64', + type: 'integer', + }, + petId: { + example: 198772, + format: 'int64', + type: 'integer', + }, + quantity: { + example: 7, + format: 'int32', + type: 'integer', + }, + shipDate: { + format: 'date-time', + type: 'string', + }, + status: { + description: 'Order Status', + enum: ['placed', 'approved', 'delivered'], + example: 'approved', + type: 'string', + }, + }, + type: 'object', + 'x-swagger-router-model': 'io.swagger.petstore.model.Order', + xml: { + name: 'order', + }, +} as const; + +export const CategorySchema = { + properties: { + id: { + example: 1, + format: 'int64', + type: 'integer', + }, + name: { + example: 'Dogs', + type: 'string', + }, + }, + type: 'object', + 'x-swagger-router-model': 'io.swagger.petstore.model.Category', + xml: { + name: 'category', + }, +} as const; + +export const UserSchema = { + properties: { + email: { + example: 'john@email.com', + type: 'string', + }, + firstName: { + example: 'John', + type: 'string', + }, + id: { + example: 10, + format: 'int64', + type: 'integer', + }, + lastName: { + example: 'James', + type: 'string', + }, + password: { + example: '12345', + type: 'string', + }, + phone: { + example: '12345', + type: 'string', + }, + userStatus: { + description: 'User Status', + example: 1, + format: 'int32', + type: 'integer', + }, + username: { + example: 'theUser', + type: 'string', + }, + }, + type: 'object', + 'x-swagger-router-model': 'io.swagger.petstore.model.User', + xml: { + name: 'user', + }, +} as const; + +export const TagSchema = { + properties: { + id: { + format: 'int64', + type: 'integer', + }, + name: { + type: 'string', + }, + }, + type: 'object', + 'x-swagger-router-model': 'io.swagger.petstore.model.Tag', + xml: { + name: 'tag', + }, +} as const; + +export const PetSchema = { + properties: { + category: { + $ref: '#/components/schemas/Category', + }, + id: { + example: 10, + format: 'int64', + type: 'integer', + }, + name: { + example: 'doggie', + type: 'string', + }, + photoUrls: { + items: { + type: 'string', + xml: { + name: 'photoUrl', + }, + }, + type: 'array', + xml: { + wrapped: true, + }, + }, + status: { + description: 'pet status in the store', + enum: ['available', 'pending', 'sold'], + type: 'string', + }, + tags: { + items: { + $ref: '#/components/schemas/Tag', + }, + type: 'array', + xml: { + wrapped: true, + }, + }, + }, + required: ['name', 'photoUrls'], + type: 'object', + 'x-swagger-router-model': 'io.swagger.petstore.model.Pet', + xml: { + name: 'pet', + }, +} as const; + +export const ApiResponseSchema = { + properties: { + code: { + format: 'int32', + type: 'integer', + }, + message: { + type: 'string', + }, + type: { + type: 'string', + }, + }, + type: 'object', + xml: { + name: '##default', + }, +} as const; diff --git a/examples/openapi-ts-swr/src/client/sdk.gen.ts b/examples/openapi-ts-swr/src/client/sdk.gen.ts new file mode 100644 index 0000000000..f424fe675e --- /dev/null +++ b/examples/openapi-ts-swr/src/client/sdk.gen.ts @@ -0,0 +1,486 @@ +// 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 { + AddPetData, + AddPetErrors, + AddPetResponses, + CreateUserData, + CreateUserErrors, + CreateUserResponses, + CreateUsersWithListInputData, + CreateUsersWithListInputErrors, + CreateUsersWithListInputResponses, + DeleteOrderData, + DeleteOrderErrors, + DeleteOrderResponses, + DeletePetData, + DeletePetErrors, + DeletePetResponses, + DeleteUserData, + DeleteUserErrors, + DeleteUserResponses, + FindPetsByStatusData, + FindPetsByStatusErrors, + FindPetsByStatusResponses, + FindPetsByTagsData, + FindPetsByTagsErrors, + FindPetsByTagsResponses, + GetInventoryData, + GetInventoryErrors, + GetInventoryResponses, + GetOrderByIdData, + GetOrderByIdErrors, + GetOrderByIdResponses, + GetPetByIdData, + GetPetByIdErrors, + GetPetByIdResponses, + GetUserByNameData, + GetUserByNameErrors, + GetUserByNameResponses, + LoginUserData, + LoginUserErrors, + LoginUserResponses, + LogoutUserData, + LogoutUserErrors, + LogoutUserResponses, + PlaceOrderData, + PlaceOrderErrors, + PlaceOrderResponses, + UpdatePetData, + UpdatePetErrors, + UpdatePetResponses, + UpdatePetWithFormData, + UpdatePetWithFormErrors, + UpdatePetWithFormResponses, + UpdateUserData, + UpdateUserErrors, + UpdateUserResponses, + UploadFileData, + UploadFileErrors, + UploadFileResponses, +} from './types.gen'; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, +> = 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; +}; + +/** + * Add a new pet to the store. + * + * Add a new pet to the store. + */ +export const addPet = ( + options: Options, +) => + (options.client ?? client).post({ + security: [ + { + scheme: 'bearer', + type: 'http', + }, + ], + url: '/pet', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers, + }, + }); + +/** + * Update an existing pet. + * + * Update an existing pet by Id. + */ +export const updatePet = ( + options: Options, +) => + (options.client ?? client).put< + UpdatePetResponses, + UpdatePetErrors, + ThrowOnError + >({ + security: [ + { + scheme: 'bearer', + type: 'http', + }, + ], + url: '/pet', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers, + }, + }); + +/** + * Finds Pets by status. + * + * Multiple status values can be provided with comma separated strings. + */ +export const findPetsByStatus = ( + options: Options, +) => + (options.client ?? client).get< + FindPetsByStatusResponses, + FindPetsByStatusErrors, + ThrowOnError + >({ + security: [ + { + scheme: 'bearer', + type: 'http', + }, + ], + url: '/pet/findByStatus', + ...options, + }); + +/** + * Finds Pets by tags. + * + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + */ +export const findPetsByTags = ( + options: Options, +) => + (options.client ?? client).get< + FindPetsByTagsResponses, + FindPetsByTagsErrors, + ThrowOnError + >({ + security: [ + { + scheme: 'bearer', + type: 'http', + }, + ], + url: '/pet/findByTags', + ...options, + }); + +/** + * Deletes a pet. + * + * Delete a pet. + */ +export const deletePet = ( + options: Options, +) => + (options.client ?? client).delete< + DeletePetResponses, + DeletePetErrors, + ThrowOnError + >({ + security: [ + { + scheme: 'bearer', + type: 'http', + }, + ], + url: '/pet/{petId}', + ...options, + }); + +/** + * Find pet by ID. + * + * Returns a single pet. + */ +export const getPetById = ( + options: Options, +) => + (options.client ?? client).get< + GetPetByIdResponses, + GetPetByIdErrors, + ThrowOnError + >({ + security: [ + { + name: 'api_key', + type: 'apiKey', + }, + { + scheme: 'bearer', + type: 'http', + }, + ], + url: '/pet/{petId}', + ...options, + }); + +/** + * Updates a pet in the store with form data. + * + * Updates a pet resource based on the form data. + */ +export const updatePetWithForm = ( + options: Options, +) => + (options.client ?? client).post< + UpdatePetWithFormResponses, + UpdatePetWithFormErrors, + ThrowOnError + >({ + security: [ + { + scheme: 'bearer', + type: 'http', + }, + ], + url: '/pet/{petId}', + ...options, + }); + +/** + * Uploads an image. + * + * Upload image of the pet. + */ +export const uploadFile = ( + options: Options, +) => + (options.client ?? client).post< + UploadFileResponses, + UploadFileErrors, + ThrowOnError + >({ + bodySerializer: null, + security: [ + { + scheme: 'bearer', + type: 'http', + }, + ], + url: '/pet/{petId}/uploadImage', + ...options, + headers: { + 'Content-Type': 'application/octet-stream', + ...options.headers, + }, + }); + +/** + * Returns pet inventories by status. + * + * Returns a map of status codes to quantities. + */ +export const getInventory = ( + options?: Options, +) => + (options?.client ?? client).get< + GetInventoryResponses, + GetInventoryErrors, + ThrowOnError + >({ + security: [ + { + name: 'api_key', + type: 'apiKey', + }, + ], + url: '/store/inventory', + ...options, + }); + +/** + * Place an order for a pet. + * + * Place a new order in the store. + */ +export const placeOrder = ( + options?: Options, +) => + (options?.client ?? client).post< + PlaceOrderResponses, + PlaceOrderErrors, + ThrowOnError + >({ + url: '/store/order', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers, + }, + }); + +/** + * Delete purchase order by identifier. + * + * For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors. + */ +export const deleteOrder = ( + options: Options, +) => + (options.client ?? client).delete< + DeleteOrderResponses, + DeleteOrderErrors, + ThrowOnError + >({ + url: '/store/order/{orderId}', + ...options, + }); + +/** + * Find purchase order by ID. + * + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. + */ +export const getOrderById = ( + options: Options, +) => + (options.client ?? client).get< + GetOrderByIdResponses, + GetOrderByIdErrors, + ThrowOnError + >({ + url: '/store/order/{orderId}', + ...options, + }); + +/** + * Create user. + * + * This can only be done by the logged in user. + */ +export const createUser = ( + options?: Options, +) => + (options?.client ?? client).post< + CreateUserResponses, + CreateUserErrors, + ThrowOnError + >({ + url: '/user', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers, + }, + }); + +/** + * Creates list of users with given input array. + * + * Creates list of users with given input array. + */ +export const createUsersWithListInput = ( + options?: Options, +) => + (options?.client ?? client).post< + CreateUsersWithListInputResponses, + CreateUsersWithListInputErrors, + ThrowOnError + >({ + url: '/user/createWithList', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers, + }, + }); + +/** + * Logs user into the system. + * + * Log into the system. + */ +export const loginUser = ( + options?: Options, +) => + (options?.client ?? client).get< + LoginUserResponses, + LoginUserErrors, + ThrowOnError + >({ + url: '/user/login', + ...options, + }); + +/** + * Logs out current logged in user session. + * + * Log user out of the system. + */ +export const logoutUser = ( + options?: Options, +) => + (options?.client ?? client).get< + LogoutUserResponses, + LogoutUserErrors, + ThrowOnError + >({ + url: '/user/logout', + ...options, + }); + +/** + * Delete user resource. + * + * This can only be done by the logged in user. + */ +export const deleteUser = ( + options: Options, +) => + (options.client ?? client).delete< + DeleteUserResponses, + DeleteUserErrors, + ThrowOnError + >({ + url: '/user/{username}', + ...options, + }); + +/** + * Get user by user name. + * + * Get user detail based on username. + */ +export const getUserByName = ( + options: Options, +) => + (options.client ?? client).get< + GetUserByNameResponses, + GetUserByNameErrors, + ThrowOnError + >({ + url: '/user/{username}', + ...options, + }); + +/** + * Update user resource. + * + * This can only be done by the logged in user. + */ +export const updateUser = ( + options: Options, +) => + (options.client ?? client).put< + UpdateUserResponses, + UpdateUserErrors, + ThrowOnError + >({ + url: '/user/{username}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers, + }, + }); diff --git a/examples/openapi-ts-swr/src/client/swr.gen.ts b/examples/openapi-ts-swr/src/client/swr.gen.ts new file mode 100644 index 0000000000..634b0c243d --- /dev/null +++ b/examples/openapi-ts-swr/src/client/swr.gen.ts @@ -0,0 +1,557 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { + addPet, + createUser, + createUsersWithListInput, + deleteOrder, + deletePet, + deleteUser, + findPetsByStatus, + findPetsByTags, + getInventory, + getOrderById, + getPetById, + getUserByName, + loginUser, + logoutUser, + type Options, + placeOrder, + updatePet, + updatePetWithForm, + updateUser, + uploadFile, +} from './sdk.gen'; +import type { + AddPetData, + CreateUserData, + CreateUsersWithListInputData, + DeleteOrderData, + DeletePetData, + DeleteUserData, + FindPetsByStatusData, + FindPetsByTagsData, + GetInventoryData, + GetOrderByIdData, + GetPetByIdData, + GetUserByNameData, + LoginUserData, + LogoutUserData, + PlaceOrderData, + UpdatePetData, + UpdatePetWithFormData, + UpdateUserData, + UploadFileData, +} from './types.gen'; + +/** + * Add a new pet to the store. + * + * Add a new pet to the store. + */ +export const addPetMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await addPet({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/pet', +}); + +/** + * Update an existing pet. + * + * Update an existing pet by Id. + */ +export const updatePetMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await updatePet({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/pet', +}); + +export const findPetsByStatusKey = (options: Options) => { + const key: any[] = ['/pet/findByStatus']; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +/** + * Finds Pets by status. + * + * Multiple status values can be provided with comma separated strings. + */ +export const findPetsByStatusOptions = ( + options: Options, +) => ({ + fetcher: async () => { + const { data } = await findPetsByStatus({ + ...options, + throwOnError: true, + }); + return data; + }, + key: findPetsByStatusKey(options), +}); + +export const findPetsByTagsKey = (options: Options) => { + const key: any[] = ['/pet/findByTags']; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +/** + * Finds Pets by tags. + * + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + */ +export const findPetsByTagsOptions = ( + options: Options, +) => ({ + fetcher: async () => { + const { data } = await findPetsByTags({ + ...options, + throwOnError: true, + }); + return data; + }, + key: findPetsByTagsKey(options), +}); + +/** + * Deletes a pet. + * + * Delete a pet. + */ +export const deletePetMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await deletePet({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/pet/{petId}', +}); + +export const getPetByIdKey = (options: Options) => { + const key: any[] = ['/pet/{petId}']; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +/** + * Find pet by ID. + * + * Returns a single pet. + */ +export const getPetByIdOptions = (options: Options) => ({ + fetcher: async () => { + const { data } = await getPetById({ + ...options, + throwOnError: true, + }); + return data; + }, + key: getPetByIdKey(options), +}); + +/** + * Updates a pet in the store with form data. + * + * Updates a pet resource based on the form data. + */ +export const updatePetWithFormMutation = ( + options?: Options, +) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await updatePetWithForm({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/pet/{petId}', +}); + +/** + * Uploads an image. + * + * Upload image of the pet. + */ +export const uploadFileMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/pet/{petId}/uploadImage', +}); + +export const getInventoryKey = (options?: Options) => { + const key: any[] = ['/store/inventory']; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +/** + * Returns pet inventories by status. + * + * Returns a map of status codes to quantities. + */ +export const getInventoryOptions = (options?: Options) => ({ + fetcher: async () => { + const { data } = await getInventory({ + ...options, + throwOnError: true, + }); + return data; + }, + key: getInventoryKey(options), +}); + +/** + * Place an order for a pet. + * + * Place a new order in the store. + */ +export const placeOrderMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await placeOrder({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/store/order', +}); + +/** + * Delete purchase order by identifier. + * + * For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors. + */ +export const deleteOrderMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await deleteOrder({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/store/order/{orderId}', +}); + +export const getOrderByIdKey = (options: Options) => { + const key: any[] = ['/store/order/{orderId}']; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +/** + * Find purchase order by ID. + * + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. + */ +export const getOrderByIdOptions = (options: Options) => ({ + fetcher: async () => { + const { data } = await getOrderById({ + ...options, + throwOnError: true, + }); + return data; + }, + key: getOrderByIdKey(options), +}); + +/** + * Create user. + * + * This can only be done by the logged in user. + */ +export const createUserMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await createUser({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/user', +}); + +/** + * Creates list of users with given input array. + * + * Creates list of users with given input array. + */ +export const createUsersWithListInputMutation = ( + options?: Options, +) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await createUsersWithListInput({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/user/createWithList', +}); + +export const loginUserKey = (options?: Options) => { + const key: any[] = ['/user/login']; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +/** + * Logs user into the system. + * + * Log into the system. + */ +export const loginUserOptions = (options?: Options) => ({ + fetcher: async () => { + const { data } = await loginUser({ + ...options, + throwOnError: true, + }); + return data; + }, + key: loginUserKey(options), +}); + +export const logoutUserKey = (options?: Options) => { + const key: any[] = ['/user/logout']; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +/** + * Logs out current logged in user session. + * + * Log user out of the system. + */ +export const logoutUserOptions = (options?: Options) => ({ + fetcher: async () => { + const { data } = await logoutUser({ + ...options, + throwOnError: true, + }); + return data; + }, + key: logoutUserKey(options), +}); + +/** + * Delete user resource. + * + * This can only be done by the logged in user. + */ +export const deleteUserMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await deleteUser({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/user/{username}', +}); + +export const getUserByNameKey = (options: Options) => { + const key: any[] = ['/user/{username}']; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +/** + * Get user by user name. + * + * Get user detail based on username. + */ +export const getUserByNameOptions = (options: Options) => ({ + fetcher: async () => { + const { data } = await getUserByName({ + ...options, + throwOnError: true, + }); + return data; + }, + key: getUserByNameKey(options), +}); + +/** + * Update user resource. + * + * This can only be done by the logged in user. + */ +export const updateUserMutation = (options?: Options) => ({ + fetcher: async ( + _key: unknown, + { + arg, + }: { + arg: Options; + }, + ) => { + const { data } = await updateUser({ + ...options, + ...arg, + throwOnError: true, + }); + return data; + }, + key: '/user/{username}', +}); diff --git a/examples/openapi-ts-swr/src/client/types.gen.ts b/examples/openapi-ts-swr/src/client/types.gen.ts new file mode 100644 index 0000000000..a2e6be0fa4 --- /dev/null +++ b/examples/openapi-ts-swr/src/client/types.gen.ts @@ -0,0 +1,699 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'https://petstore3.swagger.io/api/v3' | (string & {}); +}; + +export type Order = { + complete?: boolean; + id?: number; + petId?: number; + quantity?: number; + shipDate?: string; + /** + * Order Status + */ + status?: 'placed' | 'approved' | 'delivered'; +}; + +export type Category = { + id?: number; + name?: string; +}; + +export type User = { + email?: string; + firstName?: string; + id?: number; + lastName?: string; + password?: string; + phone?: string; + /** + * User Status + */ + userStatus?: number; + username?: string; +}; + +export type Tag = { + id?: number; + name?: string; +}; + +export type Pet = { + category?: Category; + id?: number; + name: string; + photoUrls: Array; + /** + * pet status in the store + */ + status?: 'available' | 'pending' | 'sold'; + tags?: Array; +}; + +export type ApiResponse = { + code?: number; + message?: string; + type?: string; +}; + +export type Pet2 = Pet; + +/** + * List of user object + */ +export type UserArray = Array; + +export type AddPetData = { + /** + * Create a new pet in the store + */ + body: Pet; + path?: never; + query?: never; + url: '/pet'; +}; + +export type AddPetErrors = { + /** + * Invalid input + */ + 400: unknown; + /** + * Validation exception + */ + 422: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type AddPetResponses = { + /** + * Successful operation + */ + 200: Pet; +}; + +export type AddPetResponse = AddPetResponses[keyof AddPetResponses]; + +export type UpdatePetData = { + /** + * Update an existent pet in the store + */ + body: Pet; + path?: never; + query?: never; + url: '/pet'; +}; + +export type UpdatePetErrors = { + /** + * Invalid ID supplied + */ + 400: unknown; + /** + * Pet not found + */ + 404: unknown; + /** + * Validation exception + */ + 422: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type UpdatePetResponses = { + /** + * Successful operation + */ + 200: Pet; +}; + +export type UpdatePetResponse = UpdatePetResponses[keyof UpdatePetResponses]; + +export type FindPetsByStatusData = { + body?: never; + path?: never; + query: { + /** + * Status values that need to be considered for filter + */ + status: 'available' | 'pending' | 'sold'; + }; + url: '/pet/findByStatus'; +}; + +export type FindPetsByStatusErrors = { + /** + * Invalid status value + */ + 400: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type FindPetsByStatusResponses = { + /** + * successful operation + */ + 200: Array; +}; + +export type FindPetsByStatusResponse = + FindPetsByStatusResponses[keyof FindPetsByStatusResponses]; + +export type FindPetsByTagsData = { + body?: never; + path?: never; + query: { + /** + * Tags to filter by + */ + tags: Array; + }; + url: '/pet/findByTags'; +}; + +export type FindPetsByTagsErrors = { + /** + * Invalid tag value + */ + 400: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type FindPetsByTagsResponses = { + /** + * successful operation + */ + 200: Array; +}; + +export type FindPetsByTagsResponse = + FindPetsByTagsResponses[keyof FindPetsByTagsResponses]; + +export type DeletePetData = { + body?: never; + headers?: { + api_key?: string; + }; + path: { + /** + * Pet id to delete + */ + petId: number; + }; + query?: never; + url: '/pet/{petId}'; +}; + +export type DeletePetErrors = { + /** + * Invalid pet value + */ + 400: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type DeletePetResponses = { + /** + * Pet deleted + */ + 200: unknown; +}; + +export type GetPetByIdData = { + body?: never; + path: { + /** + * ID of pet to return + */ + petId: number; + }; + query?: never; + url: '/pet/{petId}'; +}; + +export type GetPetByIdErrors = { + /** + * Invalid ID supplied + */ + 400: unknown; + /** + * Pet not found + */ + 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type GetPetByIdResponses = { + /** + * successful operation + */ + 200: Pet; +}; + +export type GetPetByIdResponse = GetPetByIdResponses[keyof GetPetByIdResponses]; + +export type UpdatePetWithFormData = { + body?: never; + path: { + /** + * ID of pet that needs to be updated + */ + petId: number; + }; + query?: { + /** + * Name of pet that needs to be updated + */ + name?: string; + /** + * Status of pet that needs to be updated + */ + status?: string; + }; + url: '/pet/{petId}'; +}; + +export type UpdatePetWithFormErrors = { + /** + * Invalid input + */ + 400: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type UpdatePetWithFormResponses = { + /** + * successful operation + */ + 200: Pet; +}; + +export type UpdatePetWithFormResponse = + UpdatePetWithFormResponses[keyof UpdatePetWithFormResponses]; + +export type UploadFileData = { + body?: Blob | File; + path: { + /** + * ID of pet to update + */ + petId: number; + }; + query?: { + /** + * Additional Metadata + */ + additionalMetadata?: string; + }; + url: '/pet/{petId}/uploadImage'; +}; + +export type UploadFileErrors = { + /** + * No file uploaded + */ + 400: unknown; + /** + * Pet not found + */ + 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type UploadFileResponses = { + /** + * successful operation + */ + 200: ApiResponse; +}; + +export type UploadFileResponse = UploadFileResponses[keyof UploadFileResponses]; + +export type GetInventoryData = { + body?: never; + path?: never; + query?: never; + url: '/store/inventory'; +}; + +export type GetInventoryErrors = { + /** + * Unexpected error + */ + default: unknown; +}; + +export type GetInventoryResponses = { + /** + * successful operation + */ + 200: { + [key: string]: number; + }; +}; + +export type GetInventoryResponse = + GetInventoryResponses[keyof GetInventoryResponses]; + +export type PlaceOrderData = { + body?: Order; + path?: never; + query?: never; + url: '/store/order'; +}; + +export type PlaceOrderErrors = { + /** + * Invalid input + */ + 400: unknown; + /** + * Validation exception + */ + 422: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type PlaceOrderResponses = { + /** + * successful operation + */ + 200: Order; +}; + +export type PlaceOrderResponse = PlaceOrderResponses[keyof PlaceOrderResponses]; + +export type DeleteOrderData = { + body?: never; + path: { + /** + * ID of the order that needs to be deleted + */ + orderId: number; + }; + query?: never; + url: '/store/order/{orderId}'; +}; + +export type DeleteOrderErrors = { + /** + * Invalid ID supplied + */ + 400: unknown; + /** + * Order not found + */ + 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type DeleteOrderResponses = { + /** + * order deleted + */ + 200: unknown; +}; + +export type GetOrderByIdData = { + body?: never; + path: { + /** + * ID of order that needs to be fetched + */ + orderId: number; + }; + query?: never; + url: '/store/order/{orderId}'; +}; + +export type GetOrderByIdErrors = { + /** + * Invalid ID supplied + */ + 400: unknown; + /** + * Order not found + */ + 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type GetOrderByIdResponses = { + /** + * successful operation + */ + 200: Order; +}; + +export type GetOrderByIdResponse = + GetOrderByIdResponses[keyof GetOrderByIdResponses]; + +export type CreateUserData = { + /** + * Created user object + */ + body?: User; + path?: never; + query?: never; + url: '/user'; +}; + +export type CreateUserErrors = { + /** + * Unexpected error + */ + default: unknown; +}; + +export type CreateUserResponses = { + /** + * successful operation + */ + 200: User; +}; + +export type CreateUserResponse = CreateUserResponses[keyof CreateUserResponses]; + +export type CreateUsersWithListInputData = { + body?: Array; + path?: never; + query?: never; + url: '/user/createWithList'; +}; + +export type CreateUsersWithListInputErrors = { + /** + * Unexpected error + */ + default: unknown; +}; + +export type CreateUsersWithListInputResponses = { + /** + * Successful operation + */ + 200: User; +}; + +export type CreateUsersWithListInputResponse = + CreateUsersWithListInputResponses[keyof CreateUsersWithListInputResponses]; + +export type LoginUserData = { + body?: never; + path?: never; + query?: { + /** + * The password for login in clear text + */ + password?: string; + /** + * The user name for login + */ + username?: string; + }; + url: '/user/login'; +}; + +export type LoginUserErrors = { + /** + * Invalid username/password supplied + */ + 400: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type LoginUserResponses = { + /** + * successful operation + */ + 200: string; +}; + +export type LoginUserResponse = LoginUserResponses[keyof LoginUserResponses]; + +export type LogoutUserData = { + body?: never; + path?: never; + query?: never; + url: '/user/logout'; +}; + +export type LogoutUserErrors = { + /** + * Unexpected error + */ + default: unknown; +}; + +export type LogoutUserResponses = { + /** + * successful operation + */ + 200: unknown; +}; + +export type DeleteUserData = { + body?: never; + path: { + /** + * The name that needs to be deleted + */ + username: string; + }; + query?: never; + url: '/user/{username}'; +}; + +export type DeleteUserErrors = { + /** + * Invalid username supplied + */ + 400: unknown; + /** + * User not found + */ + 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type DeleteUserResponses = { + /** + * User deleted + */ + 200: unknown; +}; + +export type GetUserByNameData = { + body?: never; + path: { + /** + * The name that needs to be fetched. Use user1 for testing + */ + username: string; + }; + query?: never; + url: '/user/{username}'; +}; + +export type GetUserByNameErrors = { + /** + * Invalid username supplied + */ + 400: unknown; + /** + * User not found + */ + 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type GetUserByNameResponses = { + /** + * successful operation + */ + 200: User; +}; + +export type GetUserByNameResponse = + GetUserByNameResponses[keyof GetUserByNameResponses]; + +export type UpdateUserData = { + /** + * Update an existent user in the store + */ + body?: User; + path: { + /** + * name that need to be deleted + */ + username: string; + }; + query?: never; + url: '/user/{username}'; +}; + +export type UpdateUserErrors = { + /** + * bad request + */ + 400: unknown; + /** + * user not found + */ + 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type UpdateUserResponses = { + /** + * successful operation + */ + 200: unknown; +}; diff --git a/examples/openapi-ts-swr/src/main.tsx b/examples/openapi-ts-swr/src/main.tsx new file mode 100644 index 0000000000..dbdf7dfe44 --- /dev/null +++ b/examples/openapi-ts-swr/src/main.tsx @@ -0,0 +1,36 @@ +import '@radix-ui/themes/styles.css'; + +import { Theme } from '@radix-ui/themes'; +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import { SWRConfig } from 'swr'; + +import App from './App.tsx'; +import { client } from './client/client.gen'; + +// configure internal service client +client.setConfig({ + // set default base url for requests + baseUrl: 'https://petstore3.swagger.io/api/v3', + // set default headers for requests + headers: { + Authorization: 'Bearer ', + }, +}); + +ReactDOM.createRoot(document.getElementById('root')!).render( + + + + + + + , +); diff --git a/examples/openapi-ts-swr/src/vite-env.d.ts b/examples/openapi-ts-swr/src/vite-env.d.ts new file mode 100644 index 0000000000..11f02fe2a0 --- /dev/null +++ b/examples/openapi-ts-swr/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/examples/openapi-ts-swr/tailwind.config.js b/examples/openapi-ts-swr/tailwind.config.js new file mode 100644 index 0000000000..0284c5614d --- /dev/null +++ b/examples/openapi-ts-swr/tailwind.config.js @@ -0,0 +1,8 @@ +/** @type {import('tailwindcss').Config} */ +export default { + content: ['./index.html', './src/**/*.{html,js,ts,jsx,tsx}'], + plugins: [], + theme: { + extend: {}, + }, +}; diff --git a/examples/openapi-ts-swr/tsconfig.json b/examples/openapi-ts-swr/tsconfig.json new file mode 100644 index 0000000000..04664de395 --- /dev/null +++ b/examples/openapi-ts-swr/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": false, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/examples/openapi-ts-swr/tsconfig.node.json b/examples/openapi-ts-swr/tsconfig.node.json new file mode 100644 index 0000000000..97ede7ee6f --- /dev/null +++ b/examples/openapi-ts-swr/tsconfig.node.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true, + "strict": true + }, + "include": ["vite.config.ts"] +} diff --git a/examples/openapi-ts-swr/vite.config.ts b/examples/openapi-ts-swr/vite.config.ts new file mode 100644 index 0000000000..8cbf22f1ba --- /dev/null +++ b/examples/openapi-ts-swr/vite.config.ts @@ -0,0 +1,7 @@ +import { createViteConfig } from '@config/vite-base'; +import react from '@vitejs/plugin-react'; + +// https://vitejs.dev/config/ +export default createViteConfig({ + plugins: [react()], +}); diff --git a/packages/openapi-ts-tests/main/test/plugins.test.ts b/packages/openapi-ts-tests/main/test/plugins.test.ts index 509b9d489c..6b3908a94c 100644 --- a/packages/openapi-ts-tests/main/test/plugins.test.ts +++ b/packages/openapi-ts-tests/main/test/plugins.test.ts @@ -562,6 +562,37 @@ for (const version of versions) { }), description: 'generate Angular requests and resources (class)', }, + { + config: createConfig({ + output: 'fetch', + plugins: ['swr', '@hey-api/client-fetch'], + }), + description: 'generate Fetch API client with SWR plugin', + }, + { + config: createConfig({ + output: 'axios', + plugins: ['swr', '@hey-api/client-axios'], + }), + description: 'generate Axios client with SWR plugin', + }, + { + config: createConfig({ + input: 'sdk-instance.yaml', + output: 'asClass', + plugins: [ + 'swr', + '@hey-api/client-fetch', + { + asClass: true, + classNameBuilder: '{{name}}Service', + name: '@hey-api/sdk', + }, + ], + }), + description: + 'generate Fetch API client with SWR plugin using class-based SDKs', + }, ]; it.each(scenarios)('$description', async ({ config }) => { @@ -591,10 +622,12 @@ for (const version of versions) { const myPlugin: DefinePlugin<{ customOption: boolean; name: any; + output: string; }>['Config'] = { api: undefined, config: { customOption: true, + output: 'my-plugin', }, dependencies: ['@hey-api/typescript'], handler: vi.fn(), @@ -616,9 +649,12 @@ for (const version of versions) { it('throws on invalid dependency', async () => { const myPlugin: DefinePlugin<{ name: any; + output: string; }>['Config'] = { api: undefined, - config: {}, + config: { + output: 'my-plugin', + }, dependencies: ['@hey-api/oops'], handler: vi.fn(), name: 'my-plugin', diff --git a/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts b/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts new file mode 100644 index 0000000000..4fc0595d9c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts @@ -0,0 +1,228 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { createClient, type UserConfig } from '@hey-api/openapi-ts'; +import { describe, expect, it } from 'vitest'; + +import { getFilePaths, getSpecsPath } from '../../../../utils'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +describe('SWR Plugin Basic Generation', () => { + const version = '3.1.x'; + const namespace = 'plugins'; + + const createConfig = ( + userConfig: Omit & Pick, 'input'>, + ): UserConfig => ({ + input: path.join(getSpecsPath(), version, 'security-api-key.json'), + logs: { + level: 'silent', + }, + ...userConfig, + }); + + it('generates SWR hooks with key and fetcher functions', async () => { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'basic', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const filePaths = getFilePaths(outputPath); + + // Check that swr.gen.ts was generated + const swrFile = filePaths.find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Verify query Key functions are generated + expect(fileContent).toContain('Key ='); + + // Verify query Options functions are generated + expect(fileContent).toContain('Options ='); + + // Verify key and fetcher structure + expect(fileContent).toContain('key:'); + expect(fileContent).toContain('fetcher:'); + + // Verify types are imported + expect(fileContent).toContain("from './sdk.gen'"); + expect(fileContent).toContain("from './types.gen'"); + } + }); + + it('generates SWR query hooks with proper TypeScript types', async () => { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'types', + ), + plugins: [ + '@hey-api/client-fetch', + '@hey-api/typescript', + '@hey-api/sdk', + 'swr', + ], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Verify query Key functions are generated + expect(fileContent).toContain('Key ='); + + // Verify query Options functions are generated + expect(fileContent).toContain('Options ='); + + // Verify arrow functions are async + expect(fileContent).toContain('async () => {'); + + // Verify proper structure (key and fetcher) + expect(fileContent).toContain('fetcher:'); + } + }); + + it('generates mutation hooks with proper types for POST requests', async () => { + const config = createConfig({ + input: path.join(getSpecsPath(), version, 'full.yaml'), + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'mutation-post', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Verify Mutation functions are generated + expect(fileContent).toContain('Mutation ='); + + // Verify mutation fetcher signature with _key and arg + expect(fileContent).toContain('_key: unknown'); + expect(fileContent).toContain('{ arg }'); + + // Verify async fetcher for mutations with proper typing + expect(fileContent).toMatch(/fetcher: async \(_key: unknown, { arg }/); + + // Verify key and fetcher structure + expect(fileContent).toContain('key:'); + expect(fileContent).toContain('fetcher:'); + } + }); + + it('handles required vs optional parameters correctly', async () => { + const config = createConfig({ + input: path.join(getSpecsPath(), version, 'full.yaml'), + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'parameters', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Required path parameters should have required options + // Pattern: (options: Options<...>) + expect(fileContent).toMatch(/\(options: Options) + expect(fileContent).toMatch(/\(options\?: Options { + const config = createConfig({ + input: path.join(getSpecsPath(), version, 'full.yaml'), + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'http-methods', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // POST/PUT/PATCH/DELETE should generate Mutation functions + expect(fileContent).toContain('Mutation'); + + // Verify mutations use arg spreading pattern + expect(fileContent).toContain('...arg'); + + // Verify throwOnError is used + expect(fileContent).toContain('throwOnError: true'); + } + }); +}); diff --git a/packages/openapi-ts-tests/main/test/plugins/swr/edge-cases.test.ts b/packages/openapi-ts-tests/main/test/plugins/swr/edge-cases.test.ts new file mode 100644 index 0000000000..ca99a94516 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/plugins/swr/edge-cases.test.ts @@ -0,0 +1,290 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { createClient, type UserConfig } from '@hey-api/openapi-ts'; +import { describe, expect, it } from 'vitest'; + +import { getFilePaths, getSpecsPath } from '../../../../utils'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +describe('SWR Plugin Edge Cases', () => { + const version = '3.1.x'; + const namespace = 'plugins'; + + const createConfig = ( + userConfig: Omit & Pick, 'input'>, + ): UserConfig => ({ + input: path.join(getSpecsPath(), version, 'full.yaml'), + logs: { + level: 'silent', + }, + ...userConfig, + }); + + it('handles operations with no parameters', async () => { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'edge-no-params', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Operations with no parameters should have optional options + expect(fileContent).toMatch(/\(options\?: Options { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'edge-path-only', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Path parameters should be required + expect(fileContent).toMatch(/\(options: Options { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'edge-query-only', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Query parameters might be optional + expect(fileContent).toMatch(/options\??: Options { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'edge-path-query', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Should generate functions with options parameter + expect(fileContent).toMatch(/\(options\??: Options { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'edge-body-path', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Should generate Mutation functions for POST/PUT/PATCH + expect(fileContent).toContain('Mutation'); + + // Should use arg spreading pattern for body + path + expect(fileContent).toContain('...arg'); + } + }); + + it('handles array responses', async () => { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'edge-array-response', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Should generate functions that return data + expect(fileContent).toContain('return data;'); + + // Should have proper async fetcher + expect(fileContent).toContain('async'); + } + }); + + it('handles nullable responses', async () => { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'edge-nullable', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Should generate functions with proper return types + expect(fileContent).toContain('return data;'); + } + }); + + it('generates correct SWR keys for complex parameters', async () => { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'edge-complex-keys', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Key functions should be generated + expect(fileContent).toContain('Key ='); + + // Keys should be functions that construct arrays (SWR format) + // Pattern: const key: any[] = [ '/path', ... + expect(fileContent).toMatch(/const key: any\[\] = \[/); + + // Keys should contain path strings + expect(fileContent).toMatch(/'\/(api\/)?[^']*'/); + } + }); +}); diff --git a/packages/openapi-ts-tests/main/test/plugins/swr/infinite.test.ts b/packages/openapi-ts-tests/main/test/plugins/swr/infinite.test.ts new file mode 100644 index 0000000000..c837777710 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/plugins/swr/infinite.test.ts @@ -0,0 +1,98 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { createClient, type UserConfig } from '@hey-api/openapi-ts'; +import { describe, expect, it } from 'vitest'; + +import { getFilePaths, getSpecsPath } from '../../../../utils'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +describe('SWR Infinite Plugin', () => { + const version = '3.1.x'; + const namespace = 'plugins'; + + const createConfig = ( + userConfig: Omit & Pick, 'input'>, + ): UserConfig => ({ + input: path.join(getSpecsPath(), version, 'full.yaml'), + logs: { + level: 'silent', + }, + ...userConfig, + }); + + it('generates infinite options with getKey function', async () => { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'infinite', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // Check if Infinite functions are generated + // Note: only operations with pagination support will have Infinite functions + // We're checking that the plugin doesn't crash and generates valid code + expect(fileContent).toContain('export'); + + // If Infinite functions are generated, they should have getKey + if (fileContent.includes('Infinite =')) { + expect(fileContent).toContain('getKey:'); + expect(fileContent).toContain('pageIndex'); + expect(fileContent).toContain('previousPageData'); + } + } + }); + + it('generates correct fetcher for infinite queries', async () => { + const config = createConfig({ + output: path.join( + __dirname, + 'generated', + version, + namespace, + 'swr', + 'infinite-fetcher', + ), + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'swr'], + }); + + await createClient(config); + + const outputPath = config.output as string; + const swrFile = getFilePaths(outputPath).find((filePath) => + filePath.endsWith('swr.gen.ts'), + ); + + expect(swrFile).toBeDefined(); + + if (swrFile) { + const fileContent = fs.readFileSync(swrFile, 'utf-8'); + + // If Infinite functions are generated, they should have fetcher + if (fileContent.includes('Infinite =')) { + expect(fileContent).toContain('fetcher:'); + expect(fileContent).toContain('async'); + } + } + }); +}); diff --git a/packages/openapi-ts/src/plugins/swr/config.ts b/packages/openapi-ts/src/plugins/swr/config.ts index 9da5a557bf..e640be147e 100644 --- a/packages/openapi-ts/src/plugins/swr/config.ts +++ b/packages/openapi-ts/src/plugins/swr/config.ts @@ -13,39 +13,43 @@ export const defaultConfig: SwrPlugin['Config'] = { handler: handler as SwrPlugin['Handler'], name: 'swr', resolveConfig: (plugin, context) => { - plugin.config.infiniteQueryKeys = context.valueToObject({ + // Resolve swrKeys configuration + plugin.config.swrKeys = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, - name: '{{name}}InfiniteQueryKey', - tags: false, + name: '{{name}}Key', }, mappers: { boolean: (enabled) => ({ enabled }), function: (name) => ({ name }), string: (name) => ({ name }), }, - value: plugin.config.infiniteQueryKeys, + value: plugin.config.swrKeys, }); - plugin.config.infiniteQueryOptions = context.valueToObject({ + // Resolve swrOptions configuration + plugin.config.swrOptions = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, - name: '{{name}}InfiniteOptions', + exported: true, + name: '{{name}}Options', }, mappers: { boolean: (enabled) => ({ enabled }), function: (name) => ({ name }), string: (name) => ({ name }), }, - value: plugin.config.infiniteQueryOptions, + value: plugin.config.swrOptions, }); - plugin.config.mutationOptions = context.valueToObject({ + // Resolve swrMutationOptions configuration + plugin.config.swrMutationOptions = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, + exported: true, name: '{{name}}Mutation', }, mappers: { @@ -53,61 +57,24 @@ export const defaultConfig: SwrPlugin['Config'] = { function: (name) => ({ name }), string: (name) => ({ name }), }, - value: plugin.config.mutationOptions, + value: plugin.config.swrMutationOptions, }); - plugin.config.queryKeys = context.valueToObject({ - defaultValue: { - case: plugin.config.case ?? 'camelCase', - enabled: true, - name: '{{name}}QueryKey', - tags: false, - }, - mappers: { - boolean: (enabled) => ({ enabled }), - function: (name) => ({ name }), - string: (name) => ({ name }), - }, - value: plugin.config.queryKeys, - }); - - plugin.config.queryOptions = context.valueToObject({ + // Resolve swrInfiniteOptions configuration + plugin.config.swrInfiniteOptions = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, exported: true, - name: '{{name}}Options', + name: '{{name}}Infinite', }, mappers: { boolean: (enabled) => ({ enabled }), function: (name) => ({ name }), string: (name) => ({ name }), }, - value: plugin.config.queryOptions, - }); - - plugin.config.useSwr = context.valueToObject({ - defaultValue: { - case: plugin.config.case ?? 'camelCase', - enabled: true, - name: 'use{{name}}', - }, - mappers: { - boolean: (enabled) => ({ enabled }), - function: (name) => ({ enabled: true, name }), - object: (fields) => ({ enabled: true, ...fields }), - string: (name) => ({ enabled: true, name }), - }, - value: plugin.config.useSwr, + value: plugin.config.swrInfiniteOptions, }); - - if (plugin.config.useSwr.enabled) { - // useSwr hooks consume queryOptions - if (!plugin.config.queryOptions.enabled) { - plugin.config.queryOptions.enabled = true; - plugin.config.queryOptions.exported = false; - } - } }, }; diff --git a/packages/openapi-ts/src/plugins/swr/plugin.ts b/packages/openapi-ts/src/plugins/swr/plugin.ts index d5ebb4d113..b63ced8717 100644 --- a/packages/openapi-ts/src/plugins/swr/plugin.ts +++ b/packages/openapi-ts/src/plugins/swr/plugin.ts @@ -1,4 +1,86 @@ -import type { SwrPlugin } from './types'; -import { handlerV2 } from './v2/plugin'; +import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation'; +import { stringCase } from '~/utils/stringCase'; -export const handler: SwrPlugin['Handler'] = (args) => handlerV2(args); +import { createSwrInfiniteOptions } from './swrInfiniteOptions'; +import { createSwrMutationOptions } from './swrMutationOptions'; +import { createSwrOptions } from './swrOptions'; +import type { PluginHandler } from './types'; + +/** + * Main handler for the SWR plugin. + * + * This plugin generates useSWR and useSWRMutation options for each operation. + * It follows a similar pattern to TanStack Query but adapted for SWR's API. + */ +export const handler: PluginHandler = ({ plugin }) => { + // Register external symbols from axios (for error types) + plugin.registerSymbol({ + external: 'axios', + kind: 'type', + meta: { + category: 'external', + resource: 'axios.AxiosError', + }, + name: 'AxiosError', + }); + + const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); + + // Iterate over all operations + plugin.forEach( + 'operation', + ({ operation }) => { + // Get the SDK function name + const classes = sdkPlugin.config.asClass + ? operationClasses({ + context: plugin.context, + operation, + plugin: sdkPlugin, + }) + : undefined; + const entry = classes ? classes.values().next().value : undefined; + const sdkFn = entry + ? [ + plugin.referenceSymbol({ + category: 'utility', + resource: 'class', + resourceId: entry.path[0], + tool: 'sdk', + }).placeholder, + ...entry.path.slice(1).map((className) => + stringCase({ + case: 'camelCase', + value: className, + }), + ), + entry.methodName, + ] + .filter(Boolean) + .join('.') + : plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }).placeholder; + + // Generate appropriate SWR functions based on operation type + if (plugin.hooks.operation.isQuery(operation)) { + if (plugin.config.swrOptions.enabled) { + createSwrOptions({ operation, plugin, sdkFn }); + } + if (plugin.config.swrInfiniteOptions.enabled) { + createSwrInfiniteOptions({ operation, plugin, sdkFn }); + } + } + + if (plugin.hooks.operation.isMutation(operation)) { + if (plugin.config.swrMutationOptions.enabled) { + createSwrMutationOptions({ operation, plugin, sdkFn }); + } + } + }, + { + order: 'declarations', + }, + ); +}; diff --git a/packages/openapi-ts/src/plugins/swr/swrInfiniteOptions.ts b/packages/openapi-ts/src/plugins/swr/swrInfiniteOptions.ts new file mode 100644 index 0000000000..cd7f0d7595 --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/swrInfiniteOptions.ts @@ -0,0 +1,352 @@ +import type ts from 'typescript'; + +import { operationPagination } from '~/ir/operation'; +import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; +import { + createOperationComment, + hasOperationSse, + isOperationOptionsRequired, +} from '~/plugins/shared/utils/operation'; +import { tsc } from '~/tsc'; + +import type { PluginInstance } from './types'; +import { useTypeData } from './useType'; + +const optionsParamName = 'options'; + +/** + * Create useSWRInfinite options for a given operation. + * + * This generates a function that returns an object with: + * - getKey: A function that generates keys for each page + * - fetcher: Async function that fetches a single page + * + * Example output: + * export const getUsersInfinite = (options?: GetUsersOptions) => ({ + * getKey: (pageIndex: number, previousPageData: any) => { + * if (previousPageData && !previousPageData.hasMore) return null; + * return ['/users', { ...options, page: pageIndex }]; + * }, + * fetcher: async (key) => { + * const [, params] = key; + * const { data } = await getUsers({ + * ...params, + * throwOnError: true, + * }); + * return data; + * }, + * }); + */ +export const createSwrInfiniteOptions = ({ + operation, + plugin, + sdkFn, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; + sdkFn: string; +}): void => { + if (hasOperationSse({ operation })) { + return; + } + + // Check if this operation supports pagination + const pagination = operationPagination({ + context: plugin.context, + operation, + }); + + // Only generate infinite options for operations with pagination + if (!pagination) { + return; + } + + const isRequiredOptions = isOperationOptionsRequired({ + context: plugin.context, + operation, + }); + + const typeData = useTypeData({ operation, plugin }); + + // Create the getKey function + // getKey: (pageIndex: number, previousPageData: any) => key | null + // Returns a flat array: ['/path', { path: ... }, { query: ... }, { body: ... }] + const getKeyFunction = tsc.arrowFunction({ + multiLine: true, + parameters: [ + { + name: 'pageIndex', + type: tsc.typeReferenceNode({ typeName: 'number' }), + }, + { + name: 'previousPageData', + type: tsc.typeReferenceNode({ typeName: 'any' }), + }, + ], + statements: [ + // Create page parameter object + tsc.constVariable({ + expression: tsc.objectExpression({ + multiLine: true, + obj: [ + { + key: pagination.in, + value: tsc.objectExpression({ + obj: [ + { + key: pagination.name, + value: tsc.identifier({ text: 'pageIndex' }), + }, + ], + }), + }, + ], + }), + name: 'pageParam', + }), + // Build key array similar to swrKey + tsc.constVariable({ + expression: tsc.arrayLiteralExpression({ + elements: [tsc.stringLiteral({ text: operation.path })], + }), + name: 'key', + typeName: tsc.typeReferenceNode({ typeName: 'any[]' }), + }), + // Add path parameters if they exist + tsc.ifStatement({ + expression: tsc.propertyAccessExpression({ + expression: tsc.identifier({ text: 'options' }), + isOptional: true, + name: tsc.identifier({ text: 'path' }), + }), + thenStatement: tsc.block({ + statements: [ + tsc.expressionToStatement({ + expression: tsc.callExpression({ + functionName: tsc.propertyAccessExpression({ + expression: 'key', + name: 'push', + }), + parameters: [ + tsc.objectExpression({ + multiLine: false, + obj: [ + { + key: 'path', + value: tsc.propertyAccessExpression({ + expression: 'options', + name: 'path', + }), + }, + ], + }), + ], + }), + }), + ], + }), + }), + // Add query parameters (merged with pageParam) + tsc.constVariable({ + expression: tsc.objectExpression({ + multiLine: false, + obj: [ + { + spread: tsc.propertyAccessExpression({ + expression: 'options', + isOptional: true, + name: 'query', + }), + }, + { + spread: tsc.propertyAccessExpression({ + expression: 'pageParam', + name: pagination.in, + }), + }, + ], + }), + name: 'mergedQuery', + }), + tsc.expressionToStatement({ + expression: tsc.callExpression({ + functionName: tsc.propertyAccessExpression({ + expression: 'key', + name: 'push', + }), + parameters: [ + tsc.objectExpression({ + multiLine: false, + obj: [ + { + key: 'query', + value: tsc.identifier({ text: 'mergedQuery' }), + }, + ], + }), + ], + }), + }), + // Add body if it exists + tsc.ifStatement({ + expression: tsc.propertyAccessExpression({ + expression: tsc.identifier({ text: 'options' }), + isOptional: true, + name: tsc.identifier({ text: 'body' }), + }), + thenStatement: tsc.block({ + statements: [ + tsc.expressionToStatement({ + expression: tsc.callExpression({ + functionName: tsc.propertyAccessExpression({ + expression: 'key', + name: 'push', + }), + parameters: [ + tsc.objectExpression({ + multiLine: false, + obj: [ + { + key: 'body', + value: tsc.propertyAccessExpression({ + expression: 'options', + name: 'body', + }), + }, + ], + }), + ], + }), + }), + ], + }), + }), + // return key + tsc.returnStatement({ + expression: tsc.identifier({ text: 'key' }), + }), + ], + }); + + // Create the fetcher function + // fetcher: async (key) => { ... } + // key structure: ['/path', { path: ... }, { query: ... }, { body: ... }] + // Merge all objects after the first element (path string) + + const fetcherStatements: Array = []; + + // Create params variable by merging all objects in the key array (excluding the first path string) + fetcherStatements.push( + tsc.constVariable({ + expression: tsc.identifier({ + text: 'Object.assign({}, ...key.slice(1))', + }), + name: 'params', + }), + ); + + const awaitSdkExpression = tsc.awaitExpression({ + expression: tsc.callExpression({ + functionName: sdkFn, + parameters: [ + tsc.objectExpression({ + multiLine: true, + obj: [ + { + spread: 'params', + }, + { + key: 'throwOnError', + value: true, + }, + ], + }), + ], + }), + }); + + if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { + fetcherStatements.push( + tsc.returnVariable({ + expression: awaitSdkExpression, + }), + ); + } else { + fetcherStatements.push( + tsc.constVariable({ + destructure: true, + expression: awaitSdkExpression, + name: 'data', + }), + tsc.returnVariable({ + expression: 'data', + }), + ); + } + + const fetcherFunction = tsc.arrowFunction({ + async: true, + multiLine: true, + parameters: [ + { + name: 'key', + }, + ], + statements: fetcherStatements, + }); + + // Build the infinite options object + const swrInfiniteOptionsObj = tsc.objectExpression({ + obj: [ + { + key: 'getKey', + value: getKeyFunction, + }, + { + key: 'fetcher', + value: fetcherFunction, + }, + ], + }); + + // Register the infinite options symbol + const symbolSwrInfiniteOptionsFn = plugin.registerSymbol({ + exported: plugin.config.swrInfiniteOptions.exported, + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'swrInfiniteOptions', + tool: plugin.name, + }, + name: buildName({ + config: plugin.config.swrInfiniteOptions, + name: operation.id, + }), + }); + + const statement = tsc.constVariable({ + comment: plugin.config.comments + ? createOperationComment({ operation }) + : undefined, + exportConst: symbolSwrInfiniteOptionsFn.exported, + expression: tsc.arrowFunction({ + parameters: [ + { + isRequired: isRequiredOptions, + name: optionsParamName, + type: typeData, + }, + ], + statements: [ + tsc.returnStatement({ + expression: swrInfiniteOptionsObj, + }), + ], + }), + name: symbolSwrInfiniteOptionsFn.placeholder, + }); + + plugin.setSymbolValue(symbolSwrInfiniteOptionsFn, statement); +}; diff --git a/packages/openapi-ts/src/plugins/swr/swrKey.ts b/packages/openapi-ts/src/plugins/swr/swrKey.ts new file mode 100644 index 0000000000..4c6d0ca295 --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/swrKey.ts @@ -0,0 +1,214 @@ +import type { Symbol } from '@hey-api/codegen-core'; + +import { hasOperationDataRequired } from '~/ir/operation'; +import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; +import { tsc } from '~/tsc'; + +import type { PluginInstance } from './types'; +import { useTypeData } from './useType'; + +/** + * Generate a SWR key statement for a given operation. + * + * For SWR, keys are structured to include only relevant fields (path, query, body) + * to ensure stable caching behavior. + * + * Example output: + * export const getUserByIdKey = (options: GetUserByIdOptions) => { + * const key: any[] = ['/api/users/{id}']; + * if (options?.path) key.push({ path: options.path }); + * if (options?.query) key.push({ query: options.query }); + * return key; + * } + */ +export const swrKeyStatement = ({ + operation, + plugin, + symbol, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; + symbol: Symbol; +}) => { + const typeData = useTypeData({ operation, plugin }); + + // Build statements that conditionally add relevant fields to the key + const statements: Array = []; + + // Initialize key array with the operation path as identifier + statements.push( + tsc.constVariable({ + expression: tsc.arrayLiteralExpression({ + elements: [tsc.stringLiteral({ text: operation.path })], + }), + name: 'key', + typeName: tsc.typeReferenceNode({ typeName: 'any[]' }), + }), + ); + + // Add path parameters if they exist + statements.push( + tsc.ifStatement({ + expression: tsc.propertyAccessExpression({ + expression: tsc.identifier({ text: 'options' }), + isOptional: true, + name: tsc.identifier({ text: 'path' }), + }), + thenStatement: tsc.block({ + statements: [ + tsc.expressionToStatement({ + expression: tsc.callExpression({ + functionName: tsc.propertyAccessExpression({ + expression: 'key', + name: 'push', + }), + parameters: [ + tsc.objectExpression({ + multiLine: false, + obj: [ + { + key: 'path', + value: tsc.propertyAccessExpression({ + expression: 'options', + name: 'path', + }), + }, + ], + }), + ], + }), + }), + ], + }), + }), + ); + + // Add query parameters if they exist + statements.push( + tsc.ifStatement({ + expression: tsc.propertyAccessExpression({ + expression: tsc.identifier({ text: 'options' }), + isOptional: true, + name: tsc.identifier({ text: 'query' }), + }), + thenStatement: tsc.block({ + statements: [ + tsc.expressionToStatement({ + expression: tsc.callExpression({ + functionName: tsc.propertyAccessExpression({ + expression: 'key', + name: 'push', + }), + parameters: [ + tsc.objectExpression({ + multiLine: false, + obj: [ + { + key: 'query', + value: tsc.propertyAccessExpression({ + expression: 'options', + name: 'query', + }), + }, + ], + }), + ], + }), + }), + ], + }), + }), + ); + + // Add body if it exists + statements.push( + tsc.ifStatement({ + expression: tsc.propertyAccessExpression({ + expression: tsc.identifier({ text: 'options' }), + isOptional: true, + name: tsc.identifier({ text: 'body' }), + }), + thenStatement: tsc.block({ + statements: [ + tsc.expressionToStatement({ + expression: tsc.callExpression({ + functionName: tsc.propertyAccessExpression({ + expression: 'key', + name: 'push', + }), + parameters: [ + tsc.objectExpression({ + multiLine: false, + obj: [ + { + key: 'body', + value: tsc.propertyAccessExpression({ + expression: 'options', + name: 'body', + }), + }, + ], + }), + ], + }), + }), + ], + }), + }), + ); + + // Return the key array + statements.push( + tsc.returnStatement({ + expression: tsc.identifier({ text: 'key' }), + }), + ); + + const statement = tsc.constVariable({ + exportConst: symbol.exported, + expression: tsc.arrowFunction({ + multiLine: true, + parameters: [ + { + isRequired: hasOperationDataRequired(operation), + name: 'options', + type: typeData, + }, + ], + statements, + }), + name: symbol.placeholder, + }); + + return statement; +}; + +/** + * Register a SWR key symbol for a given operation. + */ +export const registerSwrKey = ({ + operation, + plugin, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; +}): Symbol => { + const symbol = plugin.registerSymbol({ + exported: true, + name: buildName({ + config: plugin.config.swrKeys, + name: operation.id, + }), + }); + + const node = swrKeyStatement({ + operation, + plugin, + symbol, + }); + + plugin.setSymbolValue(symbol, node); + + return symbol; +}; diff --git a/packages/openapi-ts/src/plugins/swr/swrMutationOptions.ts b/packages/openapi-ts/src/plugins/swr/swrMutationOptions.ts new file mode 100644 index 0000000000..e2e2dfe0a2 --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/swrMutationOptions.ts @@ -0,0 +1,172 @@ +import type ts from 'typescript'; + +import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; +import { createOperationComment } from '~/plugins/shared/utils/operation'; +import { tsc } from '~/tsc'; + +import type { PluginInstance } from './types'; +import { useTypeData } from './useType'; + +const optionsParamName = 'options'; + +/** + * Create useSWRMutation options for a given operation. + * + * This generates a function that returns an object with: + * - key: The mutation key (usually the operation path) + * - fetcher: Async function that calls the SDK function with arg parameter + * + * Example output: + * export const createUserMutation = (options?: CreateUserOptions) => ({ + * key: '/api/users', + * fetcher: async (arg) => { + * const { data } = await createUser({ + * ...options, + * ...arg, + * throwOnError: true, + * }); + * return data; + * }, + * }); + */ +export const createSwrMutationOptions = ({ + operation, + plugin, + sdkFn, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; + sdkFn: string; +}): void => { + const typeData = useTypeData({ operation, plugin }); + + // Create the SDK function call with arg parameter + const awaitSdkExpression = tsc.awaitExpression({ + expression: tsc.callExpression({ + functionName: sdkFn, + parameters: [ + tsc.objectExpression({ + multiLine: true, + obj: [ + { + spread: optionsParamName, + }, + { + spread: 'arg', + }, + { + key: 'throwOnError', + value: true, + }, + ], + }), + ], + }), + }); + + const statements: Array = []; + + if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { + statements.push( + tsc.returnVariable({ + expression: awaitSdkExpression, + }), + ); + } else { + statements.push( + tsc.constVariable({ + destructure: true, + expression: awaitSdkExpression, + name: 'data', + }), + tsc.returnVariable({ + expression: 'data', + }), + ); + } + + // Build the options object + const swrMutationOptionsObj = tsc.objectExpression({ + obj: [ + { + key: 'key', + value: tsc.stringLiteral({ text: operation.path }), + }, + { + key: 'fetcher', + value: tsc.arrowFunction({ + async: true, + multiLine: true, + parameters: [ + { + name: '_key', + type: tsc.keywordTypeNode({ + keyword: 'unknown', + }), + }, + { + destructure: [ + { + name: 'arg', + }, + ], + name: undefined, + type: tsc.typeInterfaceNode({ + properties: [ + { + isRequired: true, + name: 'arg', + type: typeData, + }, + ], + useLegacyResolution: false, + }), + }, + ], + statements, + }), + }, + ], + }); + + // Register the mutation options symbol + const symbolSwrMutationOptionsFn = plugin.registerSymbol({ + exported: plugin.config.swrMutationOptions.exported, + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'swrMutationOptions', + tool: plugin.name, + }, + name: buildName({ + config: plugin.config.swrMutationOptions, + name: operation.id, + }), + }); + + const statement = tsc.constVariable({ + comment: plugin.config.comments + ? createOperationComment({ operation }) + : undefined, + exportConst: symbolSwrMutationOptionsFn.exported, + expression: tsc.arrowFunction({ + parameters: [ + { + isRequired: false, + name: optionsParamName, + type: typeData, + }, + ], + statements: [ + tsc.returnStatement({ + expression: swrMutationOptionsObj, + }), + ], + }), + name: symbolSwrMutationOptionsFn.placeholder, + }); + + plugin.setSymbolValue(symbolSwrMutationOptionsFn, statement); +}; diff --git a/packages/openapi-ts/src/plugins/swr/swrOptions.ts b/packages/openapi-ts/src/plugins/swr/swrOptions.ts new file mode 100644 index 0000000000..70957c076d --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/swrOptions.ts @@ -0,0 +1,162 @@ +import type ts from 'typescript'; + +import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; +import { + createOperationComment, + hasOperationSse, + isOperationOptionsRequired, +} from '~/plugins/shared/utils/operation'; +import { tsc } from '~/tsc'; + +import { registerSwrKey } from './swrKey'; +import type { PluginInstance } from './types'; +import { useTypeData } from './useType'; + +const optionsParamName = 'options'; + +/** + * Create useSWR options for a given operation. + * + * This generates a function that returns an object with: + * - key: The SWR key (array or string) + * - fetcher: Async function that calls the SDK function + * + * Example output: + * export const getUserByIdOptions = (options: GetUserByIdOptions) => ({ + * key: getUserByIdKey(options), + * fetcher: async () => { + * const { data } = await getUserById({ + * ...options, + * throwOnError: true, + * }); + * return data; + * }, + * }); + */ +export const createSwrOptions = ({ + operation, + plugin, + sdkFn, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; + sdkFn: string; +}): void => { + if (hasOperationSse({ operation })) { + return; + } + + const isRequiredOptions = isOperationOptionsRequired({ + context: plugin.context, + operation, + }); + + // Register SWR key first + const symbolSwrKey = registerSwrKey({ operation, plugin }); + + const typeData = useTypeData({ operation, plugin }); + + // Create the SDK function call + const awaitSdkExpression = tsc.awaitExpression({ + expression: tsc.callExpression({ + functionName: sdkFn, + parameters: [ + tsc.objectExpression({ + multiLine: true, + obj: [ + { + spread: optionsParamName, + }, + { + key: 'throwOnError', + value: true, + }, + ], + }), + ], + }), + }); + + const statements: Array = []; + + if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { + statements.push( + tsc.returnVariable({ + expression: awaitSdkExpression, + }), + ); + } else { + statements.push( + tsc.constVariable({ + destructure: true, + expression: awaitSdkExpression, + name: 'data', + }), + tsc.returnVariable({ + expression: 'data', + }), + ); + } + + // Build the options object + const swrOptionsObj = tsc.objectExpression({ + obj: [ + { + key: 'key', + value: tsc.callExpression({ + functionName: symbolSwrKey.placeholder, + parameters: [optionsParamName], + }), + }, + { + key: 'fetcher', + value: tsc.arrowFunction({ + async: true, + multiLine: true, + statements, + }), + }, + ], + }); + + // Register the options symbol + const symbolSwrOptionsFn = plugin.registerSymbol({ + exported: plugin.config.swrOptions.exported, + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'swrOptions', + tool: plugin.name, + }, + name: buildName({ + config: plugin.config.swrOptions, + name: operation.id, + }), + }); + + const statement = tsc.constVariable({ + comment: plugin.config.comments + ? createOperationComment({ operation }) + : undefined, + exportConst: symbolSwrOptionsFn.exported, + expression: tsc.arrowFunction({ + parameters: [ + { + isRequired: isRequiredOptions, + name: optionsParamName, + type: typeData, + }, + ], + statements: [ + tsc.returnStatement({ + expression: swrOptionsObj, + }), + ], + }), + name: symbolSwrOptionsFn.placeholder, + }); + + plugin.setSymbolValue(symbolSwrOptionsFn, statement); +}; diff --git a/packages/openapi-ts/src/plugins/swr/types.d.ts b/packages/openapi-ts/src/plugins/swr/types.d.ts index ed557bdfa1..12aa335054 100644 --- a/packages/openapi-ts/src/plugins/swr/types.d.ts +++ b/packages/openapi-ts/src/plugins/swr/types.d.ts @@ -1,4 +1,3 @@ -import type { IR } from '~/ir/types'; import type { DefinePlugin, Plugin } from '~/plugins'; import type { StringCase, StringName } from '~/types/case'; @@ -13,11 +12,6 @@ export type UserConfig = Plugin.Name<'swr'> & /** * Add comments from SDK functions to the generated SWR code? * - * Duplicating comments this way is useful so you don't need to drill into - * the underlying SDK function to learn what it does or whether it's - * deprecated. You can set this option to `false` if you prefer less - * comment duplication. - * * @default true */ comments?: boolean; @@ -29,9 +23,7 @@ export type UserConfig = Plugin.Name<'swr'> & */ exportFromIndex?: boolean; /** - * Configuration for generated infinite query key helpers. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions infiniteQueryOptions} + * Configuration for generated useSWRInfinite options helpers. * * Can be: * - `boolean`: Shorthand for `{ enabled: boolean }` @@ -40,7 +32,7 @@ export type UserConfig = Plugin.Name<'swr'> & * * @default true */ - infiniteQueryKeys?: + swrInfiniteOptions?: | boolean | StringName | { @@ -51,93 +43,27 @@ export type UserConfig = Plugin.Name<'swr'> & */ case?: StringCase; /** - * Whether to generate infinite query key helpers. + * Whether to generate useSWRInfinite options helpers. * * @default true */ enabled?: boolean; /** - * Custom naming pattern for generated infinite query key names. The name variable is - * obtained from the SDK function name. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions infiniteQueryOptions} - * - * @default '{{name}}InfiniteQueryKey' - */ - name?: StringName; - /** - * Whether to include operation tags in infinite query keys. - * This will make query keys larger but provides better cache invalidation capabilities. - * - * @default false - */ - tags?: boolean; - }; - /** - * Configuration for generated infinite query options helpers. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions infiniteQueryOptions} - * - * Can be: - * - `boolean`: Shorthand for `{ enabled: boolean }` - * - `string` or `function`: Shorthand for `{ name: string | function }` - * - `object`: Full configuration object - * - * @default true - */ - infiniteQueryOptions?: - | boolean - | StringName - | { - /** - * The casing convention to use for generated names. - * - * @default 'camelCase' - */ - case?: StringCase; - /** - * Whether to generate infinite query options helpers. + * Whether to export generated symbols. * * @default true */ - enabled?: boolean; - /** - * Custom function to generate metadata for the operation. - * Can return any valid meta object that will be included in the generated infinite query options. - * - * @param operation - The operation object containing all available metadata - * @returns A meta object with any properties you want to include - * - * @example - * ```typescript - * meta: (operation) => ({ - * customField: operation.id, - * isDeprecated: operation.deprecated, - * tags: operation.tags, - * customObject: { - * method: operation.method, - * path: operation.path - * } - * }) - * ``` - * - * @default undefined - */ - meta?: (operation: IR.OperationObject) => Record; + exported?: boolean; /** - * Custom naming pattern for generated infinite query options names. The name variable is + * Custom naming pattern for generated useSWRInfinite options names. The name variable is * obtained from the SDK function name. * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions infiniteQueryOptions} - * - * @default '{{name}}InfiniteOptions' + * @default '{{name}}Infinite' */ name?: StringName; }; /** - * Configuration for generated mutation options helpers. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/useMutation useMutation} + * Configuration for generated SWR keys. * * Can be: * - `boolean`: Shorthand for `{ enabled: boolean }` @@ -146,7 +72,7 @@ export type UserConfig = Plugin.Name<'swr'> & * * @default true */ - mutationOptions?: + swrKeys?: | boolean | StringName | { @@ -157,48 +83,21 @@ export type UserConfig = Plugin.Name<'swr'> & */ case?: StringCase; /** - * Whether to generate mutation options helpers. + * Whether to generate SWR keys. * * @default true */ enabled?: boolean; /** - * Custom function to generate metadata for the operation. - * Can return any valid meta object that will be included in the generated mutation options. - * - * @param operation - The operation object containing all available metadata - * @returns A meta object with any properties you want to include - * - * @example - * ```typescript - * meta: (operation) => ({ - * customField: operation.id, - * isDeprecated: operation.deprecated, - * tags: operation.tags, - * customObject: { - * method: operation.method, - * path: operation.path - * } - * }) - * ``` - * - * @default undefined - */ - meta?: (operation: IR.OperationObject) => Record; - /** - * Custom naming pattern for generated mutation options names. The name variable is + * Custom naming pattern for generated SWR key names. The name variable is * obtained from the SDK function name. * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/useMutation useMutation} - * - * @default '{{name}}Mutation' + * @default '{{name}}Key' */ name?: StringName; }; /** - * Configuration for generated query keys. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryKey queryKey} + * Configuration for generated useSWRMutation options helpers. * * Can be: * - `boolean`: Shorthand for `{ enabled: boolean }` @@ -207,7 +106,7 @@ export type UserConfig = Plugin.Name<'swr'> & * * @default true */ - queryKeys?: + swrMutationOptions?: | boolean | StringName | { @@ -218,32 +117,27 @@ export type UserConfig = Plugin.Name<'swr'> & */ case?: StringCase; /** - * Whether to generate query keys. + * Whether to generate useSWRMutation options helpers. * * @default true */ enabled?: boolean; /** - * Custom naming pattern for generated query key names. The name variable is - * obtained from the SDK function name. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/guides/query-keys Query Keys} + * Whether to export generated symbols. * - * @default '{{name}}QueryKey' + * @default true */ - name?: StringName; + exported?: boolean; /** - * Whether to include operation tags in query keys. - * This will make query keys larger but provides better cache invalidation capabilities. + * Custom naming pattern for generated useSWRMutation options names. The name variable is + * obtained from the SDK function name. * - * @default false + * @default '{{name}}Mutation' */ - tags?: boolean; + name?: StringName; }; /** - * Configuration for generated query options helpers. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions queryOptions} + * Configuration for generated useSWR options helpers. * * Can be: * - `boolean`: Shorthand for `{ enabled: boolean }` @@ -252,7 +146,7 @@ export type UserConfig = Plugin.Name<'swr'> & * * @default true */ - queryOptions?: + swrOptions?: | boolean | StringName | { @@ -263,7 +157,7 @@ export type UserConfig = Plugin.Name<'swr'> & */ case?: StringCase; /** - * Whether to generate query options helpers. + * Whether to generate useSWR options helpers. * * @default true */ @@ -275,76 +169,13 @@ export type UserConfig = Plugin.Name<'swr'> & */ exported?: boolean; /** - * Custom function to generate metadata for the operation. - * Can return any valid meta object that will be included in the generated query options. - * - * @param operation - The operation object containing all available metadata - * @returns A meta object with any properties you want to include - * - * @example - * ```typescript - * meta: (operation) => ({ - * customField: operation.id, - * isDeprecated: operation.deprecated, - * tags: operation.tags, - * customObject: { - * method: operation.method, - * path: operation.path - * } - * }) - * ``` - * - * @default undefined - */ - meta?: (operation: IR.OperationObject) => Record; - /** - * Custom naming pattern for generated query options names. The name variable is + * Custom naming pattern for generated useSWR options names. The name variable is * obtained from the SDK function name. * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions queryOptions} - * * @default '{{name}}Options' */ name?: StringName; }; - /** - * Configuration for generated `useSwr()` function helpers. - * - * See {@link https://swr.vercel.app/docs/api API} - * - * Can be: - * - `boolean`: Shorthand for `{ enabled: boolean }` - * - `string` or `function`: Shorthand for `{ name: string | function }` - * - `object`: Full configuration object - * - * @default true - */ - useSwr?: - | boolean - | StringName - | { - /** - * The casing convention to use for generated names. - * - * @default 'camelCase' - */ - case?: StringCase; - /** - * Whether to generate `useSwr()` function helpers. - * - * @default true - */ - enabled?: boolean; - /** - * Custom naming pattern for generated `useSwr()` function names. The name variable is - * obtained from the SDK function name. - * - * See {@link https://swr.vercel.app/docs/api API} - * - * @default 'use{{name}}' - */ - name?: StringName; - }; }; export type Config = Plugin.Name<'swr'> & @@ -368,11 +199,9 @@ export type Config = Plugin.Name<'swr'> & */ exportFromIndex: boolean; /** - * Resolved configuration for generated infinite query key helpers. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions infiniteQueryOptions} + * Resolved configuration for generated useSWRInfinite options helpers. */ - infiniteQueryKeys: { + swrInfiniteOptions: { /** * The casing convention to use for generated names. * @@ -380,83 +209,28 @@ export type Config = Plugin.Name<'swr'> & */ case: StringCase; /** - * Whether to generate infinite query key helpers. + * Whether to generate useSWRInfinite options helpers. * * @default true */ enabled: boolean; /** - * Custom naming pattern for generated infinite query key names. The name variable is obtained from the SDK function name. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions infiniteQueryOptions} - * - * @default '{{name}}InfiniteQueryKey' - */ - name: StringName; - /** - * Whether to include operation tags in infinite query keys. - * This will make query keys larger but provides better cache invalidation capabilities. - * - * @default false - */ - tags: boolean; - }; - /** - * Resolved configuration for generated infinite query options helpers. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions infiniteQueryOptions} - */ - infiniteQueryOptions: { - /** - * The casing convention to use for generated names. - * - * @default 'camelCase' - */ - case: StringCase; - /** - * Whether to generate infinite query options helpers. + * Whether to export generated symbols. * * @default true */ - enabled: boolean; - /** - * Custom function to generate metadata for the operation. - * Can return any valid meta object that will be included in the generated infinite query options. - * - * @param operation - The operation object containing all available metadata - * @returns A meta object with any properties you want to include - * - * @example - * ```typescript - * meta: (operation) => ({ - * customField: operation.id, - * isDeprecated: operation.deprecated, - * tags: operation.tags, - * customObject: { - * method: operation.method, - * path: operation.path - * } - * }) - * ``` - * - * @default undefined - */ - meta: (operation: IR.OperationObject) => Record; + exported: boolean; /** - * Custom naming pattern for generated infinite query options names. The name variable is obtained from the SDK function name. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions infiniteQueryOptions} + * Custom naming pattern for generated useSWRInfinite options names. The name variable is obtained from the SDK function name. * - * @default '{{name}}InfiniteOptions' + * @default '{{name}}Infinite' */ name: StringName; }; /** - * Resolved configuration for generated mutation options helpers. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/useMutation useMutation} + * Resolved configuration for generated SWR keys. */ - mutationOptions: { + swrKeys: { /** * The casing convention to use for generated names. * @@ -464,49 +238,22 @@ export type Config = Plugin.Name<'swr'> & */ case: StringCase; /** - * Whether to generate mutation options helpers. + * Whether to generate SWR keys. * * @default true */ enabled: boolean; /** - * Custom function to generate metadata for the operation. - * Can return any valid meta object that will be included in the generated mutation options. - * - * @param operation - The operation object containing all available metadata - * @returns A meta object with any properties you want to include - * - * @example - * ```typescript - * meta: (operation) => ({ - * customField: operation.id, - * isDeprecated: operation.deprecated, - * tags: operation.tags, - * customObject: { - * method: operation.method, - * path: operation.path - * } - * }) - * ``` - * - * @default undefined - */ - meta: (operation: IR.OperationObject) => Record; - /** - * Custom naming pattern for generated mutation options names. The name variable is obtained from the SDK function name. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/useMutation useMutation} + * Custom naming pattern for generated SWR key names. The name variable is obtained from the SDK function name. * - * @default '{{name}}Mutation' + * @default '{{name}}Key' */ name: StringName; }; /** - * Resolved configuration for generated query keys. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/guides/query-keys Query Keys} + * Resolved configuration for generated useSWRMutation options helpers. */ - queryKeys: { + swrMutationOptions: { /** * The casing convention to use for generated names. * @@ -514,33 +261,28 @@ export type Config = Plugin.Name<'swr'> & */ case: StringCase; /** - * Whether to generate query keys. + * Whether to generate useSWRMutation options helpers. * * @default true */ enabled: boolean; /** - * Custom naming pattern for generated query key names. The name variable is obtained from the SDK function name. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/guides/query-keys Query Keys} + * Whether to export generated symbols. * - * @default '{{name}}QueryKey' + * @default true */ - name: StringName; + exported: boolean; /** - * Whether to include operation tags in query keys. - * This will make query keys larger but provides better cache invalidation capabilities. + * Custom naming pattern for generated useSWRMutation options names. The name variable is obtained from the SDK function name. * - * @default false + * @default '{{name}}Mutation' */ - tags: boolean; + name: StringName; }; /** - * Resolved configuration for generated query options helpers. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions queryOptions} + * Resolved configuration for generated useSWR options helpers. */ - queryOptions: { + swrOptions: { /** * The casing convention to use for generated names. * @@ -548,7 +290,7 @@ export type Config = Plugin.Name<'swr'> & */ case: StringCase; /** - * Whether to generate query options helpers. + * Whether to generate useSWR options helpers. * * @default true */ @@ -560,65 +302,15 @@ export type Config = Plugin.Name<'swr'> & */ exported: boolean; /** - * Custom function to generate metadata for the operation. - * Can return any valid meta object that will be included in the generated query options. - * - * @param operation - The operation object containing all available metadata - * @returns A meta object with any properties you want to include - * - * @example - * ```typescript - * meta: (operation) => ({ - * customField: operation.id, - * isDeprecated: operation.deprecated, - * tags: operation.tags, - * customObject: { - * method: operation.method, - * path: operation.path - * } - * }) - * ``` - * - * @default undefined - */ - meta: (operation: IR.OperationObject) => Record; - /** - * Custom naming pattern for generated query options names. The name variable is obtained from the SDK function name. - * - * See {@link https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions queryOptions} + * Custom naming pattern for generated useSWR options names. The name variable is obtained from the SDK function name. * * @default '{{name}}Options' */ name: StringName; }; - /** - * Configuration for generated `useSwr()` function helpers. - * - * See {@link https://swr.vercel.app/docs/api API} - */ - useSwr: { - /** - * The casing convention to use for generated names. - * - * @default 'camelCase' - */ - case: StringCase; - /** - * Whether to generate `useSwr()` function helpers. - * - * @default true - */ - enabled: boolean; - /** - * Custom naming pattern for generated `useSwr()` function names. The name variable is - * obtained from the SDK function name. - * - * See {@link https://swr.vercel.app/docs/api API} - * - * @default 'use{{name}}' - */ - name: StringName; - }; }; export type SwrPlugin = DefinePlugin; + +export type PluginHandler = SwrPlugin['Handler']; +export type PluginInstance = Plugin.Instance; diff --git a/packages/openapi-ts/src/plugins/swr/useType.ts b/packages/openapi-ts/src/plugins/swr/useType.ts new file mode 100644 index 0000000000..520a8397fc --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/useType.ts @@ -0,0 +1,63 @@ +import type { IR } from '~/ir/types'; +import { getClientPlugin } from '~/plugins/@hey-api/client-core/utils'; +import { operationOptionsType } from '~/plugins/@hey-api/sdk/shared/operation'; + +import type { PluginInstance } from './types'; + +export const useTypeData = ({ + operation, + plugin, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; +}): string => { + const pluginSdk = plugin.getPluginOrThrow('@hey-api/sdk'); + const typeData = operationOptionsType({ operation, plugin: pluginSdk }); + return typeData; +}; + +export const useTypeError = ({ + operation, + plugin, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; +}): string => { + const client = getClientPlugin(plugin.context.config); + + const symbolErrorType = plugin.querySymbol({ + category: 'type', + resource: 'operation', + resourceId: operation.id, + role: 'error', + }); + + let typeErrorName: string | undefined = symbolErrorType?.placeholder; + if (!typeErrorName) { + typeErrorName = 'Error'; + } + if (client.name === '@hey-api/client-axios') { + const symbol = plugin.referenceSymbol({ + category: 'external', + resource: 'axios.AxiosError', + }); + typeErrorName = `${symbol.placeholder}<${typeErrorName}>`; + } + return typeErrorName; +}; + +export const useTypeResponse = ({ + operation, + plugin, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; +}): string => { + const symbolResponseType = plugin.querySymbol({ + category: 'type', + resource: 'operation', + resourceId: operation.id, + role: 'response', + }); + return symbolResponseType?.placeholder || 'unknown'; +}; diff --git a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts deleted file mode 100644 index 730e2ebfb0..0000000000 --- a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { registryName } from '~/plugins/@hey-api/sdk/shared/class'; -import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation'; -import { stringCase } from '~/utils/stringCase'; - -import type { SwrPlugin } from '../types'; -import { createUseSwr } from './useSwr'; - -export const handlerV2: SwrPlugin['Handler'] = ({ plugin }) => { - plugin.registerSymbol({ - external: 'swr', - importKind: 'default', - kind: 'function', - meta: { - category: 'external', - resource: 'swr', - }, - name: 'useSWR', - }); - - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - - plugin.forEach( - 'operation', - ({ operation }) => { - const classes = sdkPlugin.config.asClass - ? operationClasses({ - context: plugin.context, - operation, - plugin: sdkPlugin, - }) - : undefined; - const entry = classes ? classes.values().next().value : undefined; - // TODO: this should use class graph to determine correct path string - // as it's really easy to break once we change the class casing - let queryFn: string; - if (entry) { - const symbolClass = plugin.referenceSymbol({ - category: 'utility', - resource: 'class', - resourceId: entry.path[0], - tool: 'sdk', - }); - queryFn = [ - symbolClass.placeholder, - ...(sdkPlugin.config.instance ? [registryName, 'get()'] : []), - ...entry.path.slice(1).map((className) => - stringCase({ - case: 'camelCase', - value: className, - }), - ), - entry.methodName, - ] - .filter(Boolean) - .join('.'); - } else { - queryFn = plugin.referenceSymbol({ - category: 'sdk', - resource: 'operation', - resourceId: operation.id, - }).placeholder; - } - - if (plugin.hooks.operation.isQuery(operation)) { - // if (plugin.config.queryOptions.enabled) { - // createQueryOptions({ operation, plugin, queryFn }); - // } - - // if (plugin.config.infiniteQueryOptions.enabled) { - // createInfiniteQueryOptions({ operation, plugin, queryFn }); - // } - - if (plugin.config.useSwr.enabled) { - createUseSwr({ operation, plugin, queryFn }); - } - } - }, - { - order: 'declarations', - }, - ); -}; diff --git a/packages/openapi-ts/src/plugins/swr/v2/useSwr.ts b/packages/openapi-ts/src/plugins/swr/v2/useSwr.ts deleted file mode 100644 index f666038552..0000000000 --- a/packages/openapi-ts/src/plugins/swr/v2/useSwr.ts +++ /dev/null @@ -1,70 +0,0 @@ -import type { IR } from '~/ir/types'; -import { buildName } from '~/openApi/shared/utils/name'; -import { - createOperationComment, - hasOperationSse, -} from '~/plugins/shared/utils/operation'; -import type { TsDsl } from '~/ts-dsl'; -import { $ } from '~/ts-dsl'; - -import type { SwrPlugin } from '../types'; - -export const createUseSwr = ({ - operation, - plugin, - queryFn, -}: { - operation: IR.OperationObject; - plugin: SwrPlugin['Instance']; - queryFn: string; -}): void => { - if (hasOperationSse({ operation })) { - return; - } - - const symbolUseSwr = plugin.referenceSymbol({ - category: 'external', - resource: 'swr', - }); - const symbolUseQueryFn = plugin.registerSymbol({ - exported: true, - name: buildName({ - config: plugin.config.useSwr, - name: operation.id, - }), - }); - - const awaitSdkFn = $(queryFn) - .call($.object().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 statement = $.const(symbolUseQueryFn.placeholder) - .export(symbolUseQueryFn.exported) - .$if( - plugin.config.comments && createOperationComment({ operation }), - (c, v) => c.describe(v as ReadonlyArray), - ) - .assign( - $.func().do( - $(symbolUseSwr.placeholder) - .call( - $.literal(operation.path), - $.func() - .async() - .do(...statements), - ) - .return(), - ), - ); - plugin.setSymbolValue(symbolUseQueryFn, statement); -}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5222aee29c..cd3bce4825 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -911,6 +911,76 @@ importers: specifier: 3.0.8 version: 3.0.8(typescript@5.8.3) + examples/openapi-ts-swr: + dependencies: + '@radix-ui/react-form': + specifier: 0.1.1 + version: 0.1.1(@types/react-dom@19.0.1)(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + '@radix-ui/react-icons': + specifier: 1.3.2 + version: 1.3.2(react@19.0.0) + '@radix-ui/themes': + specifier: 3.1.6 + version: 3.1.6(@types/react-dom@19.0.1)(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + react: + specifier: 19.0.0 + version: 19.0.0 + react-dom: + specifier: 19.0.0 + version: 19.0.0(react@19.0.0) + swr: + specifier: 2.3.2 + version: 2.3.2(react@19.0.0) + devDependencies: + '@config/vite-base': + specifier: workspace:* + version: link:../../packages/config-vite-base + '@hey-api/openapi-ts': + specifier: workspace:* + version: link:../../packages/openapi-ts + '@types/react': + specifier: 19.0.1 + version: 19.0.1 + '@types/react-dom': + specifier: 19.0.1 + version: 19.0.1 + '@typescript-eslint/eslint-plugin': + specifier: 8.29.1 + version: 8.29.1(@typescript-eslint/parser@8.29.1(eslint@9.17.0(jiti@2.6.1))(typescript@5.8.3))(eslint@9.17.0(jiti@2.6.1))(typescript@5.8.3) + '@typescript-eslint/parser': + specifier: 8.29.1 + version: 8.29.1(eslint@9.17.0(jiti@2.6.1))(typescript@5.8.3) + '@vitejs/plugin-react': + specifier: 4.4.0-beta.1 + version: 4.4.0-beta.1(vite@7.1.2(@types/node@22.10.5)(jiti@2.6.1)(less@4.2.2)(sass@1.85.0)(terser@5.43.1)(yaml@2.8.1)) + autoprefixer: + specifier: 10.4.19 + version: 10.4.19(postcss@8.4.41) + eslint: + specifier: 9.17.0 + version: 9.17.0(jiti@2.6.1) + eslint-plugin-react-hooks: + specifier: 5.2.0 + version: 5.2.0(eslint@9.17.0(jiti@2.6.1)) + eslint-plugin-react-refresh: + specifier: 0.4.7 + version: 0.4.7(eslint@9.17.0(jiti@2.6.1)) + postcss: + specifier: 8.4.41 + version: 8.4.41 + prettier: + specifier: 3.4.2 + version: 3.4.2 + tailwindcss: + specifier: 3.4.9 + version: 3.4.9(ts-node@10.9.2(@types/node@22.10.5)(typescript@5.8.3)) + typescript: + specifier: 5.8.3 + version: 5.8.3 + vite: + specifier: 7.1.2 + version: 7.1.2(@types/node@22.10.5)(jiti@2.6.1)(less@4.2.2)(sass@1.85.0)(terser@5.43.1)(yaml@2.8.1) + examples/openapi-ts-tanstack-angular-query-experimental: dependencies: '@angular/animations': @@ -12681,6 +12751,11 @@ packages: engines: {node: '>=16'} hasBin: true + swr@2.3.2: + resolution: {integrity: sha512-RosxFpiabojs75IwQ316DGoDRmOqtiAj0tg8wCcbEu4CiLZBs/a9QNtHV7TUfDXmmlgqij/NqzKq/eLelyv9xA==} + peerDependencies: + react: ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 + swr@2.3.6: resolution: {integrity: sha512-wfHRmHWk/isGNMwlLGlZX5Gzz/uTgo0o2IRuTMcf4CPuPFJZlq0rDaKUx+ozB5nBOReNV1kiOyzMfj+MBMikLw==} peerDependencies: @@ -28535,6 +28610,12 @@ snapshots: picocolors: 1.1.1 sax: 1.4.1 + swr@2.3.2(react@19.0.0): + dependencies: + dequal: 2.0.3 + react: 19.0.0 + use-sync-external-store: 1.5.0(react@19.0.0) + swr@2.3.6(react@19.0.0): dependencies: dequal: 2.0.3 From d9a7967ed83a8245b040181fb5a6fd6a787e2290 Mon Sep 17 00:00:00 2001 From: Nemo Date: Mon, 10 Nov 2025 17:14:16 +0900 Subject: [PATCH 2/9] fix: lint --- examples/openapi-ts-swr/src/main.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/openapi-ts-swr/src/main.tsx b/examples/openapi-ts-swr/src/main.tsx index dbdf7dfe44..8c2717dabb 100644 --- a/examples/openapi-ts-swr/src/main.tsx +++ b/examples/openapi-ts-swr/src/main.tsx @@ -22,10 +22,9 @@ ReactDOM.createRoot(document.getElementById('root')!).render( From 34db7a003c5e78e499a8b49a5bee94c76a49000d Mon Sep 17 00:00:00 2001 From: Pewww Date: Mon, 10 Nov 2025 18:02:05 +0900 Subject: [PATCH 3/9] fix: update snapshot tests --- .../src/client/client/client.gen.ts | 1 + examples/openapi-ts-fastify/src/handlers.ts | 1 + .../2.0.x/plugins/swr/asClass/client.gen.ts | 16 + .../plugins/swr/asClass/client/client.gen.ts | 268 +++ .../2.0.x/plugins/swr/asClass/client/index.ts | 25 + .../plugins/swr/asClass/client/types.gen.ts | 241 ++ .../plugins/swr/asClass/client/utils.gen.ts | 332 +++ .../plugins/swr/asClass/core/auth.gen.ts | 42 + .../swr/asClass/core/bodySerializer.gen.ts | 100 + .../plugins/swr/asClass/core/params.gen.ts | 176 ++ .../swr/asClass/core/pathSerializer.gen.ts | 181 ++ .../asClass/core/queryKeySerializer.gen.ts | 136 ++ .../swr/asClass/core/serverSentEvents.gen.ts | 264 +++ .../plugins/swr/asClass/core/types.gen.ts | 118 + .../plugins/swr/asClass/core/utils.gen.ts | 143 ++ .../2.0.x/plugins/swr/asClass/index.ts | 4 + .../2.0.x/plugins/swr/asClass/sdk.gen.ts | 75 + .../2.0.x/plugins/swr/asClass/swr.gen.ts | 126 + .../2.0.x/plugins/swr/asClass/types.gen.ts | 101 + .../2.0.x/plugins/swr/axios/client.gen.ts | 18 + .../plugins/swr/axios/client/client.gen.ts | 163 ++ .../2.0.x/plugins/swr/axios/client/index.ts | 23 + .../plugins/swr/axios/client/types.gen.ts | 197 ++ .../plugins/swr/axios/client/utils.gen.ts | 213 ++ .../2.0.x/plugins/swr/axios/core/auth.gen.ts | 42 + .../swr/axios/core/bodySerializer.gen.ts | 100 + .../plugins/swr/axios/core/params.gen.ts | 176 ++ .../swr/axios/core/pathSerializer.gen.ts | 181 ++ .../swr/axios/core/queryKeySerializer.gen.ts | 136 ++ .../swr/axios/core/serverSentEvents.gen.ts | 264 +++ .../2.0.x/plugins/swr/axios/core/types.gen.ts | 118 + .../2.0.x/plugins/swr/axios/core/utils.gen.ts | 143 ++ .../2.0.x/plugins/swr/axios/index.ts | 4 + .../2.0.x/plugins/swr/axios/sdk.gen.ts | 347 +++ .../2.0.x/plugins/swr/axios/swr.gen.ts | 677 ++++++ .../2.0.x/plugins/swr/axios/types.gen.ts | 1188 ++++++++++ .../2.0.x/plugins/swr/fetch/client.gen.ts | 18 + .../plugins/swr/fetch/client/client.gen.ts | 268 +++ .../2.0.x/plugins/swr/fetch/client/index.ts | 25 + .../plugins/swr/fetch/client/types.gen.ts | 241 ++ .../plugins/swr/fetch/client/utils.gen.ts | 332 +++ .../2.0.x/plugins/swr/fetch/core/auth.gen.ts | 42 + .../swr/fetch/core/bodySerializer.gen.ts | 100 + .../plugins/swr/fetch/core/params.gen.ts | 176 ++ .../swr/fetch/core/pathSerializer.gen.ts | 181 ++ .../swr/fetch/core/queryKeySerializer.gen.ts | 136 ++ .../swr/fetch/core/serverSentEvents.gen.ts | 264 +++ .../2.0.x/plugins/swr/fetch/core/types.gen.ts | 118 + .../2.0.x/plugins/swr/fetch/core/utils.gen.ts | 143 ++ .../2.0.x/plugins/swr/fetch/index.ts | 4 + .../2.0.x/plugins/swr/fetch/sdk.gen.ts | 335 +++ .../2.0.x/plugins/swr/fetch/swr.gen.ts | 677 ++++++ .../2.0.x/plugins/swr/fetch/types.gen.ts | 1188 ++++++++++ .../3.0.x/plugins/swr/asClass/client.gen.ts | 16 + .../plugins/swr/asClass/client/client.gen.ts | 268 +++ .../3.0.x/plugins/swr/asClass/client/index.ts | 25 + .../plugins/swr/asClass/client/types.gen.ts | 241 ++ .../plugins/swr/asClass/client/utils.gen.ts | 332 +++ .../plugins/swr/asClass/core/auth.gen.ts | 42 + .../swr/asClass/core/bodySerializer.gen.ts | 100 + .../plugins/swr/asClass/core/params.gen.ts | 176 ++ .../swr/asClass/core/pathSerializer.gen.ts | 181 ++ .../asClass/core/queryKeySerializer.gen.ts | 136 ++ .../swr/asClass/core/serverSentEvents.gen.ts | 264 +++ .../plugins/swr/asClass/core/types.gen.ts | 118 + .../plugins/swr/asClass/core/utils.gen.ts | 143 ++ .../3.0.x/plugins/swr/asClass/index.ts | 4 + .../3.0.x/plugins/swr/asClass/sdk.gen.ts | 75 + .../3.0.x/plugins/swr/asClass/swr.gen.ts | 126 + .../3.0.x/plugins/swr/asClass/types.gen.ts | 101 + .../3.0.x/plugins/swr/axios/client.gen.ts | 18 + .../plugins/swr/axios/client/client.gen.ts | 163 ++ .../3.0.x/plugins/swr/axios/client/index.ts | 23 + .../plugins/swr/axios/client/types.gen.ts | 197 ++ .../plugins/swr/axios/client/utils.gen.ts | 213 ++ .../3.0.x/plugins/swr/axios/core/auth.gen.ts | 42 + .../swr/axios/core/bodySerializer.gen.ts | 100 + .../plugins/swr/axios/core/params.gen.ts | 176 ++ .../swr/axios/core/pathSerializer.gen.ts | 181 ++ .../swr/axios/core/queryKeySerializer.gen.ts | 136 ++ .../swr/axios/core/serverSentEvents.gen.ts | 264 +++ .../3.0.x/plugins/swr/axios/core/types.gen.ts | 118 + .../3.0.x/plugins/swr/axios/core/utils.gen.ts | 143 ++ .../3.0.x/plugins/swr/axios/index.ts | 4 + .../3.0.x/plugins/swr/axios/sdk.gen.ts | 432 ++++ .../3.0.x/plugins/swr/axios/swr.gen.ts | 999 ++++++++ .../3.0.x/plugins/swr/axios/types.gen.ts | 2072 ++++++++++++++++ .../3.0.x/plugins/swr/fetch/client.gen.ts | 18 + .../plugins/swr/fetch/client/client.gen.ts | 268 +++ .../3.0.x/plugins/swr/fetch/client/index.ts | 25 + .../plugins/swr/fetch/client/types.gen.ts | 241 ++ .../plugins/swr/fetch/client/utils.gen.ts | 332 +++ .../3.0.x/plugins/swr/fetch/core/auth.gen.ts | 42 + .../swr/fetch/core/bodySerializer.gen.ts | 100 + .../plugins/swr/fetch/core/params.gen.ts | 176 ++ .../swr/fetch/core/pathSerializer.gen.ts | 181 ++ .../swr/fetch/core/queryKeySerializer.gen.ts | 136 ++ .../swr/fetch/core/serverSentEvents.gen.ts | 264 +++ .../3.0.x/plugins/swr/fetch/core/types.gen.ts | 118 + .../3.0.x/plugins/swr/fetch/core/utils.gen.ts | 143 ++ .../3.0.x/plugins/swr/fetch/index.ts | 4 + .../3.0.x/plugins/swr/fetch/sdk.gen.ts | 418 ++++ .../3.0.x/plugins/swr/fetch/swr.gen.ts | 999 ++++++++ .../3.0.x/plugins/swr/fetch/types.gen.ts | 2072 ++++++++++++++++ .../3.1.x/plugins/swr/asClass/client.gen.ts | 16 + .../plugins/swr/asClass/client/client.gen.ts | 268 +++ .../3.1.x/plugins/swr/asClass/client/index.ts | 25 + .../plugins/swr/asClass/client/types.gen.ts | 241 ++ .../plugins/swr/asClass/client/utils.gen.ts | 332 +++ .../plugins/swr/asClass/core/auth.gen.ts | 42 + .../swr/asClass/core/bodySerializer.gen.ts | 100 + .../plugins/swr/asClass/core/params.gen.ts | 176 ++ .../swr/asClass/core/pathSerializer.gen.ts | 181 ++ .../asClass/core/queryKeySerializer.gen.ts | 136 ++ .../swr/asClass/core/serverSentEvents.gen.ts | 264 +++ .../plugins/swr/asClass/core/types.gen.ts | 118 + .../plugins/swr/asClass/core/utils.gen.ts | 143 ++ .../3.1.x/plugins/swr/asClass/index.ts | 4 + .../3.1.x/plugins/swr/asClass/sdk.gen.ts | 75 + .../3.1.x/plugins/swr/asClass/swr.gen.ts | 126 + .../3.1.x/plugins/swr/asClass/types.gen.ts | 101 + .../3.1.x/plugins/swr/axios/client.gen.ts | 18 + .../plugins/swr/axios/client/client.gen.ts | 163 ++ .../3.1.x/plugins/swr/axios/client/index.ts | 23 + .../plugins/swr/axios/client/types.gen.ts | 197 ++ .../plugins/swr/axios/client/utils.gen.ts | 213 ++ .../3.1.x/plugins/swr/axios/core/auth.gen.ts | 42 + .../swr/axios/core/bodySerializer.gen.ts | 100 + .../plugins/swr/axios/core/params.gen.ts | 176 ++ .../swr/axios/core/pathSerializer.gen.ts | 181 ++ .../swr/axios/core/queryKeySerializer.gen.ts | 136 ++ .../swr/axios/core/serverSentEvents.gen.ts | 264 +++ .../3.1.x/plugins/swr/axios/core/types.gen.ts | 118 + .../3.1.x/plugins/swr/axios/core/utils.gen.ts | 143 ++ .../3.1.x/plugins/swr/axios/index.ts | 4 + .../3.1.x/plugins/swr/axios/sdk.gen.ts | 432 ++++ .../3.1.x/plugins/swr/axios/swr.gen.ts | 999 ++++++++ .../3.1.x/plugins/swr/axios/types.gen.ts | 2091 +++++++++++++++++ .../3.1.x/plugins/swr/fetch/client.gen.ts | 18 + .../plugins/swr/fetch/client/client.gen.ts | 268 +++ .../3.1.x/plugins/swr/fetch/client/index.ts | 25 + .../plugins/swr/fetch/client/types.gen.ts | 241 ++ .../plugins/swr/fetch/client/utils.gen.ts | 332 +++ .../3.1.x/plugins/swr/fetch/core/auth.gen.ts | 42 + .../swr/fetch/core/bodySerializer.gen.ts | 100 + .../plugins/swr/fetch/core/params.gen.ts | 176 ++ .../swr/fetch/core/pathSerializer.gen.ts | 181 ++ .../swr/fetch/core/queryKeySerializer.gen.ts | 136 ++ .../swr/fetch/core/serverSentEvents.gen.ts | 264 +++ .../3.1.x/plugins/swr/fetch/core/types.gen.ts | 118 + .../3.1.x/plugins/swr/fetch/core/utils.gen.ts | 143 ++ .../3.1.x/plugins/swr/fetch/index.ts | 4 + .../3.1.x/plugins/swr/fetch/sdk.gen.ts | 418 ++++ .../3.1.x/plugins/swr/fetch/swr.gen.ts | 999 ++++++++ .../3.1.x/plugins/swr/fetch/types.gen.ts | 2091 +++++++++++++++++ .../@hey-api/client-axios/bundle/client.ts | 1 + .../__tests__/serverSentEvents.test.ts | 1 + 157 files changed, 36960 insertions(+) create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/client.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/auth.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/bodySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/params.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/pathSerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/serverSentEvents.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/types.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/utils.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/index.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/sdk.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/types.gen.ts diff --git a/examples/openapi-ts-axios/src/client/client/client.gen.ts b/examples/openapi-ts-axios/src/client/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/examples/openapi-ts-axios/src/client/client/client.gen.ts +++ b/examples/openapi-ts-axios/src/client/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/examples/openapi-ts-fastify/src/handlers.ts b/examples/openapi-ts-fastify/src/handlers.ts index c4d94692ad..baad0a9a22 100644 --- a/examples/openapi-ts-fastify/src/handlers.ts +++ b/examples/openapi-ts-fastify/src/handlers.ts @@ -4,6 +4,7 @@ export const serviceHandlers: RouteHandlers = { createPets(request, reply) { reply.code(201).send(); }, + listPets(request, reply) { reply.code(200).send([]); }, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client.gen.ts new file mode 100644 index 0000000000..cab3c70195 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig()); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/client.gen.ts new file mode 100644 index 0000000000..a439d2748f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/client.gen.ts @@ -0,0 +1,268 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { + Client, + Config, + RequestOptions, + ResolvedRequestOptions, +} from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors< + Request, + Response, + unknown, + ResolvedRequestOptions + >(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body); + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response = await _fetch(request); + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if ( + response.status === 204 || + response.headers.get('Content-Length') === '0' + ) { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'json': + case 'text': + data = await response[parseAs](); + break; + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = + (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = + (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/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/swr/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/types.gen.ts new file mode 100644 index 0000000000..b4a499cc03 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/types.gen.ts @@ -0,0 +1,241 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { + Client as CoreClient, + Config as CoreConfig, +} from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: + | 'arrayBuffer' + | 'auto' + | 'blob' + | 'formData' + | 'json' + | 'stream' + | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record + ? TData[keyof TData] + : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? + | (TData extends Record + ? TData[keyof TData] + : TData) + | undefined + : ( + | { + data: TData extends Record + ? TData[keyof TData] + : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick< + Required>, + 'method' + >, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/utils.gen.ts new file mode 100644 index 0000000000..4c48a9ee11 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/utils.gen.ts @@ -0,0 +1,332 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = ( + contentType: string | null, +): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if ( + cleanContent.startsWith('application/json') || + cleanContent.endsWith('+json') + ) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => + cleanContent.startsWith(type), + ) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = + header instanceof Headers + ? headersEntries(header) + : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e. their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = ( + request: Req, + options: Options, +) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update( + id: number | Interceptor, + fn: Interceptor, + ): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/asClass/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/sdk.gen.ts new file mode 100644 index 0000000000..fdfe39f104 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/sdk.gen.ts @@ -0,0 +1,75 @@ +// 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 { FooBarPostData, FooBarPostResponses, FooBarPutData, FooBarPutResponses, FooPostData, FooPostResponses, FooPutData, FooPutResponses, GetFooBarData, GetFooBarResponses, GetFooData, GetFooResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export class BarService { + public static post(options?: Options) { + return (options?.client ?? client).post({ + url: '/foo/bar', + ...options + }); + } + + public static put(options?: Options) { + return (options?.client ?? client).put({ + url: '/foo/bar', + ...options + }); + } +} + +export class FooService { + public static post(options?: Options) { + return (options?.client ?? client).post({ + url: '/foo', + ...options + }); + } + + public static put(options?: Options) { + return (options?.client ?? client).put({ + url: '/foo', + ...options + }); + } + + static barService = BarService; +} + +export class FooBazService { + public static getFoo(options?: Options) { + return (options?.client ?? client).get({ + url: '/foo', + ...options + }); + } + + static fooService = FooService; +} + +export class BarBazService { + public static getFooBar(options?: Options) { + return (options?.client ?? client).get({ + url: '/foo/bar', + ...options + }); + } + + static fooService = FooService; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts new file mode 100644 index 0000000000..586defdb49 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts @@ -0,0 +1,126 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { BarBazService, FooBazService, type Options } from './sdk.gen'; +import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarData, GetFooData } from './types.gen'; + +export const getFooKey = (options?: Options) => { + const key: any[] = [ + '/foo' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getFooOptions = (options?: Options) => { + return { + key: getFooKey(options), + fetcher: async () => { + const { data } = await FooBazService.getFoo({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooPostMutation = (options?: Options) => { + return { + key: '/foo', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooPutMutation = (options?: Options) => { + return { + key: '/foo', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getFooBarKey = (options?: Options) => { + const key: any[] = [ + '/foo/bar' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getFooBarOptions = (options?: Options) => { + return { + key: getFooBarKey(options), + fetcher: async () => { + const { data } = await BarBazService.getFooBar({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooBarPostMutation = (options?: Options) => { + return { + key: '/foo/bar', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooBarPutMutation = (options?: Options) => { + return { + key: '/foo/bar', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/types.gen.ts new file mode 100644 index 0000000000..9844839dee --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/types.gen.ts @@ -0,0 +1,101 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: string; +}; + +export type GetFooData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type GetFooResponses = { + /** + * OK + */ + 200: string; +}; + +export type GetFooResponse = GetFooResponses[keyof GetFooResponses]; + +export type FooPostData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type FooPostResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooPostResponse = FooPostResponses[keyof FooPostResponses]; + +export type FooPutData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type FooPutResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooPutResponse = FooPutResponses[keyof FooPutResponses]; + +export type GetFooBarData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type GetFooBarResponses = { + /** + * OK + */ + 200: string; +}; + +export type GetFooBarResponse = GetFooBarResponses[keyof GetFooBarResponses]; + +export type FooBarPostData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type FooBarPostResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooBarPostResponse = FooBarPostResponses[keyof FooBarPostResponses]; + +export type FooBarPutData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type FooBarPutResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooBarPutResponse = FooBarPutResponses[keyof FooBarPutResponses]; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client.gen.ts new file mode 100644 index 0000000000..27214c60f4 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client.gen.ts @@ -0,0 +1,18 @@ +// 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/swr/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/client.gen.ts new file mode 100644 index 0000000000..f81a9e7863 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/client.gen.ts @@ -0,0 +1,163 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + let instance: AxiosInstance; + + if (_config.axios && !('Axios' in _config.axios)) { + instance = _config.axios; + } else { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { auth, ...configWithoutAuth } = _config; + instance = axios.create(configWithoutAuth); + } + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + instance.defaults = { + ...instance.defaults, + ..._config, + // @ts-expect-error + headers: mergeHeaders(instance.defaults.headers, _config.headers), + }; + return getConfig(); + }; + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + axios: options.axios ?? _config.axios ?? instance, + headers: mergeHeaders(_config.headers, options.headers), + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.body = opts.bodySerializer(opts.body); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + // @ts-expect-error + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + try { + // assign Axios here for consistency with fetch + const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { auth, ...optsWithoutAuth } = opts; + const response = await _axios({ + ...optsWithoutAuth, + baseURL: '', // the baseURL is already included in `url` + data: getValidRequestBody(opts), + headers: opts.headers as RawAxiosRequestHeaders, + // let `paramsSerializer()` handle query params if it exists + params: opts.paramsSerializer ? opts.query : undefined, + url, + }); + + let { data } = response; + + if (opts.responseType === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return { + ...response, + data: data ?? {}, + }; + } catch (error) { + const e = error as AxiosError; + if (opts.throwOnError) { + throw e; + } + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; + } + }; + + 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 Record, + method, + // @ts-expect-error + signal: opts.signal, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + instance, + 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/swr/axios/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/index.ts new file mode 100644 index 0000000000..7bd7b98807 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/index.ts @@ -0,0 +1,23 @@ +// 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, + TDataShape, +} from './types.gen'; +export { createConfig } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/types.gen.ts new file mode 100644 index 0000000000..59be50cc30 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/types.gen.ts @@ -0,0 +1,197 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + AxiosError, + AxiosInstance, + AxiosRequestHeaders, + AxiosResponse, + AxiosStatic, + CreateAxiosDefaults, +} from 'axios'; + +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'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Axios implementation. You can use this option to provide either an + * `AxiosStatic` or an `AxiosInstance`. + * + * @default axios + */ + axios?: AxiosStatic | AxiosInstance; + /** + * Base URL for all requests made by this client. + */ + baseURL?: T['baseURL']; + /** + * 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?: + | AxiosRequestHeaders + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ClientOptions { + baseURL?: string; + throwOnError?: boolean; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, +> = ThrowOnError extends true + ? Promise< + AxiosResponse< + TData extends Record ? TData[keyof TData] : TData + > + > + : Promise< + | (AxiosResponse< + TData extends Record ? TData[keyof TData] : TData + > & { error: undefined }) + | (AxiosError< + TError extends Record ? TError[keyof TError] : TError + > & { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + }) + >; + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + 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< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + instance: AxiosInstance; +}; + +/** + * 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, +> = 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/swr/axios/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/utils.gen.ts new file mode 100644 index 0000000000..723c477c05 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/utils.gen.ts @@ -0,0 +1,213 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } 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; +}; + +const checkForExistence = ( + options: Pick & { + headers: Record; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if (name in options.headers || options.query?.[name]) { + return true; + } + if ( + 'Cookie' in options.headers && + options.headers['Cookie'] && + typeof options.headers['Cookie'] === 'string' + ) { + return options.headers['Cookie'].includes(`${name}=`); + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Record; + }) => { + 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': { + const value = `${name}=${token}`; + if ('Cookie' in options.headers && options.headers['Cookie']) { + options.headers['Cookie'] = `${options.headers['Cookie']}; ${value}`; + } else { + options.headers['Cookie'] = value; + } + break; + } + case 'header': + default: + options.headers[name] = token; + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => { + const instanceBaseUrl = options.axios?.defaults?.baseURL; + + const baseUrl = + !!options.baseURL && typeof options.baseURL === 'string' + ? options.baseURL + : instanceBaseUrl; + + return getUrl({ + baseUrl: baseUrl as string, + path: options.path, + // let `paramsSerializer()` handle query params if it exists + query: !options.paramsSerializer ? options.query : undefined, + 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 }; + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +/** + * Special Axios headers keywords allowing to set headers by request method. + */ +export const axiosHeadersKeywords = [ + 'common', + 'delete', + 'get', + 'head', + 'patch', + 'post', + 'put', +] as const; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Record => { + const mergedHeaders: Record = {}; + for (const header of headers) { + if (!header || typeof header !== 'object') { + continue; + } + + const iterator = Object.entries(header); + + for (const [key, value] of iterator) { + if ( + axiosHeadersKeywords.includes( + key as (typeof axiosHeadersKeywords)[number], + ) && + typeof value === 'object' + ) { + mergedHeaders[key] = { + ...(mergedHeaders[key] as Record), + ...value, + }; + } else if (value === null) { + delete mergedHeaders[key]; + } else if (Array.isArray(value)) { + for (const v of value) { + // @ts-expect-error + mergedHeaders[key] = [...(mergedHeaders[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[key] = + typeof value === 'object' ? JSON.stringify(value) : (value as string); + } + } + } + return mergedHeaders; +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/axios/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/sdk.gen.ts new file mode 100644 index 0000000000..239a23814a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/sdk.gen.ts @@ -0,0 +1,347 @@ +// 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) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const patchApiVbyApiVersionNoTag = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const fooWow = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const getCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const headCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).head({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).options({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const patchCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const postCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const putCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const callWithDescriptions = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/descriptions/', + ...options + }); +}; + +export const callWithParameters = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options + }); +}; + +export const callWithWeirdParameterNames = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + querySerializer: { + parameters: { + parameterModel: { + object: { + explode: false, + style: 'form' + } + } + } + }, + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callWithDefaultOptionalParameters = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callToTestOrderOfParams = (options: Options) => { + return (options.client ?? client).put({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const duplicateName = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName2 = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName3 = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName4 = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const callWithNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/no-content', + ...options + }); +}; + +export const callWithResponseAndNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/multiple-tags/response-and-no-content', + ...options + }); +}; + +export const dummyA = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/multiple-tags/a', + ...options + }); +}; + +export const dummyB = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/multiple-tags/b', + ...options + }); +}; + +export const callWithResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithDuplicateResponses = (options?: Options) => { + return (options?.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithResponses = (options?: Options) => { + return (options?.client ?? client).put({ + responseType: 'json', + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const collectionFormat = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + querySerializer: { + parameters: { + parameterArray: { + array: { + explode: false + } + }, + parameterDictionary: { + object: { + explode: false, + style: 'form' + } + } + } + }, + responseType: 'json', + url: '/api/v{api-version}/types', + ...options + }); +}; + +export const complexTypes = (options: Options) => { + return (options.client ?? client).get({ + querySerializer: { + parameters: { + parameterObject: { + object: { + explode: false, + style: 'form' + } + }, + parameterReference: { + object: { + explode: false, + style: 'form' + } + } + } + }, + responseType: 'json', + url: '/api/v{api-version}/complex', + ...options + }); +}; + +export const callWithResultFromHeader = (options?: Options) => { + return (options?.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/header', + ...options + }); +}; + +export const testErrorCode = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/error', + ...options + }); +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options + }); +}; + +/** + * Body should not be unknown + * + * Body should not be unknown + */ +export const postApiVbyApiVersionBody = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + 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/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts new file mode 100644 index 0000000000..e36cf187f8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts @@ -0,0 +1,677 @@ +// This file is auto-generated by @hey-api/openapi-ts + +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, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from './types.gen'; + +export const serviceWithEmptyTagKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no+tag' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const serviceWithEmptyTagOptions = (options?: Options) => { + return { + key: serviceWithEmptyTagKey(options), + fetcher: async () => { + const { data } = await serviceWithEmptyTag({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooWowMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { + return { + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDescriptionsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/descriptions/', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameterPath}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultParametersKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/defaults' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithDefaultParametersOptions = (options: Options) => { + return { + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callToTestOrderOfParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateNameMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName2Key = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/duplicate' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const duplicateName2Options = (options?: Options) => { + return { + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName3Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName4Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithNoContentResponseOptions = (options?: Options) => { + return { + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/response-and-no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { + return { + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyAKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/a' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyAOptions = (options?: Options) => { + return { + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyBKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/b' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyBOptions = (options?: Options) => { + return { + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/response' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseOptions = (options?: Options) => { + return { + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDuplicateResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const collectionFormatKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/collectionFormat' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const collectionFormatOptions = (options: Options) => { + return { + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const typesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/types' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const typesOptions = (options: Options) => { + return { + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexTypesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/complex' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const complexTypesOptions = (options: Options) => { + return { + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResultFromHeaderMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/header', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const testErrorCodeMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/error', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * Body should not be unknown + * + * Body should not be unknown + */ +export const postApiVbyApiVersionBodyMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/body', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/types.gen.ts new file mode 100644 index 0000000000..fa2bd89d85 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/types.gen.ts @@ -0,0 +1,1188 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseURL: 'http://localhost:3000/base' | (string & {}); +}; + +export type ExternalRefA = ExternalSharedExternalSharedModel; + +export type ExternalRefB = ExternalSharedExternalSharedModel; + +/** + * 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; +}; + +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 ExternalSharedExternalSharedModel = { + 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; +}; + +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/swr/fetch/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client.gen.ts new file mode 100644 index 0000000000..6b55ac80f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client.gen.ts @@ -0,0 +1,18 @@ +// 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/swr/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/client.gen.ts new file mode 100644 index 0000000000..a439d2748f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/client.gen.ts @@ -0,0 +1,268 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { + Client, + Config, + RequestOptions, + ResolvedRequestOptions, +} from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors< + Request, + Response, + unknown, + ResolvedRequestOptions + >(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body); + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response = await _fetch(request); + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if ( + response.status === 204 || + response.headers.get('Content-Length') === '0' + ) { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'json': + case 'text': + data = await response[parseAs](); + break; + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = + (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = + (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/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/swr/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/types.gen.ts new file mode 100644 index 0000000000..b4a499cc03 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/types.gen.ts @@ -0,0 +1,241 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { + Client as CoreClient, + Config as CoreConfig, +} from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: + | 'arrayBuffer' + | 'auto' + | 'blob' + | 'formData' + | 'json' + | 'stream' + | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record + ? TData[keyof TData] + : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? + | (TData extends Record + ? TData[keyof TData] + : TData) + | undefined + : ( + | { + data: TData extends Record + ? TData[keyof TData] + : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick< + Required>, + 'method' + >, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/utils.gen.ts new file mode 100644 index 0000000000..4c48a9ee11 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/utils.gen.ts @@ -0,0 +1,332 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = ( + contentType: string | null, +): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if ( + cleanContent.startsWith('application/json') || + cleanContent.endsWith('+json') + ) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => + cleanContent.startsWith(type), + ) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = + header instanceof Headers + ? headersEntries(header) + : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e. their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = ( + request: Req, + options: Options, +) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update( + id: number | Interceptor, + fn: Interceptor, + ): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/fetch/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/sdk.gen.ts new file mode 100644 index 0000000000..9143c94322 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/sdk.gen.ts @@ -0,0 +1,335 @@ +// 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) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const patchApiVbyApiVersionNoTag = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const fooWow = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const getCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const headCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).head({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).options({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const patchCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const postCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const putCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const callWithDescriptions = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/descriptions/', + ...options + }); +}; + +export const callWithParameters = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options + }); +}; + +export const callWithWeirdParameterNames = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + querySerializer: { + parameters: { + parameterModel: { + object: { + explode: false, + style: 'form' + } + } + } + }, + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callWithDefaultOptionalParameters = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callToTestOrderOfParams = (options: Options) => { + return (options.client ?? client).put({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const duplicateName = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName2 = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName3 = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName4 = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const callWithNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no-content', + ...options + }); +}; + +export const callWithResponseAndNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/response-and-no-content', + ...options + }); +}; + +export const dummyA = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/a', + ...options + }); +}; + +export const dummyB = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/b', + ...options + }); +}; + +export const callWithResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithDuplicateResponses = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithResponses = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const collectionFormat = (options: Options) => { + return (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) => { + return (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) => { + return (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) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/header', + ...options + }); +}; + +export const testErrorCode = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/error', + ...options + }); +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { + return (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) => { + return (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/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts new file mode 100644 index 0000000000..e36cf187f8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts @@ -0,0 +1,677 @@ +// This file is auto-generated by @hey-api/openapi-ts + +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, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from './types.gen'; + +export const serviceWithEmptyTagKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no+tag' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const serviceWithEmptyTagOptions = (options?: Options) => { + return { + key: serviceWithEmptyTagKey(options), + fetcher: async () => { + const { data } = await serviceWithEmptyTag({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooWowMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { + return { + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDescriptionsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/descriptions/', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameterPath}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultParametersKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/defaults' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithDefaultParametersOptions = (options: Options) => { + return { + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callToTestOrderOfParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateNameMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName2Key = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/duplicate' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const duplicateName2Options = (options?: Options) => { + return { + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName3Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName4Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithNoContentResponseOptions = (options?: Options) => { + return { + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/response-and-no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { + return { + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyAKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/a' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyAOptions = (options?: Options) => { + return { + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyBKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/b' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyBOptions = (options?: Options) => { + return { + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/response' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseOptions = (options?: Options) => { + return { + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDuplicateResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const collectionFormatKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/collectionFormat' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const collectionFormatOptions = (options: Options) => { + return { + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const typesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/types' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const typesOptions = (options: Options) => { + return { + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexTypesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/complex' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const complexTypesOptions = (options: Options) => { + return { + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResultFromHeaderMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/header', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const testErrorCodeMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/error', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * Body should not be unknown + * + * Body should not be unknown + */ +export const postApiVbyApiVersionBodyMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/body', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/types.gen.ts new file mode 100644 index 0000000000..9be8ff439d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/types.gen.ts @@ -0,0 +1,1188 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: 'http://localhost:3000/base' | (string & {}); +}; + +export type ExternalRefA = ExternalSharedExternalSharedModel; + +export type ExternalRefB = ExternalSharedExternalSharedModel; + +/** + * 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; +}; + +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 ExternalSharedExternalSharedModel = { + 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; +}; + +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__/3.0.x/plugins/swr/asClass/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client.gen.ts new file mode 100644 index 0000000000..cab3c70195 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig()); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/client.gen.ts new file mode 100644 index 0000000000..a439d2748f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/client.gen.ts @@ -0,0 +1,268 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { + Client, + Config, + RequestOptions, + ResolvedRequestOptions, +} from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors< + Request, + Response, + unknown, + ResolvedRequestOptions + >(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body); + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response = await _fetch(request); + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if ( + response.status === 204 || + response.headers.get('Content-Length') === '0' + ) { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'json': + case 'text': + data = await response[parseAs](); + break; + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = + (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = + (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/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/swr/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/types.gen.ts new file mode 100644 index 0000000000..b4a499cc03 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/types.gen.ts @@ -0,0 +1,241 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { + Client as CoreClient, + Config as CoreConfig, +} from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: + | 'arrayBuffer' + | 'auto' + | 'blob' + | 'formData' + | 'json' + | 'stream' + | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record + ? TData[keyof TData] + : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? + | (TData extends Record + ? TData[keyof TData] + : TData) + | undefined + : ( + | { + data: TData extends Record + ? TData[keyof TData] + : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick< + Required>, + 'method' + >, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/utils.gen.ts new file mode 100644 index 0000000000..4c48a9ee11 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/utils.gen.ts @@ -0,0 +1,332 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = ( + contentType: string | null, +): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if ( + cleanContent.startsWith('application/json') || + cleanContent.endsWith('+json') + ) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => + cleanContent.startsWith(type), + ) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = + header instanceof Headers + ? headersEntries(header) + : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e. their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = ( + request: Req, + options: Options, +) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update( + id: number | Interceptor, + fn: Interceptor, + ): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/asClass/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/sdk.gen.ts new file mode 100644 index 0000000000..fdfe39f104 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/sdk.gen.ts @@ -0,0 +1,75 @@ +// 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 { FooBarPostData, FooBarPostResponses, FooBarPutData, FooBarPutResponses, FooPostData, FooPostResponses, FooPutData, FooPutResponses, GetFooBarData, GetFooBarResponses, GetFooData, GetFooResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export class BarService { + public static post(options?: Options) { + return (options?.client ?? client).post({ + url: '/foo/bar', + ...options + }); + } + + public static put(options?: Options) { + return (options?.client ?? client).put({ + url: '/foo/bar', + ...options + }); + } +} + +export class FooService { + public static post(options?: Options) { + return (options?.client ?? client).post({ + url: '/foo', + ...options + }); + } + + public static put(options?: Options) { + return (options?.client ?? client).put({ + url: '/foo', + ...options + }); + } + + static barService = BarService; +} + +export class FooBazService { + public static getFoo(options?: Options) { + return (options?.client ?? client).get({ + url: '/foo', + ...options + }); + } + + static fooService = FooService; +} + +export class BarBazService { + public static getFooBar(options?: Options) { + return (options?.client ?? client).get({ + url: '/foo/bar', + ...options + }); + } + + static fooService = FooService; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts new file mode 100644 index 0000000000..586defdb49 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts @@ -0,0 +1,126 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { BarBazService, FooBazService, type Options } from './sdk.gen'; +import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarData, GetFooData } from './types.gen'; + +export const getFooKey = (options?: Options) => { + const key: any[] = [ + '/foo' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getFooOptions = (options?: Options) => { + return { + key: getFooKey(options), + fetcher: async () => { + const { data } = await FooBazService.getFoo({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooPostMutation = (options?: Options) => { + return { + key: '/foo', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooPutMutation = (options?: Options) => { + return { + key: '/foo', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getFooBarKey = (options?: Options) => { + const key: any[] = [ + '/foo/bar' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getFooBarOptions = (options?: Options) => { + return { + key: getFooBarKey(options), + fetcher: async () => { + const { data } = await BarBazService.getFooBar({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooBarPostMutation = (options?: Options) => { + return { + key: '/foo/bar', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooBarPutMutation = (options?: Options) => { + return { + key: '/foo/bar', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/types.gen.ts new file mode 100644 index 0000000000..836288372b --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/types.gen.ts @@ -0,0 +1,101 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type GetFooData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type GetFooResponses = { + /** + * OK + */ + 200: string; +}; + +export type GetFooResponse = GetFooResponses[keyof GetFooResponses]; + +export type FooPostData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type FooPostResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooPostResponse = FooPostResponses[keyof FooPostResponses]; + +export type FooPutData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type FooPutResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooPutResponse = FooPutResponses[keyof FooPutResponses]; + +export type GetFooBarData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type GetFooBarResponses = { + /** + * OK + */ + 200: string; +}; + +export type GetFooBarResponse = GetFooBarResponses[keyof GetFooBarResponses]; + +export type FooBarPostData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type FooBarPostResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooBarPostResponse = FooBarPostResponses[keyof FooBarPostResponses]; + +export type FooBarPutData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type FooBarPutResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooBarPutResponse = FooBarPutResponses[keyof FooBarPutResponses]; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client.gen.ts new file mode 100644 index 0000000000..27214c60f4 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client.gen.ts @@ -0,0 +1,18 @@ +// 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/swr/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/client.gen.ts new file mode 100644 index 0000000000..f81a9e7863 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/client.gen.ts @@ -0,0 +1,163 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + let instance: AxiosInstance; + + if (_config.axios && !('Axios' in _config.axios)) { + instance = _config.axios; + } else { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { auth, ...configWithoutAuth } = _config; + instance = axios.create(configWithoutAuth); + } + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + instance.defaults = { + ...instance.defaults, + ..._config, + // @ts-expect-error + headers: mergeHeaders(instance.defaults.headers, _config.headers), + }; + return getConfig(); + }; + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + axios: options.axios ?? _config.axios ?? instance, + headers: mergeHeaders(_config.headers, options.headers), + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.body = opts.bodySerializer(opts.body); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + // @ts-expect-error + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + try { + // assign Axios here for consistency with fetch + const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { auth, ...optsWithoutAuth } = opts; + const response = await _axios({ + ...optsWithoutAuth, + baseURL: '', // the baseURL is already included in `url` + data: getValidRequestBody(opts), + headers: opts.headers as RawAxiosRequestHeaders, + // let `paramsSerializer()` handle query params if it exists + params: opts.paramsSerializer ? opts.query : undefined, + url, + }); + + let { data } = response; + + if (opts.responseType === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return { + ...response, + data: data ?? {}, + }; + } catch (error) { + const e = error as AxiosError; + if (opts.throwOnError) { + throw e; + } + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; + } + }; + + 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 Record, + method, + // @ts-expect-error + signal: opts.signal, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + instance, + 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/swr/axios/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/index.ts new file mode 100644 index 0000000000..7bd7b98807 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/index.ts @@ -0,0 +1,23 @@ +// 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, + TDataShape, +} from './types.gen'; +export { createConfig } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/types.gen.ts new file mode 100644 index 0000000000..59be50cc30 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/types.gen.ts @@ -0,0 +1,197 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + AxiosError, + AxiosInstance, + AxiosRequestHeaders, + AxiosResponse, + AxiosStatic, + CreateAxiosDefaults, +} from 'axios'; + +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'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Axios implementation. You can use this option to provide either an + * `AxiosStatic` or an `AxiosInstance`. + * + * @default axios + */ + axios?: AxiosStatic | AxiosInstance; + /** + * Base URL for all requests made by this client. + */ + baseURL?: T['baseURL']; + /** + * 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?: + | AxiosRequestHeaders + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ClientOptions { + baseURL?: string; + throwOnError?: boolean; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, +> = ThrowOnError extends true + ? Promise< + AxiosResponse< + TData extends Record ? TData[keyof TData] : TData + > + > + : Promise< + | (AxiosResponse< + TData extends Record ? TData[keyof TData] : TData + > & { error: undefined }) + | (AxiosError< + TError extends Record ? TError[keyof TError] : TError + > & { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + }) + >; + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + 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< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + instance: AxiosInstance; +}; + +/** + * 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, +> = 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/swr/axios/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/utils.gen.ts new file mode 100644 index 0000000000..723c477c05 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/utils.gen.ts @@ -0,0 +1,213 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } 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; +}; + +const checkForExistence = ( + options: Pick & { + headers: Record; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if (name in options.headers || options.query?.[name]) { + return true; + } + if ( + 'Cookie' in options.headers && + options.headers['Cookie'] && + typeof options.headers['Cookie'] === 'string' + ) { + return options.headers['Cookie'].includes(`${name}=`); + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Record; + }) => { + 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': { + const value = `${name}=${token}`; + if ('Cookie' in options.headers && options.headers['Cookie']) { + options.headers['Cookie'] = `${options.headers['Cookie']}; ${value}`; + } else { + options.headers['Cookie'] = value; + } + break; + } + case 'header': + default: + options.headers[name] = token; + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => { + const instanceBaseUrl = options.axios?.defaults?.baseURL; + + const baseUrl = + !!options.baseURL && typeof options.baseURL === 'string' + ? options.baseURL + : instanceBaseUrl; + + return getUrl({ + baseUrl: baseUrl as string, + path: options.path, + // let `paramsSerializer()` handle query params if it exists + query: !options.paramsSerializer ? options.query : undefined, + 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 }; + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +/** + * Special Axios headers keywords allowing to set headers by request method. + */ +export const axiosHeadersKeywords = [ + 'common', + 'delete', + 'get', + 'head', + 'patch', + 'post', + 'put', +] as const; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Record => { + const mergedHeaders: Record = {}; + for (const header of headers) { + if (!header || typeof header !== 'object') { + continue; + } + + const iterator = Object.entries(header); + + for (const [key, value] of iterator) { + if ( + axiosHeadersKeywords.includes( + key as (typeof axiosHeadersKeywords)[number], + ) && + typeof value === 'object' + ) { + mergedHeaders[key] = { + ...(mergedHeaders[key] as Record), + ...value, + }; + } else if (value === null) { + delete mergedHeaders[key]; + } else if (Array.isArray(value)) { + for (const v of value) { + // @ts-expect-error + mergedHeaders[key] = [...(mergedHeaders[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[key] = + typeof value === 'object' ? JSON.stringify(value) : (value as string); + } + } + } + return mergedHeaders; +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/axios/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/sdk.gen.ts new file mode 100644 index 0000000000..2d24d85a6d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/sdk.gen.ts @@ -0,0 +1,432 @@ +// 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) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const patchApiVbyApiVersionNoTag = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const import_ = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/no+tag', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const fooWow = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const apiVVersionODataControllerCount = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/simple/$count', + ...options + }); +}; + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => { + return (options.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/simple:operation', + ...options + }); +}; + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const getCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const headCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).head({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).options({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const patchCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const postCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const putCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const deleteFoo = (options: Options) => { + return (options.client ?? client).delete({ + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', + ...options + }); +}; + +export const callWithDescriptions = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/descriptions', + ...options + }); +}; + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/deprecated', + ...options + }); +}; + +export const callWithParameters = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const callWithWeirdParameterNames = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const postCallWithOptionalParam = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const postApiVbyApiVersionRequestBody = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/requestBody', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } + }); +}; + +export const postApiVbyApiVersionFormData = (options?: Options) => { + return (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/formData', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } + }); +}; + +export const callWithDefaultParameters = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callWithDefaultOptionalParameters = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callToTestOrderOfParams = (options: Options) => { + return (options.client ?? client).put({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const duplicateName = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName2 = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName3 = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName4 = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const callWithNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no-content', + ...options + }); +}; + +export const callWithResponseAndNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/multiple-tags/response-and-no-content', + ...options + }); +}; + +export const dummyA = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/multiple-tags/a', + ...options + }); +}; + +export const dummyB = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/b', + ...options + }); +}; + +export const callWithResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithDuplicateResponses = (options?: Options) => { + return (options?.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithResponses = (options?: Options) => { + return (options?.client ?? client).put({ + responseType: 'json', + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const collectionFormat = (options: Options) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/collectionFormat', + ...options + }); +}; + +export const types = (options: Options) => { + return (options.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/types', + ...options + }); +}; + +export const uploadFile = (options: Options) => { + return (options.client ?? client).post({ + ...urlSearchParamsBodySerializer, + responseType: 'json', + url: '/api/v{api-version}/upload', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } + }); +}; + +export const fileResponse = (options: Options) => { + return (options.client ?? client).get({ + responseType: 'blob', + url: '/api/v{api-version}/file/{id}', + ...options + }); +}; + +export const complexTypes = (options: Options) => { + return (options.client ?? client).get({ + querySerializer: { + parameters: { + parameterObject: { + object: { + style: 'form' + } + } + } + }, + responseType: 'json', + url: '/api/v{api-version}/complex', + ...options + }); +}; + +export const multipartResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multipart', + ...options + }); +}; + +export const multipartRequest = (options?: Options) => { + return (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/multipart', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } + }); +}; + +export const complexParams = (options: Options) => { + return (options.client ?? client).put({ + responseType: 'json', + url: '/api/v{api-version}/complex/{id}', + ...options, + headers: { + 'Content-Type': 'application/json-patch+json', + ...options.headers + } + }); +}; + +export const callWithResultFromHeader = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/header', + ...options + }); +}; + +export const testErrorCode = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/error', + ...options + }); +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options + }); +}; + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => { + return (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/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts new file mode 100644 index 0000000000..1fb85af58b --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts @@ -0,0 +1,999 @@ +// This file is auto-generated by @hey-api/openapi-ts + +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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData } from './types.gen'; + +export const exportKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no+tag' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const exportOptions = (options?: Options) => { + return { + key: exportKey(options), + fetcher: async () => { + const { data } = await export_({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const importMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await import_({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooWowMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const apiVVersionODataControllerCountKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple/$count' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const apiVVersionODataControllerCountOptions = (options?: Options) => { + return { + key: apiVVersionODataControllerCountKey(options), + fetcher: async () => { + const { data } = await apiVVersionODataControllerCount({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple:operation' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => { + return { + key: getApiVbyApiVersionSimpleOperationKey(options), + fetcher: async () => { + const { data } = await getApiVbyApiVersionSimpleOperation({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { + return { + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteFooMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteFoo({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDescriptionsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/descriptions', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * @deprecated + */ +export const deprecatedCallMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/deprecated', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deprecatedCall({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameterPath}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithOptionalParamKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/parameters' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithOptionalParamOptions = (options: Options) => { + return { + key: getCallWithOptionalParamKey(options), + fetcher: async () => { + const { data } = await getCallWithOptionalParam({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithOptionalParamInfinite = (options: Options) => { + return { + getKey: (pageIndex: number, previousPageData: any) => { + const pageParam = { + query: { + page: pageIndex + } + }; + const key: any[] = [ + '/api/v{api-version}/parameters' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + const mergedQuery = { ...options?.query, ...pageParam.query }; + key.push({ query: mergedQuery }); + if (options?.body) { + key.push({ body: options.body }); + } + return key; + }, + fetcher: async (key) => { + const params = Object.assign({}, ...key.slice(1)); + const { data } = await getCallWithOptionalParam({ + ...params, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithOptionalParamMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/requestBody', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postApiVbyApiVersionFormDataMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/formData', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultParametersKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/defaults' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithDefaultParametersOptions = (options?: Options) => { + return { + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callToTestOrderOfParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateNameMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName2Key = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/duplicate' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const duplicateName2Options = (options?: Options) => { + return { + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName3Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName4Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithNoContentResponseOptions = (options?: Options) => { + return { + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/response-and-no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { + return { + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyAKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/a' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyAOptions = (options?: Options) => { + return { + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyBKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/b' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyBOptions = (options?: Options) => { + return { + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/response' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseOptions = (options?: Options) => { + return { + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDuplicateResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const collectionFormatKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/collectionFormat' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const collectionFormatOptions = (options: Options) => { + return { + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const typesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/types' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const typesOptions = (options: Options) => { + return { + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const uploadFileMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/upload', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fileResponseKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/file/{id}' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const fileResponseOptions = (options: Options) => { + return { + key: fileResponseKey(options), + fetcher: async () => { + const { data } = await fileResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexTypesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/complex' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const complexTypesOptions = (options: Options) => { + return { + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const multipartResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multipart' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const multipartResponseOptions = (options?: Options) => { + return { + key: multipartResponseKey(options), + fetcher: async () => { + const { data } = await multipartResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const multipartRequestMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/multipart', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await multipartRequest({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/complex/{id}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await complexParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResultFromHeaderMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/header', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const testErrorCodeMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/error', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * Login User + */ +export const putWithFormUrlEncodedMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/types.gen.ts new file mode 100644 index 0000000000..e8df455edc --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/types.gen.ts @@ -0,0 +1,2072 @@ +// 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 = ExternalSharedExternalSharedModel; + +export type ExternalRefB = ExternalSharedExternalSharedModel; + +/** + * 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; +}; + +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 | string | undefined; +}; + +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; +}; + +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 ExternalSharedExternalSharedModel = { + 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; +}; + +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/swr/fetch/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client.gen.ts new file mode 100644 index 0000000000..6b55ac80f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client.gen.ts @@ -0,0 +1,18 @@ +// 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/swr/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/client.gen.ts new file mode 100644 index 0000000000..a439d2748f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/client.gen.ts @@ -0,0 +1,268 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { + Client, + Config, + RequestOptions, + ResolvedRequestOptions, +} from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors< + Request, + Response, + unknown, + ResolvedRequestOptions + >(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body); + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response = await _fetch(request); + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if ( + response.status === 204 || + response.headers.get('Content-Length') === '0' + ) { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'json': + case 'text': + data = await response[parseAs](); + break; + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = + (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = + (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/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/swr/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/types.gen.ts new file mode 100644 index 0000000000..b4a499cc03 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/types.gen.ts @@ -0,0 +1,241 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { + Client as CoreClient, + Config as CoreConfig, +} from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: + | 'arrayBuffer' + | 'auto' + | 'blob' + | 'formData' + | 'json' + | 'stream' + | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record + ? TData[keyof TData] + : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? + | (TData extends Record + ? TData[keyof TData] + : TData) + | undefined + : ( + | { + data: TData extends Record + ? TData[keyof TData] + : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick< + Required>, + 'method' + >, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/utils.gen.ts new file mode 100644 index 0000000000..4c48a9ee11 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/utils.gen.ts @@ -0,0 +1,332 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = ( + contentType: string | null, +): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if ( + cleanContent.startsWith('application/json') || + cleanContent.endsWith('+json') + ) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => + cleanContent.startsWith(type), + ) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = + header instanceof Headers + ? headersEntries(header) + : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e. their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = ( + request: Req, + options: Options, +) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update( + id: number | Interceptor, + fn: Interceptor, + ): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/fetch/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/sdk.gen.ts new file mode 100644 index 0000000000..4166f8b7c0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/sdk.gen.ts @@ -0,0 +1,418 @@ +// 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) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const patchApiVbyApiVersionNoTag = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const import_ = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/no+tag', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const fooWow = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const apiVVersionODataControllerCount = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/simple/$count', + ...options + }); +}; + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/simple:operation', + ...options + }); +}; + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const getCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const headCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).head({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).options({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const patchCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const postCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const putCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const deleteFoo = (options: Options) => { + return (options.client ?? client).delete({ + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', + ...options + }); +}; + +export const callWithDescriptions = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/descriptions', + ...options + }); +}; + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/deprecated', + ...options + }); +}; + +export const callWithParameters = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const callWithWeirdParameterNames = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const postCallWithOptionalParam = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const postApiVbyApiVersionRequestBody = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/requestBody', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } + }); +}; + +export const postApiVbyApiVersionFormData = (options?: Options) => { + return (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/formData', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } + }); +}; + +export const callWithDefaultParameters = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callWithDefaultOptionalParameters = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callToTestOrderOfParams = (options: Options) => { + return (options.client ?? client).put({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const duplicateName = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName2 = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName3 = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName4 = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const callWithNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no-content', + ...options + }); +}; + +export const callWithResponseAndNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/response-and-no-content', + ...options + }); +}; + +export const dummyA = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/a', + ...options + }); +}; + +export const dummyB = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/b', + ...options + }); +}; + +export const callWithResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithDuplicateResponses = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithResponses = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const collectionFormat = (options: Options) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/collectionFormat', + ...options + }); +}; + +export const types = (options: Options) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/types', + ...options + }); +}; + +export const uploadFile = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/file/{id}', + ...options + }); +}; + +export const complexTypes = (options: Options) => { + return (options.client ?? client).get({ + querySerializer: { + parameters: { + parameterObject: { + object: { + style: 'form' + } + } + } + }, + url: '/api/v{api-version}/complex', + ...options + }); +}; + +export const multipartResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multipart', + ...options + }); +}; + +export const multipartRequest = (options?: Options) => { + return (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/multipart', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } + }); +}; + +export const complexParams = (options: Options) => { + return (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) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/header', + ...options + }); +}; + +export const testErrorCode = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/error', + ...options + }); +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options + }); +}; + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => { + return (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/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts new file mode 100644 index 0000000000..1fb85af58b --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts @@ -0,0 +1,999 @@ +// This file is auto-generated by @hey-api/openapi-ts + +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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData } from './types.gen'; + +export const exportKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no+tag' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const exportOptions = (options?: Options) => { + return { + key: exportKey(options), + fetcher: async () => { + const { data } = await export_({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const importMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await import_({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooWowMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const apiVVersionODataControllerCountKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple/$count' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const apiVVersionODataControllerCountOptions = (options?: Options) => { + return { + key: apiVVersionODataControllerCountKey(options), + fetcher: async () => { + const { data } = await apiVVersionODataControllerCount({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple:operation' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => { + return { + key: getApiVbyApiVersionSimpleOperationKey(options), + fetcher: async () => { + const { data } = await getApiVbyApiVersionSimpleOperation({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { + return { + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteFooMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteFoo({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDescriptionsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/descriptions', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * @deprecated + */ +export const deprecatedCallMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/deprecated', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deprecatedCall({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameterPath}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithOptionalParamKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/parameters' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithOptionalParamOptions = (options: Options) => { + return { + key: getCallWithOptionalParamKey(options), + fetcher: async () => { + const { data } = await getCallWithOptionalParam({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithOptionalParamInfinite = (options: Options) => { + return { + getKey: (pageIndex: number, previousPageData: any) => { + const pageParam = { + query: { + page: pageIndex + } + }; + const key: any[] = [ + '/api/v{api-version}/parameters' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + const mergedQuery = { ...options?.query, ...pageParam.query }; + key.push({ query: mergedQuery }); + if (options?.body) { + key.push({ body: options.body }); + } + return key; + }, + fetcher: async (key) => { + const params = Object.assign({}, ...key.slice(1)); + const { data } = await getCallWithOptionalParam({ + ...params, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithOptionalParamMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/requestBody', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postApiVbyApiVersionFormDataMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/formData', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultParametersKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/defaults' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithDefaultParametersOptions = (options?: Options) => { + return { + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callToTestOrderOfParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateNameMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName2Key = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/duplicate' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const duplicateName2Options = (options?: Options) => { + return { + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName3Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName4Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithNoContentResponseOptions = (options?: Options) => { + return { + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/response-and-no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { + return { + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyAKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/a' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyAOptions = (options?: Options) => { + return { + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyBKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/b' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyBOptions = (options?: Options) => { + return { + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/response' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseOptions = (options?: Options) => { + return { + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDuplicateResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const collectionFormatKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/collectionFormat' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const collectionFormatOptions = (options: Options) => { + return { + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const typesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/types' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const typesOptions = (options: Options) => { + return { + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const uploadFileMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/upload', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fileResponseKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/file/{id}' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const fileResponseOptions = (options: Options) => { + return { + key: fileResponseKey(options), + fetcher: async () => { + const { data } = await fileResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexTypesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/complex' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const complexTypesOptions = (options: Options) => { + return { + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const multipartResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multipart' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const multipartResponseOptions = (options?: Options) => { + return { + key: multipartResponseKey(options), + fetcher: async () => { + const { data } = await multipartResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const multipartRequestMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/multipart', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await multipartRequest({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/complex/{id}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await complexParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResultFromHeaderMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/header', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const testErrorCodeMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/error', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * Login User + */ +export const putWithFormUrlEncodedMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/types.gen.ts new file mode 100644 index 0000000000..ef8b52efdf --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/types.gen.ts @@ -0,0 +1,2072 @@ +// 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 = ExternalSharedExternalSharedModel; + +export type ExternalRefB = ExternalSharedExternalSharedModel; + +/** + * 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; +}; + +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 | string | undefined; +}; + +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; +}; + +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 ExternalSharedExternalSharedModel = { + 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; +}; + +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.1.x/plugins/swr/asClass/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client.gen.ts new file mode 100644 index 0000000000..cab3c70195 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client.gen.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { type ClientOptions, type Config, createClient, createConfig } from './client'; +import type { ClientOptions as ClientOptions2 } from './types.gen'; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = (override?: Config) => Config & T>; + +export const client = createClient(createConfig()); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/client.gen.ts new file mode 100644 index 0000000000..a439d2748f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/client.gen.ts @@ -0,0 +1,268 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { + Client, + Config, + RequestOptions, + ResolvedRequestOptions, +} from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors< + Request, + Response, + unknown, + ResolvedRequestOptions + >(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body); + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response = await _fetch(request); + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if ( + response.status === 204 || + response.headers.get('Content-Length') === '0' + ) { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'json': + case 'text': + data = await response[parseAs](); + break; + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = + (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = + (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/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/swr/asClass/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/types.gen.ts new file mode 100644 index 0000000000..b4a499cc03 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/types.gen.ts @@ -0,0 +1,241 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { + Client as CoreClient, + Config as CoreConfig, +} from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: + | 'arrayBuffer' + | 'auto' + | 'blob' + | 'formData' + | 'json' + | 'stream' + | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record + ? TData[keyof TData] + : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? + | (TData extends Record + ? TData[keyof TData] + : TData) + | undefined + : ( + | { + data: TData extends Record + ? TData[keyof TData] + : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick< + Required>, + 'method' + >, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/utils.gen.ts new file mode 100644 index 0000000000..4c48a9ee11 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/utils.gen.ts @@ -0,0 +1,332 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = ( + contentType: string | null, +): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if ( + cleanContent.startsWith('application/json') || + cleanContent.endsWith('+json') + ) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => + cleanContent.startsWith(type), + ) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = + header instanceof Headers + ? headersEntries(header) + : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e. their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = ( + request: Req, + options: Options, +) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update( + id: number | Interceptor, + fn: Interceptor, + ): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/asClass/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/sdk.gen.ts new file mode 100644 index 0000000000..fdfe39f104 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/sdk.gen.ts @@ -0,0 +1,75 @@ +// 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 { FooBarPostData, FooBarPostResponses, FooBarPutData, FooBarPutResponses, FooPostData, FooPostResponses, FooPutData, FooPutResponses, GetFooBarData, GetFooBarResponses, GetFooData, GetFooResponses } from './types.gen'; + +export type Options = Options2 & { + /** + * You can provide a client instance returned by `createClient()` instead of + * individual options. This might be also useful if you want to implement a + * custom client. + */ + client?: Client; + /** + * You can pass arbitrary values through the `meta` object. This can be + * used to access values that aren't defined as part of the SDK function. + */ + meta?: Record; +}; + +export class BarService { + public static post(options?: Options) { + return (options?.client ?? client).post({ + url: '/foo/bar', + ...options + }); + } + + public static put(options?: Options) { + return (options?.client ?? client).put({ + url: '/foo/bar', + ...options + }); + } +} + +export class FooService { + public static post(options?: Options) { + return (options?.client ?? client).post({ + url: '/foo', + ...options + }); + } + + public static put(options?: Options) { + return (options?.client ?? client).put({ + url: '/foo', + ...options + }); + } + + static barService = BarService; +} + +export class FooBazService { + public static getFoo(options?: Options) { + return (options?.client ?? client).get({ + url: '/foo', + ...options + }); + } + + static fooService = FooService; +} + +export class BarBazService { + public static getFooBar(options?: Options) { + return (options?.client ?? client).get({ + url: '/foo/bar', + ...options + }); + } + + static fooService = FooService; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts new file mode 100644 index 0000000000..586defdb49 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts @@ -0,0 +1,126 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { BarBazService, FooBazService, type Options } from './sdk.gen'; +import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarData, GetFooData } from './types.gen'; + +export const getFooKey = (options?: Options) => { + const key: any[] = [ + '/foo' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getFooOptions = (options?: Options) => { + return { + key: getFooKey(options), + fetcher: async () => { + const { data } = await FooBazService.getFoo({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooPostMutation = (options?: Options) => { + return { + key: '/foo', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooPutMutation = (options?: Options) => { + return { + key: '/foo', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getFooBarKey = (options?: Options) => { + const key: any[] = [ + '/foo/bar' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getFooBarOptions = (options?: Options) => { + return { + key: getFooBarKey(options), + fetcher: async () => { + const { data } = await BarBazService.getFooBar({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooBarPostMutation = (options?: Options) => { + return { + key: '/foo/bar', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooBarPutMutation = (options?: Options) => { + return { + key: '/foo/bar', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/types.gen.ts new file mode 100644 index 0000000000..836288372b --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/types.gen.ts @@ -0,0 +1,101 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type ClientOptions = { + baseUrl: `${string}://${string}` | (string & {}); +}; + +export type GetFooData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type GetFooResponses = { + /** + * OK + */ + 200: string; +}; + +export type GetFooResponse = GetFooResponses[keyof GetFooResponses]; + +export type FooPostData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type FooPostResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooPostResponse = FooPostResponses[keyof FooPostResponses]; + +export type FooPutData = { + body?: never; + path?: never; + query?: never; + url: '/foo'; +}; + +export type FooPutResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooPutResponse = FooPutResponses[keyof FooPutResponses]; + +export type GetFooBarData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type GetFooBarResponses = { + /** + * OK + */ + 200: string; +}; + +export type GetFooBarResponse = GetFooBarResponses[keyof GetFooBarResponses]; + +export type FooBarPostData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type FooBarPostResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooBarPostResponse = FooBarPostResponses[keyof FooBarPostResponses]; + +export type FooBarPutData = { + body?: never; + path?: never; + query?: never; + url: '/foo/bar'; +}; + +export type FooBarPutResponses = { + /** + * OK + */ + 200: string; +}; + +export type FooBarPutResponse = FooBarPutResponses[keyof FooBarPutResponses]; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client.gen.ts new file mode 100644 index 0000000000..27214c60f4 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client.gen.ts @@ -0,0 +1,18 @@ +// 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/swr/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/client.gen.ts new file mode 100644 index 0000000000..f81a9e7863 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/client.gen.ts @@ -0,0 +1,163 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { Client, Config, RequestOptions } from './types.gen'; +import { + buildUrl, + createConfig, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + let instance: AxiosInstance; + + if (_config.axios && !('Axios' in _config.axios)) { + instance = _config.axios; + } else { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { auth, ...configWithoutAuth } = _config; + instance = axios.create(configWithoutAuth); + } + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + instance.defaults = { + ...instance.defaults, + ..._config, + // @ts-expect-error + headers: mergeHeaders(instance.defaults.headers, _config.headers), + }; + return getConfig(); + }; + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + axios: options.axios ?? _config.axios ?? instance, + headers: mergeHeaders(_config.headers, options.headers), + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.body = opts.bodySerializer(opts.body); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + // @ts-expect-error + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + try { + // assign Axios here for consistency with fetch + const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { auth, ...optsWithoutAuth } = opts; + const response = await _axios({ + ...optsWithoutAuth, + baseURL: '', // the baseURL is already included in `url` + data: getValidRequestBody(opts), + headers: opts.headers as RawAxiosRequestHeaders, + // let `paramsSerializer()` handle query params if it exists + params: opts.paramsSerializer ? opts.query : undefined, + url, + }); + + let { data } = response; + + if (opts.responseType === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return { + ...response, + data: data ?? {}, + }; + } catch (error) { + const e = error as AxiosError; + if (opts.throwOnError) { + throw e; + } + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; + } + }; + + 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 Record, + method, + // @ts-expect-error + signal: opts.signal, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + instance, + 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/swr/axios/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/index.ts new file mode 100644 index 0000000000..7bd7b98807 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/index.ts @@ -0,0 +1,23 @@ +// 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, + TDataShape, +} from './types.gen'; +export { createConfig } from './utils.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/types.gen.ts new file mode 100644 index 0000000000..59be50cc30 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/types.gen.ts @@ -0,0 +1,197 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + AxiosError, + AxiosInstance, + AxiosRequestHeaders, + AxiosResponse, + AxiosStatic, + CreateAxiosDefaults, +} from 'axios'; + +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'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Axios implementation. You can use this option to provide either an + * `AxiosStatic` or an `AxiosInstance`. + * + * @default axios + */ + axios?: AxiosStatic | AxiosInstance; + /** + * Base URL for all requests made by this client. + */ + baseURL?: T['baseURL']; + /** + * 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?: + | AxiosRequestHeaders + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ClientOptions { + baseURL?: string; + throwOnError?: boolean; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, +> = ThrowOnError extends true + ? Promise< + AxiosResponse< + TData extends Record ? TData[keyof TData] : TData + > + > + : Promise< + | (AxiosResponse< + TData extends Record ? TData[keyof TData] : TData + > & { error: undefined }) + | (AxiosError< + TError extends Record ? TError[keyof TError] : TError + > & { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + }) + >; + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, +>( + 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< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + instance: AxiosInstance; +}; + +/** + * 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, +> = 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/swr/axios/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/utils.gen.ts new file mode 100644 index 0000000000..723c477c05 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/utils.gen.ts @@ -0,0 +1,213 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } 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; +}; + +const checkForExistence = ( + options: Pick & { + headers: Record; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if (name in options.headers || options.query?.[name]) { + return true; + } + if ( + 'Cookie' in options.headers && + options.headers['Cookie'] && + typeof options.headers['Cookie'] === 'string' + ) { + return options.headers['Cookie'].includes(`${name}=`); + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Record; + }) => { + 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': { + const value = `${name}=${token}`; + if ('Cookie' in options.headers && options.headers['Cookie']) { + options.headers['Cookie'] = `${options.headers['Cookie']}; ${value}`; + } else { + options.headers['Cookie'] = value; + } + break; + } + case 'header': + default: + options.headers[name] = token; + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => { + const instanceBaseUrl = options.axios?.defaults?.baseURL; + + const baseUrl = + !!options.baseURL && typeof options.baseURL === 'string' + ? options.baseURL + : instanceBaseUrl; + + return getUrl({ + baseUrl: baseUrl as string, + path: options.path, + // let `paramsSerializer()` handle query params if it exists + query: !options.paramsSerializer ? options.query : undefined, + 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 }; + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +/** + * Special Axios headers keywords allowing to set headers by request method. + */ +export const axiosHeadersKeywords = [ + 'common', + 'delete', + 'get', + 'head', + 'patch', + 'post', + 'put', +] as const; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Record => { + const mergedHeaders: Record = {}; + for (const header of headers) { + if (!header || typeof header !== 'object') { + continue; + } + + const iterator = Object.entries(header); + + for (const [key, value] of iterator) { + if ( + axiosHeadersKeywords.includes( + key as (typeof axiosHeadersKeywords)[number], + ) && + typeof value === 'object' + ) { + mergedHeaders[key] = { + ...(mergedHeaders[key] as Record), + ...value, + }; + } else if (value === null) { + delete mergedHeaders[key]; + } else if (Array.isArray(value)) { + for (const v of value) { + // @ts-expect-error + mergedHeaders[key] = [...(mergedHeaders[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[key] = + typeof value === 'object' ? JSON.stringify(value) : (value as string); + } + } + } + return mergedHeaders; +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/axios/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/sdk.gen.ts new file mode 100644 index 0000000000..2d24d85a6d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/sdk.gen.ts @@ -0,0 +1,432 @@ +// 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) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const patchApiVbyApiVersionNoTag = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const import_ = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/no+tag', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const fooWow = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const apiVVersionODataControllerCount = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/simple/$count', + ...options + }); +}; + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => { + return (options.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/simple:operation', + ...options + }); +}; + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const getCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const headCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).head({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).options({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const patchCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const postCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const putCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const deleteFoo = (options: Options) => { + return (options.client ?? client).delete({ + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', + ...options + }); +}; + +export const callWithDescriptions = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/descriptions', + ...options + }); +}; + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/deprecated', + ...options + }); +}; + +export const callWithParameters = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const callWithWeirdParameterNames = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const postCallWithOptionalParam = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const postApiVbyApiVersionRequestBody = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/requestBody', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } + }); +}; + +export const postApiVbyApiVersionFormData = (options?: Options) => { + return (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/formData', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } + }); +}; + +export const callWithDefaultParameters = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callWithDefaultOptionalParameters = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callToTestOrderOfParams = (options: Options) => { + return (options.client ?? client).put({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const duplicateName = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName2 = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName3 = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName4 = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const callWithNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no-content', + ...options + }); +}; + +export const callWithResponseAndNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/multiple-tags/response-and-no-content', + ...options + }); +}; + +export const dummyA = (options?: Options) => { + return (options?.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/multiple-tags/a', + ...options + }); +}; + +export const dummyB = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/b', + ...options + }); +}; + +export const callWithResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithDuplicateResponses = (options?: Options) => { + return (options?.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithResponses = (options?: Options) => { + return (options?.client ?? client).put({ + responseType: 'json', + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const collectionFormat = (options: Options) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/collectionFormat', + ...options + }); +}; + +export const types = (options: Options) => { + return (options.client ?? client).get({ + responseType: 'json', + url: '/api/v{api-version}/types', + ...options + }); +}; + +export const uploadFile = (options: Options) => { + return (options.client ?? client).post({ + ...urlSearchParamsBodySerializer, + responseType: 'json', + url: '/api/v{api-version}/upload', + ...options, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + ...options.headers + } + }); +}; + +export const fileResponse = (options: Options) => { + return (options.client ?? client).get({ + responseType: 'blob', + url: '/api/v{api-version}/file/{id}', + ...options + }); +}; + +export const complexTypes = (options: Options) => { + return (options.client ?? client).get({ + querySerializer: { + parameters: { + parameterObject: { + object: { + style: 'form' + } + } + } + }, + responseType: 'json', + url: '/api/v{api-version}/complex', + ...options + }); +}; + +export const multipartResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multipart', + ...options + }); +}; + +export const multipartRequest = (options?: Options) => { + return (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/multipart', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } + }); +}; + +export const complexParams = (options: Options) => { + return (options.client ?? client).put({ + responseType: 'json', + url: '/api/v{api-version}/complex/{id}', + ...options, + headers: { + 'Content-Type': 'application/json-patch+json', + ...options.headers + } + }); +}; + +export const callWithResultFromHeader = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/header', + ...options + }); +}; + +export const testErrorCode = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/error', + ...options + }); +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { + return (options.client ?? client).post({ + responseType: 'json', + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options + }); +}; + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => { + return (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/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts new file mode 100644 index 0000000000..4f818115be --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts @@ -0,0 +1,999 @@ +// This file is auto-generated by @hey-api/openapi-ts + +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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData } from './types.gen'; + +export const exportKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no+tag' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const exportOptions = (options?: Options) => { + return { + key: exportKey(options), + fetcher: async () => { + const { data } = await export_({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const importMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await import_({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooWowMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const apiVVersionODataControllerCountKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple/$count' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const apiVVersionODataControllerCountOptions = (options?: Options) => { + return { + key: apiVVersionODataControllerCountKey(options), + fetcher: async () => { + const { data } = await apiVVersionODataControllerCount({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple:operation' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => { + return { + key: getApiVbyApiVersionSimpleOperationKey(options), + fetcher: async () => { + const { data } = await getApiVbyApiVersionSimpleOperation({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { + return { + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteFooMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteFoo({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDescriptionsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/descriptions', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * @deprecated + */ +export const deprecatedCallMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/deprecated', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deprecatedCall({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameterPath}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithOptionalParamKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/parameters' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithOptionalParamOptions = (options: Options) => { + return { + key: getCallWithOptionalParamKey(options), + fetcher: async () => { + const { data } = await getCallWithOptionalParam({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithOptionalParamInfinite = (options: Options) => { + return { + getKey: (pageIndex: number) => { + const pageParam = { + query: { + page: pageIndex + } + }; + const key: any[] = [ + '/api/v{api-version}/parameters' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + const mergedQuery = { ...options?.query, ...pageParam.query }; + key.push({ query: mergedQuery }); + if (options?.body) { + key.push({ body: options.body }); + } + return key; + }, + fetcher: async (key: unknown[]) => { + const params = Object.assign({}, ...key.slice(1)); + const { data } = await getCallWithOptionalParam({ + ...params, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithOptionalParamMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/requestBody', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postApiVbyApiVersionFormDataMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/formData', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultParametersKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/defaults' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithDefaultParametersOptions = (options?: Options) => { + return { + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callToTestOrderOfParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateNameMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName2Key = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/duplicate' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const duplicateName2Options = (options?: Options) => { + return { + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName3Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName4Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithNoContentResponseOptions = (options?: Options) => { + return { + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/response-and-no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { + return { + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyAKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/a' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyAOptions = (options?: Options) => { + return { + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyBKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/b' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyBOptions = (options?: Options) => { + return { + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/response' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseOptions = (options?: Options) => { + return { + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDuplicateResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const collectionFormatKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/collectionFormat' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const collectionFormatOptions = (options: Options) => { + return { + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const typesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/types' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const typesOptions = (options: Options) => { + return { + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const uploadFileMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/upload', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fileResponseKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/file/{id}' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const fileResponseOptions = (options: Options) => { + return { + key: fileResponseKey(options), + fetcher: async () => { + const { data } = await fileResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexTypesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/complex' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const complexTypesOptions = (options: Options) => { + return { + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const multipartResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multipart' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const multipartResponseOptions = (options?: Options) => { + return { + key: multipartResponseKey(options), + fetcher: async () => { + const { data } = await multipartResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const multipartRequestMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/multipart', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await multipartRequest({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/complex/{id}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await complexParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResultFromHeaderMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/header', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const testErrorCodeMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/error', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * Login User + */ +export const putWithFormUrlEncodedMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/types.gen.ts new file mode 100644 index 0000000000..3d1d4d6fcc --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/types.gen.ts @@ -0,0 +1,2091 @@ +// 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 = ExternalSharedExternalSharedModel; + +/** + * External ref to shared model (B) + */ +export type ExternalRefB = ExternalSharedExternalSharedModel; + +/** + * 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; +}; + +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 | string | undefined; +}; + +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; +}; + +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 ExternalSharedExternalSharedModel = { + 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; +}; + +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/swr/fetch/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client.gen.ts new file mode 100644 index 0000000000..6b55ac80f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client.gen.ts @@ -0,0 +1,18 @@ +// 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/swr/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/client.gen.ts new file mode 100644 index 0000000000..a439d2748f --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/client.gen.ts @@ -0,0 +1,268 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen'; +import type { HttpMethod } from '../core/types.gen'; +import { getValidRequestBody } from '../core/utils.gen'; +import type { + Client, + Config, + RequestOptions, + ResolvedRequestOptions, +} from './types.gen'; +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams, +} from './utils.gen'; + +type ReqInit = Omit & { + body?: any; + headers: ReturnType; +}; + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config); + + const getConfig = (): Config => ({ ..._config }); + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config); + return getConfig(); + }; + + const interceptors = createInterceptors< + Request, + Response, + unknown, + ResolvedRequestOptions + >(); + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined, + }; + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security, + }); + } + + if (opts.requestValidator) { + await opts.requestValidator(opts); + } + + if (opts.body !== undefined && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body); + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.body === undefined || opts.serializedBody === '') { + opts.headers.delete('Content-Type'); + } + + const url = buildUrl(opts); + + return { opts, url }; + }; + + const request: Client['request'] = async (options) => { + // @ts-expect-error + const { opts, url } = await beforeRequest(options); + const requestInit: ReqInit = { + redirect: 'follow', + ...opts, + body: getValidRequestBody(opts), + }; + + let request = new Request(url, requestInit); + + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = opts.fetch!; + let response = await _fetch(request); + + for (const fn of interceptors.response.fns) { + if (fn) { + response = await fn(response, request, opts); + } + } + + const result = { + request, + response, + }; + + if (response.ok) { + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json'; + + if ( + response.status === 204 || + response.headers.get('Content-Length') === '0' + ) { + let emptyData: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'text': + emptyData = await response[parseAs](); + break; + case 'formData': + emptyData = new FormData(); + break; + case 'stream': + emptyData = response.body; + break; + case 'json': + default: + emptyData = {}; + break; + } + return opts.responseStyle === 'data' + ? emptyData + : { + data: emptyData, + ...result, + }; + } + + let data: any; + switch (parseAs) { + case 'arrayBuffer': + case 'blob': + case 'formData': + case 'json': + case 'text': + data = await response[parseAs](); + break; + case 'stream': + return opts.responseStyle === 'data' + ? response.body + : { + data: response.body, + ...result, + }; + } + + if (parseAs === 'json') { + if (opts.responseValidator) { + await opts.responseValidator(data); + } + + if (opts.responseTransformer) { + data = await opts.responseTransformer(data); + } + } + + return opts.responseStyle === 'data' + ? data + : { + data, + ...result, + }; + } + + const textError = await response.text(); + let jsonError: unknown; + + try { + jsonError = JSON.parse(textError); + } catch { + // noop + } + + const error = jsonError ?? textError; + let finalError = error; + + for (const fn of interceptors.error.fns) { + if (fn) { + finalError = (await fn(error, response, request, opts)) as string; + } + } + + finalError = finalError || ({} as string); + + if (opts.throwOnError) { + throw finalError; + } + + // TODO: we probably want to return error and improve types + return opts.responseStyle === 'data' + ? undefined + : { + error: finalError, + ...result, + }; + }; + + const makeMethodFn = + (method: Uppercase) => (options: RequestOptions) => + request({ ...options, method }); + + const makeSseFn = + (method: Uppercase) => async (options: RequestOptions) => { + const { opts, url } = await beforeRequest(options); + return createSseClient({ + ...opts, + body: opts.body as BodyInit | null | undefined, + headers: opts.headers as unknown as Record, + method, + onRequest: async (url, init) => { + let request = new Request(url, init); + for (const fn of interceptors.request.fns) { + if (fn) { + request = await fn(request, opts); + } + } + return request; + }, + url, + }); + }; + + return { + buildUrl, + connect: makeMethodFn('CONNECT'), + delete: makeMethodFn('DELETE'), + get: makeMethodFn('GET'), + getConfig, + head: makeMethodFn('HEAD'), + interceptors, + options: makeMethodFn('OPTIONS'), + patch: makeMethodFn('PATCH'), + post: makeMethodFn('POST'), + put: makeMethodFn('PUT'), + request, + setConfig, + sse: { + connect: makeSseFn('CONNECT'), + delete: makeSseFn('DELETE'), + get: makeSseFn('GET'), + head: makeSseFn('HEAD'), + options: makeSseFn('OPTIONS'), + patch: makeSseFn('PATCH'), + post: makeSseFn('POST'), + put: makeSseFn('PUT'), + trace: makeSseFn('TRACE'), + }, + trace: makeMethodFn('TRACE'), + } as Client; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/index.ts new file mode 100644 index 0000000000..b295edeca0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/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/swr/fetch/client/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/types.gen.ts new file mode 100644 index 0000000000..b4a499cc03 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/types.gen.ts @@ -0,0 +1,241 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth } from '../core/auth.gen'; +import type { + ServerSentEventsOptions, + ServerSentEventsResult, +} from '../core/serverSentEvents.gen'; +import type { + Client as CoreClient, + Config as CoreConfig, +} from '../core/types.gen'; +import type { Middleware } from './utils.gen'; + +export type ResponseStyle = 'data' | 'fields'; + +export interface Config + extends Omit, + CoreConfig { + /** + * Base URL for all requests made by this client. + */ + baseUrl?: T['baseUrl']; + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** + * Return the response data parsed in a specified format. By default, `auto` + * will infer the appropriate method from the `Content-Type` response header. + * You can override this behavior with any of the {@link Body} methods. + * Select `stream` if you don't want to parse response data at all. + * + * @default 'auto' + */ + parseAs?: + | 'arrayBuffer' + | 'auto' + | 'blob' + | 'formData' + | 'json' + | 'stream' + | 'text'; + /** + * Should we return only data or multiple fields (data, error, response, etc.)? + * + * @default 'fields' + */ + responseStyle?: ResponseStyle; + /** + * Throw an error instead of returning it in the response? + * + * @default false + */ + throwOnError?: T['throwOnError']; +} + +export interface RequestOptions< + TData = unknown, + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends Config<{ + responseStyle: TResponseStyle; + throwOnError: ThrowOnError; + }>, + Pick< + ServerSentEventsOptions, + | 'onSseError' + | 'onSseEvent' + | 'sseDefaultRetryDelay' + | 'sseMaxRetryAttempts' + | 'sseMaxRetryDelay' + > { + /** + * Any body that you want to add to your request. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} + */ + body?: unknown; + path?: Record; + query?: Record; + /** + * Security mechanism(s) to use for the request. + */ + security?: ReadonlyArray; + url: Url; +} + +export interface ResolvedRequestOptions< + TResponseStyle extends ResponseStyle = 'fields', + ThrowOnError extends boolean = boolean, + Url extends string = string, +> extends RequestOptions { + serializedBody?: string; +} + +export type RequestResult< + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields', +> = ThrowOnError extends true + ? Promise< + TResponseStyle extends 'data' + ? TData extends Record + ? TData[keyof TData] + : TData + : { + data: TData extends Record + ? TData[keyof TData] + : TData; + request: Request; + response: Response; + } + > + : Promise< + TResponseStyle extends 'data' + ? + | (TData extends Record + ? TData[keyof TData] + : TData) + | undefined + : ( + | { + data: TData extends Record + ? TData[keyof TData] + : TData; + error: undefined; + } + | { + data: undefined; + error: TError extends Record + ? TError[keyof TError] + : TError; + } + ) & { + request: Request; + response: Response; + } + >; + +export interface ClientOptions { + baseUrl?: string; + responseStyle?: ResponseStyle; + throwOnError?: boolean; +} + +type MethodFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => RequestResult; + +type SseFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'>, +) => Promise>; + +type RequestFn = < + TData = unknown, + TError = unknown, + ThrowOnError extends boolean = false, + TResponseStyle extends ResponseStyle = 'fields', +>( + options: Omit, 'method'> & + Pick< + Required>, + 'method' + >, +) => RequestResult; + +type BuildUrlFn = < + TData extends { + body?: unknown; + path?: Record; + query?: Record; + url: string; + }, +>( + options: TData & Options, +) => string; + +export type Client = CoreClient< + RequestFn, + Config, + MethodFn, + BuildUrlFn, + SseFn +> & { + interceptors: Middleware; +}; + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config, +) => Config & T>; + +export interface TDataShape { + body?: unknown; + headers?: unknown; + path?: unknown; + query?: unknown; + url: string; +} + +type OmitKeys = Pick>; + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields', +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + ([TData] extends [never] ? unknown : Omit); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/utils.gen.ts new file mode 100644 index 0000000000..4c48a9ee11 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/utils.gen.ts @@ -0,0 +1,332 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { getAuthToken } from '../core/auth.gen'; +import type { QuerySerializerOptions } from '../core/bodySerializer.gen'; +import { jsonBodySerializer } from '../core/bodySerializer.gen'; +import { + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from '../core/pathSerializer.gen'; +import { getUrl } from '../core/utils.gen'; +import type { Client, ClientOptions, Config, RequestOptions } from './types.gen'; + +export const createQuerySerializer = ({ + parameters = {}, + ...args +}: QuerySerializerOptions = {}) => { + const querySerializer = (queryParams: T) => { + const search: string[] = []; + if (queryParams && typeof queryParams === 'object') { + for (const name in queryParams) { + const value = queryParams[name]; + + if (value === undefined || value === null) { + continue; + } + + const options = parameters[name] || args; + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'form', + value, + ...options.array, + }); + if (serializedArray) search.push(serializedArray); + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved: options.allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...options.object, + }); + if (serializedObject) search.push(serializedObject); + } else { + const serializedPrimitive = serializePrimitiveParam({ + allowReserved: options.allowReserved, + name, + value: value as string, + }); + if (serializedPrimitive) search.push(serializedPrimitive); + } + } + } + return search.join('&'); + }; + return querySerializer; +}; + +/** + * Infers parseAs value from provided Content-Type header. + */ +export const getParseAs = ( + contentType: string | null, +): Exclude => { + if (!contentType) { + // If no Content-Type header is provided, the best we can do is return the raw response body, + // which is effectively the same as the 'stream' option. + return 'stream'; + } + + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } + + if ( + cleanContent.startsWith('application/json') || + cleanContent.endsWith('+json') + ) { + return 'json'; + } + + if (cleanContent === 'multipart/form-data') { + return 'formData'; + } + + if ( + ['application/', 'audio/', 'image/', 'video/'].some((type) => + cleanContent.startsWith(type), + ) + ) { + return 'blob'; + } + + if (cleanContent.startsWith('text/')) { + return 'text'; + } + + return; +}; + +const checkForExistence = ( + options: Pick & { + headers: Headers; + }, + name?: string, +): boolean => { + if (!name) { + return false; + } + if ( + options.headers.has(name) || + options.query?.[name] || + options.headers.get('Cookie')?.includes(`${name}=`) + ) { + return true; + } + return false; +}; + +export const setAuthParams = async ({ + security, + ...options +}: Pick, 'security'> & + Pick & { + headers: Headers; + }) => { + for (const auth of security) { + if (checkForExistence(options, auth.name)) { + continue; + } + + const token = await getAuthToken(auth, options.auth); + + if (!token) { + continue; + } + + const name = auth.name ?? 'Authorization'; + + switch (auth.in) { + case 'query': + if (!options.query) { + options.query = {}; + } + options.query[name] = token; + break; + case 'cookie': + options.headers.append('Cookie', `${name}=${token}`); + break; + case 'header': + default: + options.headers.set(name, token); + break; + } + } +}; + +export const buildUrl: Client['buildUrl'] = (options) => + getUrl({ + baseUrl: options.baseUrl as string, + path: options.path, + query: options.query, + querySerializer: + typeof options.querySerializer === 'function' + ? options.querySerializer + : createQuerySerializer(options.querySerializer), + url: options.url, + }); + +export const mergeConfigs = (a: Config, b: Config): Config => { + const config = { ...a, ...b }; + if (config.baseUrl?.endsWith('/')) { + config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1); + } + config.headers = mergeHeaders(a.headers, b.headers); + return config; +}; + +const headersEntries = (headers: Headers): Array<[string, string]> => { + const entries: Array<[string, string]> = []; + headers.forEach((value, key) => { + entries.push([key, value]); + }); + return entries; +}; + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers(); + for (const header of headers) { + if (!header) { + continue; + } + + const iterator = + header instanceof Headers + ? headersEntries(header) + : Object.entries(header); + + for (const [key, value] of iterator) { + if (value === null) { + mergedHeaders.delete(key); + } else if (Array.isArray(value)) { + for (const v of value) { + mergedHeaders.append(key, v as string); + } + } else if (value !== undefined) { + // assume object headers are meant to be JSON stringified, i.e. their + // content value in OpenAPI specification is 'application/json' + mergedHeaders.set( + key, + typeof value === 'object' ? JSON.stringify(value) : (value as string), + ); + } + } + } + return mergedHeaders; +}; + +type ErrInterceptor = ( + error: Err, + response: Res, + request: Req, + options: Options, +) => Err | Promise; + +type ReqInterceptor = ( + request: Req, + options: Options, +) => Req | Promise; + +type ResInterceptor = ( + response: Res, + request: Req, + options: Options, +) => Res | Promise; + +class Interceptors { + fns: Array = []; + + clear(): void { + this.fns = []; + } + + eject(id: number | Interceptor): void { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = null; + } + } + + exists(id: number | Interceptor): boolean { + const index = this.getInterceptorIndex(id); + return Boolean(this.fns[index]); + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this.fns[id] ? id : -1; + } + return this.fns.indexOf(id); + } + + update( + id: number | Interceptor, + fn: Interceptor, + ): number | Interceptor | false { + const index = this.getInterceptorIndex(id); + if (this.fns[index]) { + this.fns[index] = fn; + return id; + } + return false; + } + + use(fn: Interceptor): number { + this.fns.push(fn); + return this.fns.length - 1; + } +} + +export interface Middleware { + error: Interceptors>; + request: Interceptors>; + response: Interceptors>; +} + +export const createInterceptors = (): Middleware< + Req, + Res, + Err, + Options +> => ({ + error: new Interceptors>(), + request: new Interceptors>(), + response: new Interceptors>(), +}); + +const defaultQuerySerializer = createQuerySerializer({ + allowReserved: false, + array: { + explode: true, + style: 'form', + }, + object: { + explode: true, + style: 'deepObject', + }, +}); + +const defaultHeaders = { + 'Content-Type': 'application/json', +}; + +export const createConfig = ( + override: Config & T> = {}, +): Config & T> => ({ + ...jsonBodySerializer, + headers: defaultHeaders, + parseAs: 'auto', + querySerializer: defaultQuerySerializer, + ...override, +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/auth.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/auth.gen.ts new file mode 100644 index 0000000000..f8a73266f9 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/auth.gen.ts @@ -0,0 +1,42 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined; + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie'; + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string; + scheme?: 'basic' | 'bearer'; + type: 'apiKey' | 'http'; +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken, +): Promise => { + const token = + typeof callback === 'function' ? await callback(auth) : callback; + + if (!token) { + return; + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}`; + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}`; + } + + return token; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/bodySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/bodySerializer.gen.ts new file mode 100644 index 0000000000..552b50f7c8 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/bodySerializer.gen.ts @@ -0,0 +1,100 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { + ArrayStyle, + ObjectStyle, + SerializerOptions, +} from './pathSerializer.gen'; + +export type QuerySerializer = (query: Record) => string; + +export type BodySerializer = (body: any) => any; + +type QuerySerializerOptionsObject = { + allowReserved?: boolean; + array?: Partial>; + object?: Partial>; +}; + +export type QuerySerializerOptions = QuerySerializerOptionsObject & { + /** + * Per-parameter serialization overrides. When provided, these settings + * override the global array/object settings for specific parameter names. + */ + parameters?: Record; +}; + +const serializeFormDataPair = ( + data: FormData, + key: string, + value: unknown, +): void => { + if (typeof value === 'string' || value instanceof Blob) { + data.append(key, value); + } else if (value instanceof Date) { + data.append(key, value.toISOString()); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +const serializeUrlSearchParamsPair = ( + data: URLSearchParams, + key: string, + value: unknown, +): void => { + if (typeof value === 'string') { + data.append(key, value); + } else { + data.append(key, JSON.stringify(value)); + } +}; + +export const formDataBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): FormData => { + const data = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeFormDataPair(data, key, v)); + } else { + serializeFormDataPair(data, key, value); + } + }); + + return data; + }, +}; + +export const jsonBodySerializer = { + bodySerializer: (body: T): string => + JSON.stringify(body, (_key, value) => + typeof value === 'bigint' ? value.toString() : value, + ), +}; + +export const urlSearchParamsBodySerializer = { + bodySerializer: | Array>>( + body: T, + ): string => { + const data = new URLSearchParams(); + + Object.entries(body).forEach(([key, value]) => { + if (value === undefined || value === null) { + return; + } + if (Array.isArray(value)) { + value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); + } else { + serializeUrlSearchParamsPair(data, key, value); + } + }); + + return data.toString(); + }, +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/params.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/params.gen.ts new file mode 100644 index 0000000000..602715c46c --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/params.gen.ts @@ -0,0 +1,176 @@ +// This file is auto-generated by @hey-api/openapi-ts + +type Slot = 'body' | 'headers' | 'path' | 'query'; + +export type Field = + | { + in: Exclude; + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If omitted, we use the same value as `key`. + */ + map?: string; + } + | { + in: Extract; + /** + * Key isn't required for bodies. + */ + key?: string; + map?: string; + } + | { + /** + * Field name. This is the name we want the user to see and use. + */ + key: string; + /** + * Field mapped name. This is the name we want to use in the request. + * If `in` is omitted, `map` aliases `key` to the transport layer. + */ + map: Slot; + }; + +export interface Fields { + allowExtra?: Partial>; + args?: ReadonlyArray; +} + +export type FieldsConfig = ReadonlyArray; + +const extraPrefixesMap: Record = { + $body_: 'body', + $headers_: 'headers', + $path_: 'path', + $query_: 'query', +}; +const extraPrefixes = Object.entries(extraPrefixesMap); + +type KeyMap = Map< + string, + | { + in: Slot; + map?: string; + } + | { + in?: never; + map: Slot; + } +>; + +const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => { + if (!map) { + map = new Map(); + } + + for (const config of fields) { + if ('in' in config) { + if (config.key) { + map.set(config.key, { + in: config.in, + map: config.map, + }); + } + } else if ('key' in config) { + map.set(config.key, { + map: config.map, + }); + } else if (config.args) { + buildKeyMap(config.args, map); + } + } + + return map; +}; + +interface Params { + body: unknown; + headers: Record; + path: Record; + query: Record; +} + +const stripEmptySlots = (params: Params) => { + for (const [slot, value] of Object.entries(params)) { + if (value && typeof value === 'object' && !Object.keys(value).length) { + delete params[slot as Slot]; + } + } +}; + +export const buildClientParams = ( + args: ReadonlyArray, + fields: FieldsConfig, +) => { + const params: Params = { + body: {}, + headers: {}, + path: {}, + query: {}, + }; + + const map = buildKeyMap(fields); + + let config: FieldsConfig[number] | undefined; + + for (const [index, arg] of args.entries()) { + if (fields[index]) { + config = fields[index]; + } + + if (!config) { + continue; + } + + if ('in' in config) { + if (config.key) { + const field = map.get(config.key)!; + const name = field.map || config.key; + if (field.in) { + (params[field.in] as Record)[name] = arg; + } + } else { + params.body = arg; + } + } else { + for (const [key, value] of Object.entries(arg ?? {})) { + const field = map.get(key); + + if (field) { + if (field.in) { + const name = field.map || key; + (params[field.in] as Record)[name] = value; + } else { + params[field.map] = value; + } + } else { + const extra = extraPrefixes.find(([prefix]) => + key.startsWith(prefix), + ); + + if (extra) { + const [prefix, slot] = extra; + (params[slot] as Record)[ + key.slice(prefix.length) + ] = value; + } else if ('allowExtra' in config && config.allowExtra) { + for (const [slot, allowed] of Object.entries(config.allowExtra)) { + if (allowed) { + (params[slot as Slot] as Record)[key] = value; + break; + } + } + } + } + } + } + } + + stripEmptySlots(params); + + return params; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/pathSerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/pathSerializer.gen.ts new file mode 100644 index 0000000000..8d99931047 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/pathSerializer.gen.ts @@ -0,0 +1,181 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions + extends SerializePrimitiveOptions, + SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean; + name: string; +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean; + style: T; +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle; +type MatrixStyle = 'label' | 'matrix' | 'simple'; +export type ObjectStyle = 'form' | 'deepObject'; +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle; + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string; +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ','; + case 'pipeDelimited': + return '|'; + case 'spaceDelimited': + return '%20'; + default: + return ','; + } +}; + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.'; + case 'matrix': + return ';'; + case 'simple': + return ','; + default: + return '&'; + } +}; + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value, +}: SerializeOptions & { + value: unknown[]; +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)); + switch (style) { + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + case 'simple': + return joinedValues; + default: + return `${name}=${joinedValues}`; + } + } + + const separator = separatorArrayExplode(style); + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string); + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string, + }); + }) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value, +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return ''; + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.', + ); + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}`; +}; + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly, +}: SerializeOptions & { + value: Record | Date; + valueOnly?: boolean; +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`; + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = []; + Object.entries(value).forEach(([key, v]) => { + values = [ + ...values, + key, + allowReserved ? (v as string) : encodeURIComponent(v as string), + ]; + }); + const joinedValues = values.join(','); + switch (style) { + case 'form': + return `${name}=${joinedValues}`; + case 'label': + return `.${joinedValues}`; + case 'matrix': + return `;${name}=${joinedValues}`; + default: + return joinedValues; + } + } + + const separator = separatorObjectExplode(style); + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string, + }), + ) + .join(separator); + return style === 'label' || style === 'matrix' + ? separator + joinedValues + : joinedValues; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts new file mode 100644 index 0000000000..d3bb68396e --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/queryKeySerializer.gen.ts @@ -0,0 +1,136 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * JSON-friendly union that mirrors what Pinia Colada can hash. + */ +export type JsonValue = + | null + | string + | number + | boolean + | JsonValue[] + | { [key: string]: JsonValue }; + +/** + * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes. + */ +export const queryKeyJsonReplacer = (_key: string, value: unknown) => { + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + if (typeof value === 'bigint') { + return value.toString(); + } + if (value instanceof Date) { + return value.toISOString(); + } + return value; +}; + +/** + * Safely stringifies a value and parses it back into a JsonValue. + */ +export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => { + try { + const json = JSON.stringify(input, queryKeyJsonReplacer); + if (json === undefined) { + return undefined; + } + return JSON.parse(json) as JsonValue; + } catch { + return undefined; + } +}; + +/** + * Detects plain objects (including objects with a null prototype). + */ +const isPlainObject = (value: unknown): value is Record => { + if (value === null || typeof value !== 'object') { + return false; + } + const prototype = Object.getPrototypeOf(value as object); + return prototype === Object.prototype || prototype === null; +}; + +/** + * Turns URLSearchParams into a sorted JSON object for deterministic keys. + */ +const serializeSearchParams = (params: URLSearchParams): JsonValue => { + const entries = Array.from(params.entries()).sort(([a], [b]) => + a.localeCompare(b), + ); + const result: Record = {}; + + for (const [key, value] of entries) { + const existing = result[key]; + if (existing === undefined) { + result[key] = value; + continue; + } + + if (Array.isArray(existing)) { + (existing as string[]).push(value); + } else { + result[key] = [existing, value]; + } + } + + return result; +}; + +/** + * Normalizes any accepted value into a JSON-friendly shape for query keys. + */ +export const serializeQueryKeyValue = ( + value: unknown, +): JsonValue | undefined => { + if (value === null) { + return null; + } + + if ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) { + return value; + } + + if ( + value === undefined || + typeof value === 'function' || + typeof value === 'symbol' + ) { + return undefined; + } + + if (typeof value === 'bigint') { + return value.toString(); + } + + if (value instanceof Date) { + return value.toISOString(); + } + + if (Array.isArray(value)) { + return stringifyToJsonValue(value); + } + + if ( + typeof URLSearchParams !== 'undefined' && + value instanceof URLSearchParams + ) { + return serializeSearchParams(value); + } + + if (isPlainObject(value)) { + return stringifyToJsonValue(value); + } + + return undefined; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/serverSentEvents.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/serverSentEvents.gen.ts new file mode 100644 index 0000000000..f8fd78e284 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/serverSentEvents.gen.ts @@ -0,0 +1,264 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen'; + +export type ServerSentEventsOptions = Omit< + RequestInit, + 'method' +> & + Pick & { + /** + * Fetch API implementation. You can use this option to provide a custom + * fetch instance. + * + * @default globalThis.fetch + */ + fetch?: typeof fetch; + /** + * Implementing clients can call request interceptors inside this hook. + */ + onRequest?: (url: string, init: RequestInit) => Promise; + /** + * Callback invoked when a network or parsing error occurs during streaming. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param error The error that occurred. + */ + onSseError?: (error: unknown) => void; + /** + * Callback invoked when an event is streamed from the server. + * + * This option applies only if the endpoint returns a stream of events. + * + * @param event Event streamed from the server. + * @returns Nothing (void). + */ + onSseEvent?: (event: StreamEvent) => void; + serializedBody?: RequestInit['body']; + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number; + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number; + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number; + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise; + url: string; + }; + +export interface StreamEvent { + data: TData; + event?: string; + id?: string; + retry?: number; +} + +export type ServerSentEventsResult< + TData = unknown, + TReturn = void, + TNext = unknown, +> = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + >; +}; + +export const createSseClient = ({ + onRequest, + onSseError, + onSseEvent, + responseTransformer, + responseValidator, + sseDefaultRetryDelay, + sseMaxRetryAttempts, + sseMaxRetryDelay, + sseSleepFn, + url, + ...options +}: ServerSentEventsOptions): ServerSentEventsResult => { + let lastEventId: string | undefined; + + const sleep = + sseSleepFn ?? + ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms))); + + const createStream = async function* () { + let retryDelay: number = sseDefaultRetryDelay ?? 3000; + let attempt = 0; + const signal = options.signal ?? new AbortController().signal; + + while (true) { + if (signal.aborted) break; + + attempt++; + + const headers = + options.headers instanceof Headers + ? options.headers + : new Headers(options.headers as Record | undefined); + + if (lastEventId !== undefined) { + headers.set('Last-Event-ID', lastEventId); + } + + try { + const requestInit: RequestInit = { + redirect: 'follow', + ...options, + body: options.serializedBody, + headers, + signal, + }; + let request = new Request(url, requestInit); + if (onRequest) { + request = await onRequest(url, requestInit); + } + // fetch must be assigned here, otherwise it would throw the error: + // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation + const _fetch = options.fetch ?? globalThis.fetch; + const response = await _fetch(request); + + if (!response.ok) + throw new Error( + `SSE failed: ${response.status} ${response.statusText}`, + ); + + if (!response.body) throw new Error('No body in SSE response'); + + const reader = response.body + .pipeThrough(new TextDecoderStream()) + .getReader(); + + let buffer = ''; + + const abortHandler = () => { + try { + reader.cancel(); + } catch { + // noop + } + }; + + signal.addEventListener('abort', abortHandler); + + try { + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += value; + + 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/swr/fetch/core/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/types.gen.ts new file mode 100644 index 0000000000..643c070c9d --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/types.gen.ts @@ -0,0 +1,118 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen'; +import type { + BodySerializer, + QuerySerializer, + QuerySerializerOptions, +} from './bodySerializer.gen'; + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace'; + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never, +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn; + getConfig: () => Config; + request: RequestFn; + setConfig: (config: Config) => Config; +} & { + [K in HttpMethod]: MethodFn; +} & ([SseFn] extends [never] + ? { sse?: never } + : { sse: { [K in HttpMethod]: SseFn } }); + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken; + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null; + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined + | unknown + >; + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase; + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions; + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise; + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise; + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise; +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false; + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true + ? never + : K]: T[K]; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/utils.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/utils.gen.ts new file mode 100644 index 0000000000..0b5389d089 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/core/utils.gen.ts @@ -0,0 +1,143 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { BodySerializer, QuerySerializer } from './bodySerializer.gen'; +import { + type ArraySeparatorStyle, + serializeArrayParam, + serializeObjectParam, + serializePrimitiveParam, +} from './pathSerializer.gen'; + +export interface PathSerializer { + path: Record; + url: string; +} + +export const PATH_PARAM_RE = /\{[^{}]+\}/g; + +export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { + let url = _url; + const matches = _url.match(PATH_PARAM_RE); + if (matches) { + for (const match of matches) { + let explode = false; + let name = match.substring(1, match.length - 1); + let style: ArraySeparatorStyle = 'simple'; + + if (name.endsWith('*')) { + explode = true; + name = name.substring(0, name.length - 1); + } + + if (name.startsWith('.')) { + name = name.substring(1); + style = 'label'; + } else if (name.startsWith(';')) { + name = name.substring(1); + style = 'matrix'; + } + + const value = path[name]; + + if (value === undefined || value === null) { + continue; + } + + if (Array.isArray(value)) { + url = url.replace( + match, + serializeArrayParam({ explode, name, style, value }), + ); + continue; + } + + if (typeof value === 'object') { + url = url.replace( + match, + serializeObjectParam({ + explode, + name, + style, + value: value as Record, + valueOnly: true, + }), + ); + continue; + } + + if (style === 'matrix') { + url = url.replace( + match, + `;${serializePrimitiveParam({ + name, + value: value as string, + })}`, + ); + continue; + } + + const replaceValue = encodeURIComponent( + style === 'label' ? `.${value as string}` : (value as string), + ); + url = url.replace(match, replaceValue); + } + } + return url; +}; + +export const getUrl = ({ + baseUrl, + path, + query, + querySerializer, + url: _url, +}: { + baseUrl?: string; + path?: Record; + query?: Record; + querySerializer: QuerySerializer; + url: string; +}) => { + const pathUrl = _url.startsWith('/') ? _url : `/${_url}`; + let url = (baseUrl ?? '') + pathUrl; + if (path) { + url = defaultPathSerializer({ path, url }); + } + let search = query ? querySerializer(query) : ''; + if (search.startsWith('?')) { + search = search.substring(1); + } + if (search) { + url += `?${search}`; + } + return url; +}; + +export function getValidRequestBody(options: { + body?: unknown; + bodySerializer?: BodySerializer | null; + serializedBody?: unknown; +}) { + const hasBody = options.body !== undefined; + const isSerializedBody = hasBody && options.bodySerializer; + + if (isSerializedBody) { + if ('serializedBody' in options) { + const hasSerializedBody = + options.serializedBody !== undefined && options.serializedBody !== ''; + + return hasSerializedBody ? options.serializedBody : null; + } + + // not all clients implement a serializedBody property (i.e. client-axios) + return options.body !== '' ? options.body : null; + } + + // plain/text body + if (hasBody) { + return options.body; + } + + // no body was provided + return undefined; +} diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/index.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/index.ts new file mode 100644 index 0000000000..c352c1047a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type * from './types.gen'; +export * from './sdk.gen'; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/sdk.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/sdk.gen.ts new file mode 100644 index 0000000000..4166f8b7c0 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/sdk.gen.ts @@ -0,0 +1,418 @@ +// 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) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const patchApiVbyApiVersionNoTag = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const import_ = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/no+tag', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const fooWow = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/no+tag', + ...options + }); +}; + +export const apiVVersionODataControllerCount = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/simple/$count', + ...options + }); +}; + +export const getApiVbyApiVersionSimpleOperation = (options: Options) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/simple:operation', + ...options + }); +}; + +export const deleteCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const getCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const headCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).head({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const optionsCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).options({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const patchCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).patch({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const postCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const putCallWithoutParametersAndResponse = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/simple', + ...options + }); +}; + +export const deleteFoo = (options: Options) => { + return (options.client ?? client).delete({ + url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', + ...options + }); +}; + +export const callWithDescriptions = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/descriptions', + ...options + }); +}; + +/** + * @deprecated + */ +export const deprecatedCall = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/deprecated', + ...options + }); +}; + +export const callWithParameters = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters/{parameterPath}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const callWithWeirdParameterNames = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const postCallWithOptionalParam = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/parameters', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }); +}; + +export const postApiVbyApiVersionRequestBody = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/requestBody', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options?.headers + } + }); +}; + +export const postApiVbyApiVersionFormData = (options?: Options) => { + return (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/formData', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } + }); +}; + +export const callWithDefaultParameters = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callWithDefaultOptionalParameters = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const callToTestOrderOfParams = (options: Options) => { + return (options.client ?? client).put({ + url: '/api/v{api-version}/defaults', + ...options + }); +}; + +export const duplicateName = (options?: Options) => { + return (options?.client ?? client).delete({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName2 = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName3 = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const duplicateName4 = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/duplicate', + ...options + }); +}; + +export const callWithNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/no-content', + ...options + }); +}; + +export const callWithResponseAndNoContentResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/response-and-no-content', + ...options + }); +}; + +export const dummyA = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/a', + ...options + }); +}; + +export const dummyB = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multiple-tags/b', + ...options + }); +}; + +export const callWithResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithDuplicateResponses = (options?: Options) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const callWithResponses = (options?: Options) => { + return (options?.client ?? client).put({ + url: '/api/v{api-version}/response', + ...options + }); +}; + +export const collectionFormat = (options: Options) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/collectionFormat', + ...options + }); +}; + +export const types = (options: Options) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/types', + ...options + }); +}; + +export const uploadFile = (options: Options) => { + return (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) => { + return (options.client ?? client).get({ + url: '/api/v{api-version}/file/{id}', + ...options + }); +}; + +export const complexTypes = (options: Options) => { + return (options.client ?? client).get({ + querySerializer: { + parameters: { + parameterObject: { + object: { + style: 'form' + } + } + } + }, + url: '/api/v{api-version}/complex', + ...options + }); +}; + +export const multipartResponse = (options?: Options) => { + return (options?.client ?? client).get({ + url: '/api/v{api-version}/multipart', + ...options + }); +}; + +export const multipartRequest = (options?: Options) => { + return (options?.client ?? client).post({ + ...formDataBodySerializer, + url: '/api/v{api-version}/multipart', + ...options, + headers: { + 'Content-Type': null, + ...options?.headers + } + }); +}; + +export const complexParams = (options: Options) => { + return (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) => { + return (options?.client ?? client).post({ + url: '/api/v{api-version}/header', + ...options + }); +}; + +export const testErrorCode = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/error', + ...options + }); +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串 = (options: Options) => { + return (options.client ?? client).post({ + url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + ...options + }); +}; + +/** + * Login User + */ +export const putWithFormUrlEncoded = (options: Options) => { + return (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/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts new file mode 100644 index 0000000000..1fb85af58b --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts @@ -0,0 +1,999 @@ +// This file is auto-generated by @hey-api/openapi-ts + +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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData } from './types.gen'; + +export const exportKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no+tag' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const exportOptions = (options?: Options) => { + return { + key: exportKey(options), + fetcher: async () => { + const { data } = await export_({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const importMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await import_({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fooWowMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/no+tag', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const apiVVersionODataControllerCountKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple/$count' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const apiVVersionODataControllerCountOptions = (options?: Options) => { + return { + key: apiVVersionODataControllerCountKey(options), + fetcher: async () => { + const { data } = await apiVVersionODataControllerCount({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple:operation' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => { + return { + key: getApiVbyApiVersionSimpleOperationKey(options), + fetcher: async () => { + const { data } = await getApiVbyApiVersionSimpleOperation({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/simple' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { + return { + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/simple', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const deleteFooMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deleteFoo({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDescriptionsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/descriptions', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * @deprecated + */ +export const deprecatedCallMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/deprecated', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await deprecatedCall({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameterPath}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithWeirdParameterNamesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithOptionalParamKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/parameters' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const getCallWithOptionalParamOptions = (options: Options) => { + return { + key: getCallWithOptionalParamKey(options), + fetcher: async () => { + const { data } = await getCallWithOptionalParam({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const getCallWithOptionalParamInfinite = (options: Options) => { + return { + getKey: (pageIndex: number, previousPageData: any) => { + const pageParam = { + query: { + page: pageIndex + } + }; + const key: any[] = [ + '/api/v{api-version}/parameters' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + const mergedQuery = { ...options?.query, ...pageParam.query }; + key.push({ query: mergedQuery }); + if (options?.body) { + key.push({ body: options.body }); + } + return key; + }, + fetcher: async (key) => { + const params = Object.assign({}, ...key.slice(1)); + const { data } = await getCallWithOptionalParam({ + ...params, + throwOnError: true + }); + return data; + } + }; +}; + +export const postCallWithOptionalParamMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/parameters', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/requestBody', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const postApiVbyApiVersionFormDataMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/formData', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultParametersKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/defaults' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithDefaultParametersOptions = (options?: Options) => { + return { + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callToTestOrderOfParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/defaults', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateNameMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName2Key = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/duplicate' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const duplicateName2Options = (options?: Options) => { + return { + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName3Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const duplicateName4Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/duplicate', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithNoContentResponseOptions = (options?: Options) => { + return { + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/response-and-no-content' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { + return { + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyAKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/a' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyAOptions = (options?: Options) => { + return { + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const dummyBKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multiple-tags/b' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const dummyBOptions = (options?: Options) => { + return { + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/response' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const callWithResponseOptions = (options?: Options) => { + return { + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithDuplicateResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResponsesMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/response', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const collectionFormatKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/collectionFormat' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const collectionFormatOptions = (options: Options) => { + return { + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const typesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/types' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const typesOptions = (options: Options) => { + return { + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const uploadFileMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/upload', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const fileResponseKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/file/{id}' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const fileResponseOptions = (options: Options) => { + return { + key: fileResponseKey(options), + fetcher: async () => { + const { data } = await fileResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexTypesKey = (options: Options) => { + const key: any[] = [ + '/api/v{api-version}/complex' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const complexTypesOptions = (options: Options) => { + return { + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const multipartResponseKey = (options?: Options) => { + const key: any[] = [ + '/api/v{api-version}/multipart' + ]; + if (options?.path) { + key.push({ path: options.path }); + } + if (options?.query) { + key.push({ query: options.query }); + } + if (options?.body) { + key.push({ body: options.body }); + } + return key; +}; + +export const multipartResponseOptions = (options?: Options) => { + return { + key: multipartResponseKey(options), + fetcher: async () => { + const { data } = await multipartResponse({ + ...options, + throwOnError: true + }); + return data; + } + }; +}; + +export const multipartRequestMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/multipart', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await multipartRequest({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const complexParamsMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/complex/{id}', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await complexParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const callWithResultFromHeaderMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/header', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const testErrorCodeMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/error', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; + +/** + * Login User + */ +export const putWithFormUrlEncodedMutation = (options?: Options) => { + return { + key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', + fetcher: async (_key: unknown, { arg }: { + arg: Options; + }) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } + }; +}; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/types.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/types.gen.ts new file mode 100644 index 0000000000..3cdf939bbb --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/types.gen.ts @@ -0,0 +1,2091 @@ +// 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 = ExternalSharedExternalSharedModel; + +/** + * External ref to shared model (B) + */ +export type ExternalRefB = ExternalSharedExternalSharedModel; + +/** + * 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; +}; + +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 | string | undefined; +}; + +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; +}; + +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 ExternalSharedExternalSharedModel = { + 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; +}; + +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/src/plugins/@hey-api/client-axios/bundle/client.ts b/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/client.ts index fcbbfea0bf..5e7bbf203e 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/client.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/client.ts @@ -74,6 +74,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-core/__tests__/serverSentEvents.test.ts b/packages/openapi-ts/src/plugins/@hey-api/client-core/__tests__/serverSentEvents.test.ts index 26802d9362..c7e7db1df5 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-core/__tests__/serverSentEvents.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-core/__tests__/serverSentEvents.test.ts @@ -451,6 +451,7 @@ describe('createSseClient', () => { stream[Symbol.asyncIterator](); // pull all events until done + // eslint-disable-next-line @typescript-eslint/no-unused-vars for await (const _ of stream) { /* noop */ From b31e88f68cc6bcb333638940a7751bad7dc7ecf9 Mon Sep 17 00:00:00 2001 From: Pewww Date: Wed, 12 Nov 2025 14:49:21 +0900 Subject: [PATCH 4/9] fix: re-design swr plugin structure --- examples/openapi-ts-swr/src/App.tsx | 170 ++++++++- examples/openapi-ts-swr/src/client/swr.gen.ts | 218 ++++------- packages/openapi-ts/src/plugins/swr/config.ts | 1 + packages/openapi-ts/src/plugins/swr/plugin.ts | 82 +--- .../src/plugins/swr/swrInfiniteOptions.ts | 352 ------------------ packages/openapi-ts/src/plugins/swr/swrKey.ts | 214 ----------- .../src/plugins/swr/swrMutationOptions.ts | 172 --------- .../openapi-ts/src/plugins/swr/swrOptions.ts | 162 -------- .../openapi-ts/src/plugins/swr/types.d.ts | 12 + .../openapi-ts/src/plugins/swr/v2/plugin.ts | 86 +++++ .../src/plugins/swr/v2/swrInfiniteOptions.ts | 297 +++++++++++++++ .../openapi-ts/src/plugins/swr/v2/swrKey.ts | 157 ++++++++ .../src/plugins/swr/v2/swrMutationOptions.ts | 162 ++++++++ .../src/plugins/swr/v2/swrOptions.ts | 134 +++++++ 14 files changed, 1082 insertions(+), 1137 deletions(-) delete mode 100644 packages/openapi-ts/src/plugins/swr/swrInfiniteOptions.ts delete mode 100644 packages/openapi-ts/src/plugins/swr/swrKey.ts delete mode 100644 packages/openapi-ts/src/plugins/swr/swrMutationOptions.ts delete mode 100644 packages/openapi-ts/src/plugins/swr/swrOptions.ts create mode 100644 packages/openapi-ts/src/plugins/swr/v2/plugin.ts create mode 100644 packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts create mode 100644 packages/openapi-ts/src/plugins/swr/v2/swrKey.ts create mode 100644 packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts create mode 100644 packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts diff --git a/examples/openapi-ts-swr/src/App.tsx b/examples/openapi-ts-swr/src/App.tsx index 7e31788892..5613dfb393 100644 --- a/examples/openapi-ts-swr/src/App.tsx +++ b/examples/openapi-ts-swr/src/App.tsx @@ -21,11 +21,17 @@ import useSWRMutation from 'swr/mutation'; import { createClient } from './client/client'; import { PetSchema } from './client/schemas.gen'; +import { getInventory } from './client/sdk.gen'; import { addPetMutation, + findPetsByStatusKey, + findPetsByStatusOptions, + getInventoryKey, getPetByIdOptions, + loginUserKey, updatePetMutation, } from './client/swr.gen'; +// import { getPetByIdKey } from './client/swr.gen'; // For Pattern 2 example import type { Pet } from './client/types.gen'; const localClient = createClient({ @@ -59,8 +65,12 @@ function App() { const [pet, setPet] = useState(); const [petId, setPetId] = useState(); const [isRequiredNameError, setIsRequiredNameError] = useState(false); + const [showAdvancedExamples, setShowAdvancedExamples] = useState(false); - // Mutations + // ============================================================================ + // Mutations - using the generated mutation options + // ============================================================================ + // The mutation options provide the key and fetcher following SWR best practices const { fetcher: addPetFetcher, key: addPetKey } = addPetMutation(); const addPet = useSWRMutation(addPetKey, addPetFetcher, { onError: (error) => { @@ -83,7 +93,11 @@ function App() { }, }); - // Query - only fetch if petId is set + // ============================================================================ + // Pattern 1: Using Options (Recommended for most cases) + // ============================================================================ + // The options provide both key and fetcher in the correct format + // Conditional fetching is controlled by passing null to useSWR const petOptions = petId ? getPetByIdOptions({ client: localClient, @@ -98,6 +112,75 @@ function App() { petOptions?.fetcher ?? null, ); + // ============================================================================ + // Pattern 2: Using Key function directly (for custom fetchers) + // ============================================================================ + // Key functions always return a valid key array, never null + // This gives you full control over the fetcher while maintaining cache consistency + // + // Example (disabled to avoid duplicate requests): + // const petByIdKey = petId ? getPetByIdKey({ path: { petId } }) : null; + // const { data: customFetchedPet } = useSWR(petByIdKey, async (key) => { + // if (!key) return null; + // // Custom fetch logic here - you can add transforms, error handling, etc. + // console.log('Fetching with key:', key); + // const response = await fetch(`/api/pet/${key[1]}`); + // return response.json(); + // }); + + // ============================================================================ + // Pattern 3: Optional parameters with optional chaining + // ============================================================================ + // When options are optional, keys use optional chaining (options?.query) + // This is safe and always returns a valid key + const inventoryKey = getInventoryKey(); // No params needed + const { data: inventory } = useSWR( + showAdvancedExamples ? inventoryKey : null, + async () => { + // Custom fetcher - you control the implementation + const { data } = await getInventory({ + client: localClient, + throwOnError: true, + }); + return data; + }, + ); + + // ============================================================================ + // Pattern 4: Required parameters + // ============================================================================ + // When parameters are required, options must be provided + // The key function directly accesses options.query without optional chaining + const petsByStatusKey = findPetsByStatusKey({ + query: { status: 'available' }, + }); + + // Or use the full options for convenience + const { fetcher: petsByStatusFetcher, key: petsByStatusKey2 } = + findPetsByStatusOptions({ + client: localClient, + query: { status: 'available' }, + }); + + const { data: availablePets } = useSWR( + showAdvancedExamples ? petsByStatusKey2 : null, + showAdvancedExamples ? petsByStatusFetcher : null, + ); + + // ============================================================================ + // Pattern 5: Demonstrating key equality for cache consistency + // ============================================================================ + // Keys with the same parameters will have the same cache entry + // This is a core SWR v2 improvement - primitive values in key arrays + const loginKey1 = loginUserKey({ + query: { password: 'pass', username: 'test' }, + }); + const loginKey2 = loginUserKey({ + query: { password: 'pass', username: 'test' }, + }); + // loginKey1 and loginKey2 will be treated as the same cache key by SWR + // because they have the same primitive values: ['/user/login', { username: 'test', password: 'pass' }] + const onAddPet = async (formData: FormData) => { // simple form field validation to demonstrate using schemas if (PetSchema.required.includes('name') && !formData.get('name')) { @@ -180,7 +263,10 @@ function App() { @hey-api/openapi-ts 🤝 SWR
+ + {/* Main Demo Section */} + Basic Usage Demo @@ -205,6 +291,66 @@ function App() { Get Random Pet + +
+ + {/* Advanced Examples Toggle */} + + + + {showAdvancedExamples && ( + + + SWR v2 Key Patterns + + + + Inventory (Optional params): + + + Key: {JSON.stringify(inventoryKey)} + + + Count:{' '} + {inventory ? Object.keys(inventory).length : 'Loading...'} + + + + + + Available Pets (Required params): + + + Key: {JSON.stringify(petsByStatusKey)} + + + Found: {availablePets?.length ?? 'Loading...'} pets + + + + + + Key Equality Demo: + + + Key 1: {JSON.stringify(loginKey1)} + + + Key 2: {JSON.stringify(loginKey2)} + + + ✓ These keys are equal and share the same cache + + + + + )} +
); } + + Note: The infinite options are only generated for operations that have + pagination configured in the OpenAPI spec. */} diff --git a/examples/openapi-ts-swr/src/client/swr.gen.ts b/examples/openapi-ts-swr/src/client/swr.gen.ts index 634b0c243d..adb6a24aee 100644 --- a/examples/openapi-ts-swr/src/client/swr.gen.ts +++ b/examples/openapi-ts-swr/src/client/swr.gen.ts @@ -51,7 +51,7 @@ import type { */ export const addPetMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string, { arg, }: { @@ -75,7 +75,7 @@ export const addPetMutation = (options?: Options) => ({ */ export const updatePetMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string, { arg, }: { @@ -92,19 +92,10 @@ export const updatePetMutation = (options?: Options) => ({ key: '/pet', }); -export const findPetsByStatusKey = (options: Options) => { - const key: any[] = ['/pet/findByStatus']; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +export const findPetsByStatusKey = (options: Options) => [ + '/pet/findByStatus', + options.query, +]; /** * Finds Pets by status. @@ -115,28 +106,16 @@ export const findPetsByStatusOptions = ( options: Options, ) => ({ fetcher: async () => { - const { data } = await findPetsByStatus({ - ...options, - throwOnError: true, - }); + const { data } = await findPetsByStatus({ ...options, throwOnError: true }); return data; }, key: findPetsByStatusKey(options), }); -export const findPetsByTagsKey = (options: Options) => { - const key: any[] = ['/pet/findByTags']; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +export const findPetsByTagsKey = (options: Options) => [ + '/pet/findByTags', + options.query, +]; /** * Finds Pets by tags. @@ -147,10 +126,7 @@ export const findPetsByTagsOptions = ( options: Options, ) => ({ fetcher: async () => { - const { data } = await findPetsByTags({ - ...options, - throwOnError: true, - }); + const { data } = await findPetsByTags({ ...options, throwOnError: true }); return data; }, key: findPetsByTagsKey(options), @@ -163,7 +139,7 @@ export const findPetsByTagsOptions = ( */ export const deletePetMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string | readonly [string, ...Array], { arg, }: { @@ -177,22 +153,13 @@ export const deletePetMutation = (options?: Options) => ({ }); return data; }, - key: '/pet/{petId}', + key: options?.path ? ['/pet/{petId}', options.path.petId] : '/pet/{petId}', }); -export const getPetByIdKey = (options: Options) => { - const key: any[] = ['/pet/{petId}']; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +export const getPetByIdKey = (options: Options) => [ + '/pet/{petId}', + options.path.petId, +]; /** * Find pet by ID. @@ -201,10 +168,7 @@ export const getPetByIdKey = (options: Options) => { */ export const getPetByIdOptions = (options: Options) => ({ fetcher: async () => { - const { data } = await getPetById({ - ...options, - throwOnError: true, - }); + const { data } = await getPetById({ ...options, throwOnError: true }); return data; }, key: getPetByIdKey(options), @@ -219,7 +183,7 @@ export const updatePetWithFormMutation = ( options?: Options, ) => ({ fetcher: async ( - _key: unknown, + _key: string | readonly [string, ...Array], { arg, }: { @@ -233,7 +197,7 @@ export const updatePetWithFormMutation = ( }); return data; }, - key: '/pet/{petId}', + key: options?.path ? ['/pet/{petId}', options.path.petId] : '/pet/{petId}', }); /** @@ -243,7 +207,7 @@ export const updatePetWithFormMutation = ( */ export const uploadFileMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string | readonly [string, ...Array], { arg, }: { @@ -257,22 +221,15 @@ export const uploadFileMutation = (options?: Options) => ({ }); return data; }, - key: '/pet/{petId}/uploadImage', + key: options?.path + ? ['/pet/{petId}/uploadImage', options.path.petId] + : '/pet/{petId}/uploadImage', }); -export const getInventoryKey = (options?: Options) => { - const key: any[] = ['/store/inventory']; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +export const getInventoryKey = (options?: Options) => [ + '/store/inventory', + options?.query, +]; /** * Returns pet inventories by status. @@ -281,10 +238,7 @@ export const getInventoryKey = (options?: Options) => { */ export const getInventoryOptions = (options?: Options) => ({ fetcher: async () => { - const { data } = await getInventory({ - ...options, - throwOnError: true, - }); + const { data } = await getInventory({ ...options, throwOnError: true }); return data; }, key: getInventoryKey(options), @@ -297,7 +251,7 @@ export const getInventoryOptions = (options?: Options) => ({ */ export const placeOrderMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string, { arg, }: { @@ -321,7 +275,7 @@ export const placeOrderMutation = (options?: Options) => ({ */ export const deleteOrderMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string | readonly [string, ...Array], { arg, }: { @@ -335,22 +289,15 @@ export const deleteOrderMutation = (options?: Options) => ({ }); return data; }, - key: '/store/order/{orderId}', + key: options?.path + ? ['/store/order/{orderId}', options.path.orderId] + : '/store/order/{orderId}', }); -export const getOrderByIdKey = (options: Options) => { - const key: any[] = ['/store/order/{orderId}']; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +export const getOrderByIdKey = (options: Options) => [ + '/store/order/{orderId}', + options.path.orderId, +]; /** * Find purchase order by ID. @@ -359,10 +306,7 @@ export const getOrderByIdKey = (options: Options) => { */ export const getOrderByIdOptions = (options: Options) => ({ fetcher: async () => { - const { data } = await getOrderById({ - ...options, - throwOnError: true, - }); + const { data } = await getOrderById({ ...options, throwOnError: true }); return data; }, key: getOrderByIdKey(options), @@ -375,7 +319,7 @@ export const getOrderByIdOptions = (options: Options) => ({ */ export const createUserMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string, { arg, }: { @@ -401,7 +345,7 @@ export const createUsersWithListInputMutation = ( options?: Options, ) => ({ fetcher: async ( - _key: unknown, + _key: string, { arg, }: { @@ -418,19 +362,10 @@ export const createUsersWithListInputMutation = ( key: '/user/createWithList', }); -export const loginUserKey = (options?: Options) => { - const key: any[] = ['/user/login']; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +export const loginUserKey = (options?: Options) => [ + '/user/login', + options?.query, +]; /** * Logs user into the system. @@ -439,28 +374,16 @@ export const loginUserKey = (options?: Options) => { */ export const loginUserOptions = (options?: Options) => ({ fetcher: async () => { - const { data } = await loginUser({ - ...options, - throwOnError: true, - }); + const { data } = await loginUser({ ...options, throwOnError: true }); return data; }, key: loginUserKey(options), }); -export const logoutUserKey = (options?: Options) => { - const key: any[] = ['/user/logout']; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +export const logoutUserKey = (options?: Options) => [ + '/user/logout', + options?.query, +]; /** * Logs out current logged in user session. @@ -469,10 +392,7 @@ export const logoutUserKey = (options?: Options) => { */ export const logoutUserOptions = (options?: Options) => ({ fetcher: async () => { - const { data } = await logoutUser({ - ...options, - throwOnError: true, - }); + const { data } = await logoutUser({ ...options, throwOnError: true }); return data; }, key: logoutUserKey(options), @@ -485,7 +405,7 @@ export const logoutUserOptions = (options?: Options) => ({ */ export const deleteUserMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string | readonly [string, ...Array], { arg, }: { @@ -499,22 +419,15 @@ export const deleteUserMutation = (options?: Options) => ({ }); return data; }, - key: '/user/{username}', + key: options?.path + ? ['/user/{username}', options.path.username] + : '/user/{username}', }); -export const getUserByNameKey = (options: Options) => { - const key: any[] = ['/user/{username}']; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +export const getUserByNameKey = (options: Options) => [ + '/user/{username}', + options.path.username, +]; /** * Get user by user name. @@ -523,10 +436,7 @@ export const getUserByNameKey = (options: Options) => { */ export const getUserByNameOptions = (options: Options) => ({ fetcher: async () => { - const { data } = await getUserByName({ - ...options, - throwOnError: true, - }); + const { data } = await getUserByName({ ...options, throwOnError: true }); return data; }, key: getUserByNameKey(options), @@ -539,7 +449,7 @@ export const getUserByNameOptions = (options: Options) => ({ */ export const updateUserMutation = (options?: Options) => ({ fetcher: async ( - _key: unknown, + _key: string | readonly [string, ...Array], { arg, }: { @@ -553,5 +463,7 @@ export const updateUserMutation = (options?: Options) => ({ }); return data; }, - key: '/user/{username}', + key: options?.path + ? ['/user/{username}', options.path.username] + : '/user/{username}', }); diff --git a/packages/openapi-ts/src/plugins/swr/config.ts b/packages/openapi-ts/src/plugins/swr/config.ts index e640be147e..33f3be339c 100644 --- a/packages/openapi-ts/src/plugins/swr/config.ts +++ b/packages/openapi-ts/src/plugins/swr/config.ts @@ -18,6 +18,7 @@ export const defaultConfig: SwrPlugin['Config'] = { defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, + exported: true, name: '{{name}}Key', }, mappers: { diff --git a/packages/openapi-ts/src/plugins/swr/plugin.ts b/packages/openapi-ts/src/plugins/swr/plugin.ts index b63ced8717..0bdd89f7d1 100644 --- a/packages/openapi-ts/src/plugins/swr/plugin.ts +++ b/packages/openapi-ts/src/plugins/swr/plugin.ts @@ -1,86 +1,10 @@ -import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation'; -import { stringCase } from '~/utils/stringCase'; - -import { createSwrInfiniteOptions } from './swrInfiniteOptions'; -import { createSwrMutationOptions } from './swrMutationOptions'; -import { createSwrOptions } from './swrOptions'; import type { PluginHandler } from './types'; +import { handlerV2 } from './v2/plugin'; /** * Main handler for the SWR plugin. * * This plugin generates useSWR and useSWRMutation options for each operation. - * It follows a similar pattern to TanStack Query but adapted for SWR's API. + * It follows SWR's official recommended patterns for key design and data fetching. */ -export const handler: PluginHandler = ({ plugin }) => { - // Register external symbols from axios (for error types) - plugin.registerSymbol({ - external: 'axios', - kind: 'type', - meta: { - category: 'external', - resource: 'axios.AxiosError', - }, - name: 'AxiosError', - }); - - const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); - - // Iterate over all operations - plugin.forEach( - 'operation', - ({ operation }) => { - // Get the SDK function name - const classes = sdkPlugin.config.asClass - ? operationClasses({ - context: plugin.context, - operation, - plugin: sdkPlugin, - }) - : undefined; - const entry = classes ? classes.values().next().value : undefined; - const sdkFn = entry - ? [ - plugin.referenceSymbol({ - category: 'utility', - resource: 'class', - resourceId: entry.path[0], - tool: 'sdk', - }).placeholder, - ...entry.path.slice(1).map((className) => - stringCase({ - case: 'camelCase', - value: className, - }), - ), - entry.methodName, - ] - .filter(Boolean) - .join('.') - : plugin.referenceSymbol({ - category: 'sdk', - resource: 'operation', - resourceId: operation.id, - }).placeholder; - - // Generate appropriate SWR functions based on operation type - if (plugin.hooks.operation.isQuery(operation)) { - if (plugin.config.swrOptions.enabled) { - createSwrOptions({ operation, plugin, sdkFn }); - } - if (plugin.config.swrInfiniteOptions.enabled) { - createSwrInfiniteOptions({ operation, plugin, sdkFn }); - } - } - - if (plugin.hooks.operation.isMutation(operation)) { - if (plugin.config.swrMutationOptions.enabled) { - createSwrMutationOptions({ operation, plugin, sdkFn }); - } - } - }, - { - order: 'declarations', - }, - ); -}; +export const handler: PluginHandler = handlerV2; diff --git a/packages/openapi-ts/src/plugins/swr/swrInfiniteOptions.ts b/packages/openapi-ts/src/plugins/swr/swrInfiniteOptions.ts deleted file mode 100644 index cd7f0d7595..0000000000 --- a/packages/openapi-ts/src/plugins/swr/swrInfiniteOptions.ts +++ /dev/null @@ -1,352 +0,0 @@ -import type ts from 'typescript'; - -import { operationPagination } from '~/ir/operation'; -import type { IR } from '~/ir/types'; -import { buildName } from '~/openApi/shared/utils/name'; -import { - createOperationComment, - hasOperationSse, - isOperationOptionsRequired, -} from '~/plugins/shared/utils/operation'; -import { tsc } from '~/tsc'; - -import type { PluginInstance } from './types'; -import { useTypeData } from './useType'; - -const optionsParamName = 'options'; - -/** - * Create useSWRInfinite options for a given operation. - * - * This generates a function that returns an object with: - * - getKey: A function that generates keys for each page - * - fetcher: Async function that fetches a single page - * - * Example output: - * export const getUsersInfinite = (options?: GetUsersOptions) => ({ - * getKey: (pageIndex: number, previousPageData: any) => { - * if (previousPageData && !previousPageData.hasMore) return null; - * return ['/users', { ...options, page: pageIndex }]; - * }, - * fetcher: async (key) => { - * const [, params] = key; - * const { data } = await getUsers({ - * ...params, - * throwOnError: true, - * }); - * return data; - * }, - * }); - */ -export const createSwrInfiniteOptions = ({ - operation, - plugin, - sdkFn, -}: { - operation: IR.OperationObject; - plugin: PluginInstance; - sdkFn: string; -}): void => { - if (hasOperationSse({ operation })) { - return; - } - - // Check if this operation supports pagination - const pagination = operationPagination({ - context: plugin.context, - operation, - }); - - // Only generate infinite options for operations with pagination - if (!pagination) { - return; - } - - const isRequiredOptions = isOperationOptionsRequired({ - context: plugin.context, - operation, - }); - - const typeData = useTypeData({ operation, plugin }); - - // Create the getKey function - // getKey: (pageIndex: number, previousPageData: any) => key | null - // Returns a flat array: ['/path', { path: ... }, { query: ... }, { body: ... }] - const getKeyFunction = tsc.arrowFunction({ - multiLine: true, - parameters: [ - { - name: 'pageIndex', - type: tsc.typeReferenceNode({ typeName: 'number' }), - }, - { - name: 'previousPageData', - type: tsc.typeReferenceNode({ typeName: 'any' }), - }, - ], - statements: [ - // Create page parameter object - tsc.constVariable({ - expression: tsc.objectExpression({ - multiLine: true, - obj: [ - { - key: pagination.in, - value: tsc.objectExpression({ - obj: [ - { - key: pagination.name, - value: tsc.identifier({ text: 'pageIndex' }), - }, - ], - }), - }, - ], - }), - name: 'pageParam', - }), - // Build key array similar to swrKey - tsc.constVariable({ - expression: tsc.arrayLiteralExpression({ - elements: [tsc.stringLiteral({ text: operation.path })], - }), - name: 'key', - typeName: tsc.typeReferenceNode({ typeName: 'any[]' }), - }), - // Add path parameters if they exist - tsc.ifStatement({ - expression: tsc.propertyAccessExpression({ - expression: tsc.identifier({ text: 'options' }), - isOptional: true, - name: tsc.identifier({ text: 'path' }), - }), - thenStatement: tsc.block({ - statements: [ - tsc.expressionToStatement({ - expression: tsc.callExpression({ - functionName: tsc.propertyAccessExpression({ - expression: 'key', - name: 'push', - }), - parameters: [ - tsc.objectExpression({ - multiLine: false, - obj: [ - { - key: 'path', - value: tsc.propertyAccessExpression({ - expression: 'options', - name: 'path', - }), - }, - ], - }), - ], - }), - }), - ], - }), - }), - // Add query parameters (merged with pageParam) - tsc.constVariable({ - expression: tsc.objectExpression({ - multiLine: false, - obj: [ - { - spread: tsc.propertyAccessExpression({ - expression: 'options', - isOptional: true, - name: 'query', - }), - }, - { - spread: tsc.propertyAccessExpression({ - expression: 'pageParam', - name: pagination.in, - }), - }, - ], - }), - name: 'mergedQuery', - }), - tsc.expressionToStatement({ - expression: tsc.callExpression({ - functionName: tsc.propertyAccessExpression({ - expression: 'key', - name: 'push', - }), - parameters: [ - tsc.objectExpression({ - multiLine: false, - obj: [ - { - key: 'query', - value: tsc.identifier({ text: 'mergedQuery' }), - }, - ], - }), - ], - }), - }), - // Add body if it exists - tsc.ifStatement({ - expression: tsc.propertyAccessExpression({ - expression: tsc.identifier({ text: 'options' }), - isOptional: true, - name: tsc.identifier({ text: 'body' }), - }), - thenStatement: tsc.block({ - statements: [ - tsc.expressionToStatement({ - expression: tsc.callExpression({ - functionName: tsc.propertyAccessExpression({ - expression: 'key', - name: 'push', - }), - parameters: [ - tsc.objectExpression({ - multiLine: false, - obj: [ - { - key: 'body', - value: tsc.propertyAccessExpression({ - expression: 'options', - name: 'body', - }), - }, - ], - }), - ], - }), - }), - ], - }), - }), - // return key - tsc.returnStatement({ - expression: tsc.identifier({ text: 'key' }), - }), - ], - }); - - // Create the fetcher function - // fetcher: async (key) => { ... } - // key structure: ['/path', { path: ... }, { query: ... }, { body: ... }] - // Merge all objects after the first element (path string) - - const fetcherStatements: Array = []; - - // Create params variable by merging all objects in the key array (excluding the first path string) - fetcherStatements.push( - tsc.constVariable({ - expression: tsc.identifier({ - text: 'Object.assign({}, ...key.slice(1))', - }), - name: 'params', - }), - ); - - const awaitSdkExpression = tsc.awaitExpression({ - expression: tsc.callExpression({ - functionName: sdkFn, - parameters: [ - tsc.objectExpression({ - multiLine: true, - obj: [ - { - spread: 'params', - }, - { - key: 'throwOnError', - value: true, - }, - ], - }), - ], - }), - }); - - if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { - fetcherStatements.push( - tsc.returnVariable({ - expression: awaitSdkExpression, - }), - ); - } else { - fetcherStatements.push( - tsc.constVariable({ - destructure: true, - expression: awaitSdkExpression, - name: 'data', - }), - tsc.returnVariable({ - expression: 'data', - }), - ); - } - - const fetcherFunction = tsc.arrowFunction({ - async: true, - multiLine: true, - parameters: [ - { - name: 'key', - }, - ], - statements: fetcherStatements, - }); - - // Build the infinite options object - const swrInfiniteOptionsObj = tsc.objectExpression({ - obj: [ - { - key: 'getKey', - value: getKeyFunction, - }, - { - key: 'fetcher', - value: fetcherFunction, - }, - ], - }); - - // Register the infinite options symbol - const symbolSwrInfiniteOptionsFn = plugin.registerSymbol({ - exported: plugin.config.swrInfiniteOptions.exported, - meta: { - category: 'hook', - resource: 'operation', - resourceId: operation.id, - role: 'swrInfiniteOptions', - tool: plugin.name, - }, - name: buildName({ - config: plugin.config.swrInfiniteOptions, - name: operation.id, - }), - }); - - const statement = tsc.constVariable({ - comment: plugin.config.comments - ? createOperationComment({ operation }) - : undefined, - exportConst: symbolSwrInfiniteOptionsFn.exported, - expression: tsc.arrowFunction({ - parameters: [ - { - isRequired: isRequiredOptions, - name: optionsParamName, - type: typeData, - }, - ], - statements: [ - tsc.returnStatement({ - expression: swrInfiniteOptionsObj, - }), - ], - }), - name: symbolSwrInfiniteOptionsFn.placeholder, - }); - - plugin.setSymbolValue(symbolSwrInfiniteOptionsFn, statement); -}; diff --git a/packages/openapi-ts/src/plugins/swr/swrKey.ts b/packages/openapi-ts/src/plugins/swr/swrKey.ts deleted file mode 100644 index 4c6d0ca295..0000000000 --- a/packages/openapi-ts/src/plugins/swr/swrKey.ts +++ /dev/null @@ -1,214 +0,0 @@ -import type { Symbol } from '@hey-api/codegen-core'; - -import { hasOperationDataRequired } from '~/ir/operation'; -import type { IR } from '~/ir/types'; -import { buildName } from '~/openApi/shared/utils/name'; -import { tsc } from '~/tsc'; - -import type { PluginInstance } from './types'; -import { useTypeData } from './useType'; - -/** - * Generate a SWR key statement for a given operation. - * - * For SWR, keys are structured to include only relevant fields (path, query, body) - * to ensure stable caching behavior. - * - * Example output: - * export const getUserByIdKey = (options: GetUserByIdOptions) => { - * const key: any[] = ['/api/users/{id}']; - * if (options?.path) key.push({ path: options.path }); - * if (options?.query) key.push({ query: options.query }); - * return key; - * } - */ -export const swrKeyStatement = ({ - operation, - plugin, - symbol, -}: { - operation: IR.OperationObject; - plugin: PluginInstance; - symbol: Symbol; -}) => { - const typeData = useTypeData({ operation, plugin }); - - // Build statements that conditionally add relevant fields to the key - const statements: Array = []; - - // Initialize key array with the operation path as identifier - statements.push( - tsc.constVariable({ - expression: tsc.arrayLiteralExpression({ - elements: [tsc.stringLiteral({ text: operation.path })], - }), - name: 'key', - typeName: tsc.typeReferenceNode({ typeName: 'any[]' }), - }), - ); - - // Add path parameters if they exist - statements.push( - tsc.ifStatement({ - expression: tsc.propertyAccessExpression({ - expression: tsc.identifier({ text: 'options' }), - isOptional: true, - name: tsc.identifier({ text: 'path' }), - }), - thenStatement: tsc.block({ - statements: [ - tsc.expressionToStatement({ - expression: tsc.callExpression({ - functionName: tsc.propertyAccessExpression({ - expression: 'key', - name: 'push', - }), - parameters: [ - tsc.objectExpression({ - multiLine: false, - obj: [ - { - key: 'path', - value: tsc.propertyAccessExpression({ - expression: 'options', - name: 'path', - }), - }, - ], - }), - ], - }), - }), - ], - }), - }), - ); - - // Add query parameters if they exist - statements.push( - tsc.ifStatement({ - expression: tsc.propertyAccessExpression({ - expression: tsc.identifier({ text: 'options' }), - isOptional: true, - name: tsc.identifier({ text: 'query' }), - }), - thenStatement: tsc.block({ - statements: [ - tsc.expressionToStatement({ - expression: tsc.callExpression({ - functionName: tsc.propertyAccessExpression({ - expression: 'key', - name: 'push', - }), - parameters: [ - tsc.objectExpression({ - multiLine: false, - obj: [ - { - key: 'query', - value: tsc.propertyAccessExpression({ - expression: 'options', - name: 'query', - }), - }, - ], - }), - ], - }), - }), - ], - }), - }), - ); - - // Add body if it exists - statements.push( - tsc.ifStatement({ - expression: tsc.propertyAccessExpression({ - expression: tsc.identifier({ text: 'options' }), - isOptional: true, - name: tsc.identifier({ text: 'body' }), - }), - thenStatement: tsc.block({ - statements: [ - tsc.expressionToStatement({ - expression: tsc.callExpression({ - functionName: tsc.propertyAccessExpression({ - expression: 'key', - name: 'push', - }), - parameters: [ - tsc.objectExpression({ - multiLine: false, - obj: [ - { - key: 'body', - value: tsc.propertyAccessExpression({ - expression: 'options', - name: 'body', - }), - }, - ], - }), - ], - }), - }), - ], - }), - }), - ); - - // Return the key array - statements.push( - tsc.returnStatement({ - expression: tsc.identifier({ text: 'key' }), - }), - ); - - const statement = tsc.constVariable({ - exportConst: symbol.exported, - expression: tsc.arrowFunction({ - multiLine: true, - parameters: [ - { - isRequired: hasOperationDataRequired(operation), - name: 'options', - type: typeData, - }, - ], - statements, - }), - name: symbol.placeholder, - }); - - return statement; -}; - -/** - * Register a SWR key symbol for a given operation. - */ -export const registerSwrKey = ({ - operation, - plugin, -}: { - operation: IR.OperationObject; - plugin: PluginInstance; -}): Symbol => { - const symbol = plugin.registerSymbol({ - exported: true, - name: buildName({ - config: plugin.config.swrKeys, - name: operation.id, - }), - }); - - const node = swrKeyStatement({ - operation, - plugin, - symbol, - }); - - plugin.setSymbolValue(symbol, node); - - return symbol; -}; diff --git a/packages/openapi-ts/src/plugins/swr/swrMutationOptions.ts b/packages/openapi-ts/src/plugins/swr/swrMutationOptions.ts deleted file mode 100644 index e2e2dfe0a2..0000000000 --- a/packages/openapi-ts/src/plugins/swr/swrMutationOptions.ts +++ /dev/null @@ -1,172 +0,0 @@ -import type ts from 'typescript'; - -import type { IR } from '~/ir/types'; -import { buildName } from '~/openApi/shared/utils/name'; -import { createOperationComment } from '~/plugins/shared/utils/operation'; -import { tsc } from '~/tsc'; - -import type { PluginInstance } from './types'; -import { useTypeData } from './useType'; - -const optionsParamName = 'options'; - -/** - * Create useSWRMutation options for a given operation. - * - * This generates a function that returns an object with: - * - key: The mutation key (usually the operation path) - * - fetcher: Async function that calls the SDK function with arg parameter - * - * Example output: - * export const createUserMutation = (options?: CreateUserOptions) => ({ - * key: '/api/users', - * fetcher: async (arg) => { - * const { data } = await createUser({ - * ...options, - * ...arg, - * throwOnError: true, - * }); - * return data; - * }, - * }); - */ -export const createSwrMutationOptions = ({ - operation, - plugin, - sdkFn, -}: { - operation: IR.OperationObject; - plugin: PluginInstance; - sdkFn: string; -}): void => { - const typeData = useTypeData({ operation, plugin }); - - // Create the SDK function call with arg parameter - const awaitSdkExpression = tsc.awaitExpression({ - expression: tsc.callExpression({ - functionName: sdkFn, - parameters: [ - tsc.objectExpression({ - multiLine: true, - obj: [ - { - spread: optionsParamName, - }, - { - spread: 'arg', - }, - { - key: 'throwOnError', - value: true, - }, - ], - }), - ], - }), - }); - - const statements: Array = []; - - if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { - statements.push( - tsc.returnVariable({ - expression: awaitSdkExpression, - }), - ); - } else { - statements.push( - tsc.constVariable({ - destructure: true, - expression: awaitSdkExpression, - name: 'data', - }), - tsc.returnVariable({ - expression: 'data', - }), - ); - } - - // Build the options object - const swrMutationOptionsObj = tsc.objectExpression({ - obj: [ - { - key: 'key', - value: tsc.stringLiteral({ text: operation.path }), - }, - { - key: 'fetcher', - value: tsc.arrowFunction({ - async: true, - multiLine: true, - parameters: [ - { - name: '_key', - type: tsc.keywordTypeNode({ - keyword: 'unknown', - }), - }, - { - destructure: [ - { - name: 'arg', - }, - ], - name: undefined, - type: tsc.typeInterfaceNode({ - properties: [ - { - isRequired: true, - name: 'arg', - type: typeData, - }, - ], - useLegacyResolution: false, - }), - }, - ], - statements, - }), - }, - ], - }); - - // Register the mutation options symbol - const symbolSwrMutationOptionsFn = plugin.registerSymbol({ - exported: plugin.config.swrMutationOptions.exported, - meta: { - category: 'hook', - resource: 'operation', - resourceId: operation.id, - role: 'swrMutationOptions', - tool: plugin.name, - }, - name: buildName({ - config: plugin.config.swrMutationOptions, - name: operation.id, - }), - }); - - const statement = tsc.constVariable({ - comment: plugin.config.comments - ? createOperationComment({ operation }) - : undefined, - exportConst: symbolSwrMutationOptionsFn.exported, - expression: tsc.arrowFunction({ - parameters: [ - { - isRequired: false, - name: optionsParamName, - type: typeData, - }, - ], - statements: [ - tsc.returnStatement({ - expression: swrMutationOptionsObj, - }), - ], - }), - name: symbolSwrMutationOptionsFn.placeholder, - }); - - plugin.setSymbolValue(symbolSwrMutationOptionsFn, statement); -}; diff --git a/packages/openapi-ts/src/plugins/swr/swrOptions.ts b/packages/openapi-ts/src/plugins/swr/swrOptions.ts deleted file mode 100644 index 70957c076d..0000000000 --- a/packages/openapi-ts/src/plugins/swr/swrOptions.ts +++ /dev/null @@ -1,162 +0,0 @@ -import type ts from 'typescript'; - -import type { IR } from '~/ir/types'; -import { buildName } from '~/openApi/shared/utils/name'; -import { - createOperationComment, - hasOperationSse, - isOperationOptionsRequired, -} from '~/plugins/shared/utils/operation'; -import { tsc } from '~/tsc'; - -import { registerSwrKey } from './swrKey'; -import type { PluginInstance } from './types'; -import { useTypeData } from './useType'; - -const optionsParamName = 'options'; - -/** - * Create useSWR options for a given operation. - * - * This generates a function that returns an object with: - * - key: The SWR key (array or string) - * - fetcher: Async function that calls the SDK function - * - * Example output: - * export const getUserByIdOptions = (options: GetUserByIdOptions) => ({ - * key: getUserByIdKey(options), - * fetcher: async () => { - * const { data } = await getUserById({ - * ...options, - * throwOnError: true, - * }); - * return data; - * }, - * }); - */ -export const createSwrOptions = ({ - operation, - plugin, - sdkFn, -}: { - operation: IR.OperationObject; - plugin: PluginInstance; - sdkFn: string; -}): void => { - if (hasOperationSse({ operation })) { - return; - } - - const isRequiredOptions = isOperationOptionsRequired({ - context: plugin.context, - operation, - }); - - // Register SWR key first - const symbolSwrKey = registerSwrKey({ operation, plugin }); - - const typeData = useTypeData({ operation, plugin }); - - // Create the SDK function call - const awaitSdkExpression = tsc.awaitExpression({ - expression: tsc.callExpression({ - functionName: sdkFn, - parameters: [ - tsc.objectExpression({ - multiLine: true, - obj: [ - { - spread: optionsParamName, - }, - { - key: 'throwOnError', - value: true, - }, - ], - }), - ], - }), - }); - - const statements: Array = []; - - if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { - statements.push( - tsc.returnVariable({ - expression: awaitSdkExpression, - }), - ); - } else { - statements.push( - tsc.constVariable({ - destructure: true, - expression: awaitSdkExpression, - name: 'data', - }), - tsc.returnVariable({ - expression: 'data', - }), - ); - } - - // Build the options object - const swrOptionsObj = tsc.objectExpression({ - obj: [ - { - key: 'key', - value: tsc.callExpression({ - functionName: symbolSwrKey.placeholder, - parameters: [optionsParamName], - }), - }, - { - key: 'fetcher', - value: tsc.arrowFunction({ - async: true, - multiLine: true, - statements, - }), - }, - ], - }); - - // Register the options symbol - const symbolSwrOptionsFn = plugin.registerSymbol({ - exported: plugin.config.swrOptions.exported, - meta: { - category: 'hook', - resource: 'operation', - resourceId: operation.id, - role: 'swrOptions', - tool: plugin.name, - }, - name: buildName({ - config: plugin.config.swrOptions, - name: operation.id, - }), - }); - - const statement = tsc.constVariable({ - comment: plugin.config.comments - ? createOperationComment({ operation }) - : undefined, - exportConst: symbolSwrOptionsFn.exported, - expression: tsc.arrowFunction({ - parameters: [ - { - isRequired: isRequiredOptions, - name: optionsParamName, - type: typeData, - }, - ], - statements: [ - tsc.returnStatement({ - expression: swrOptionsObj, - }), - ], - }), - name: symbolSwrOptionsFn.placeholder, - }); - - plugin.setSymbolValue(symbolSwrOptionsFn, statement); -}; diff --git a/packages/openapi-ts/src/plugins/swr/types.d.ts b/packages/openapi-ts/src/plugins/swr/types.d.ts index 12aa335054..559d800905 100644 --- a/packages/openapi-ts/src/plugins/swr/types.d.ts +++ b/packages/openapi-ts/src/plugins/swr/types.d.ts @@ -88,6 +88,12 @@ export type UserConfig = Plugin.Name<'swr'> & * @default true */ enabled?: boolean; + /** + * Whether to export generated symbols. + * + * @default true + */ + exported?: boolean; /** * Custom naming pattern for generated SWR key names. The name variable is * obtained from the SDK function name. @@ -243,6 +249,12 @@ export type Config = Plugin.Name<'swr'> & * @default true */ enabled: boolean; + /** + * Whether to export generated symbols. + * + * @default true + */ + exported: boolean; /** * Custom naming pattern for generated SWR key names. The name variable is obtained from the SDK function name. * diff --git a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts new file mode 100644 index 0000000000..139f956a46 --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts @@ -0,0 +1,86 @@ +import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation'; +import { stringCase } from '~/utils/stringCase'; + +import type { PluginHandler } from '../types'; +import { createSwrInfiniteOptions } from './swrInfiniteOptions'; +import { createSwrMutationOptions } from './swrMutationOptions'; +import { createSwrOptions } from './swrOptions'; + +/** + * Main handler for the SWR plugin (v2). + * + * This plugin generates useSWR and useSWRMutation options for each operation. + * It follows SWR's official recommended patterns for key design and data fetching. + */ +export const handlerV2: PluginHandler = ({ plugin }) => { + // Register external symbols from axios (for error types) + plugin.registerSymbol({ + external: 'axios', + kind: 'type', + meta: { + category: 'external', + resource: 'axios.AxiosError', + }, + name: 'AxiosError', + }); + + const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk'); + + // Iterate over all operations + plugin.forEach( + 'operation', + ({ operation }) => { + // Get the SDK function name + const classes = sdkPlugin.config.asClass + ? operationClasses({ + context: plugin.context, + operation, + plugin: sdkPlugin, + }) + : undefined; + const entry = classes ? classes.values().next().value : undefined; + const sdkFn = entry + ? [ + plugin.referenceSymbol({ + category: 'utility', + resource: 'class', + resourceId: entry.path[0], + tool: 'sdk', + }).placeholder, + ...entry.path.slice(1).map((className) => + stringCase({ + case: 'camelCase', + value: className, + }), + ), + entry.methodName, + ] + .filter(Boolean) + .join('.') + : plugin.referenceSymbol({ + category: 'sdk', + resource: 'operation', + resourceId: operation.id, + }).placeholder; + + // Generate appropriate SWR functions based on operation type + if (plugin.hooks.operation.isQuery(operation)) { + if (plugin.config.swrOptions.enabled) { + createSwrOptions({ operation, plugin, sdkFn }); + } + if (plugin.config.swrInfiniteOptions.enabled) { + createSwrInfiniteOptions({ operation, plugin, sdkFn }); + } + } + + if (plugin.hooks.operation.isMutation(operation)) { + if (plugin.config.swrMutationOptions.enabled) { + createSwrMutationOptions({ operation, plugin, sdkFn }); + } + } + }, + { + order: 'declarations', + }, + ); +}; diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts new file mode 100644 index 0000000000..069c2ac4aa --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts @@ -0,0 +1,297 @@ +import ts from 'typescript'; + +import { operationPagination } from '~/ir/operation'; +import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; +import { + createOperationComment, + hasOperationSse, + isOperationOptionsRequired, +} from '~/plugins/shared/utils/operation'; +import type { TsDsl } from '~/ts-dsl'; +import { $ } from '~/ts-dsl'; + +import type { PluginInstance } from '../types'; +import { useTypeData, useTypeResponse } from '../useType'; + +const optionsParamName = 'options'; + +/** + * Create useSWRInfinite options for a given operation with pagination support. + * + * This generates a wrapper function that accepts operation options and returns an object + * compatible with SWR's useSWRInfinite hook signature: + * - getKey: A function that generates SWR keys for each page + * - fetcher: An async function that fetches a single page + * + * The getKey function signature matches SWR's requirements: + * (pageIndex: number, previousPageData: ResponseType | null) => Key | null + * + * The key structure uses primitive values for optimal caching: + * [path, ...pathParams, queryObject] + * + * Optional parameters use optional chaining (options?.query) for safe access. + * + * Usage with useSWRInfinite: + * const { getKey, fetcher } = getUsersInfinite({ query: { status: 'active' } }); + * const { data, size, setSize } = useSWRInfinite(getKey, fetcher, { + * initialSize: 1, + * revalidateFirstPage: true, + * }); + * + * Example outputs: + * + * Without path params (optional): + * export const getUsersInfinite = (options?: GetUsersData) => ({ + * getKey: (pageIndex: number, previousPageData: GetUsersResponse | null) => + * ['/users', { ...options?.query, page: pageIndex }], + * fetcher: async (key: readonly [string, GetUsersData['query']]) => { + * const params = { query: key[1] }; + * const { data } = await getUsers({ ...params, throwOnError: true }); + * return data; + * } + * }); + * + * With path params (options required): + * export const getOrgUsersInfinite = (options: GetOrgUsersData) => ({ + * getKey: (pageIndex: number, previousPageData: GetOrgUsersResponse | null) => + * ['/orgs/{orgId}/users', options.path.orgId, { ...options.query, page: pageIndex }], + * fetcher: async (key: readonly [string, string, GetOrgUsersData['query']]) => { + * const params = { path: { orgId: key[1] }, query: key[2] }; + * const { data } = await getOrgUsers({ ...params, throwOnError: true }); + * return data; + * } + * }); + * + * Note: The getKey function always returns a key array for each page. Use conditional + * logic within getKey (checking previousPageData) to stop pagination, not to disable + * the entire query. The key itself is never null - only returned when pagination ends. + */ +export const createSwrInfiniteOptions = ({ + operation, + plugin, + sdkFn, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; + sdkFn: string; +}): void => { + if (hasOperationSse({ operation })) { + return; + } + + // Check if this operation supports pagination + const pagination = operationPagination({ + context: plugin.context, + operation, + }); + + // Only generate infinite options for operations with pagination + if (!pagination) { + return; + } + + const isRequiredOptions = isOperationOptionsRequired({ + context: plugin.context, + operation, + }); + + const typeData = useTypeData({ operation, plugin }); + const typeResponse = useTypeResponse({ operation, plugin }); + + // Create the getKey function + // Following SWR's useSWRInfinite pattern: + // getKey: (pageIndex: number, previousPageData: ResponseType | null) => Key | null + // + // The getKey function should: + // 1. Return null to stop fetching (when previousPageData is empty/end reached) + // 2. Return key array with primitive values for each page + // 3. Match the pattern from swrKey.ts: ['/path', ...pathParams, queryObject] + const getKeyStatements: Array> = []; + + // Build the key array following the same pattern as regular keys + const pathParams = operation.parameters?.path || {}; + const hasQueryParams = + operation.parameters?.query && + Object.keys(operation.parameters.query).length > 0; + + const keyElements: ts.Expression[] = [$.literal(operation.path).$render()]; + + // Extract each path parameter as a separate primitive value + for (const key in pathParams) { + const parameter = pathParams[key]!; + // Use optional chaining if options is optional + if (isRequiredOptions) { + keyElements.push( + $('options').attr('path').attr(parameter.name).$render(), + ); + } else { + // Create options?.path.{paramName} with optional chaining + keyElements.push( + $( + ts.factory.createPropertyAccessExpression( + ts.factory.createPropertyAccessChain( + $('options').$render(), + ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), + ts.factory.createIdentifier('path'), + ), + ts.factory.createIdentifier(parameter.name), + ), + ).$render(), + ); + } + } + + // For query parameters, merge with pagination + if (hasQueryParams) { + // Create merged query object: { ...options?.query, [paginationName]: pageIndex } + // Need to use optional chaining for options.query when options is optional + const queryAccess = isRequiredOptions + ? $('options').attr('query') + : $( + ts.factory.createPropertyAccessChain( + $('options').$render(), + ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), + ts.factory.createIdentifier('query'), + ), + ); + const mergedQuery = $.object() + .spread(queryAccess) + .prop(pagination.name, 'pageIndex'); + keyElements.push(mergedQuery.$render()); + } else { + // If no existing query params, just add pagination as an object + keyElements.push($.object().prop(pagination.name, 'pageIndex').$render()); + } + + // Create the array: ['/path', ...pathParams, queryWithPagination] + const keyArrayExpr = $(ts.factory.createArrayLiteralExpression(keyElements)); + + // Return the key array + getKeyStatements.push(keyArrayExpr.return()); + + const getKeyFunction = $.func() + .param('pageIndex', (p) => p.type('number')) + .param('previousPageData', (p) => p.type(`${typeResponse} | null`)) + .do(...getKeyStatements); + + // Create the fetcher function + // Fetcher receives the key array and reconstructs the options object + const fetcherStatements: Array> = []; + + // Reconstruct the options object from the key array + // Key structure: ['/path', ...pathParams, queryObj] + // We need to build: { path: { param1: value1, ... }, query: queryObj } + const pathParamsCount = Object.keys(pathParams).length; + + // Build the reconstructed options object + let reconstructedOptions = $.object(); + + // Add path params if they exist + if (pathParamsCount > 0) { + let pathObj = $.object(); + let paramIndex = 1; // Start after the path string + for (const key in pathParams) { + const parameter = pathParams[key]!; + // Create element access: key[index] + const elementAccess = $( + ts.factory.createElementAccessExpression( + $('key').$render(), + ts.factory.createNumericLiteral(paramIndex), + ), + ); + pathObj = pathObj.prop(parameter.name, elementAccess); + paramIndex++; + } + reconstructedOptions = reconstructedOptions.prop('path', pathObj); + } + + // Add query params (last element in key array) + // Query is at index: 1 + pathParamsCount + const queryIndex = 1 + pathParamsCount; + const queryAccess = $( + ts.factory.createElementAccessExpression( + $('key').$render(), + ts.factory.createNumericLiteral(queryIndex), + ), + ); + reconstructedOptions = reconstructedOptions.prop('query', queryAccess); + + fetcherStatements.push($.const('params').assign(reconstructedOptions)); + + const awaitSdkFn = $(sdkFn) + .call($.object().spread('params').prop('throwOnError', $.literal(true))) + .await(); + + if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { + fetcherStatements.push($.return(awaitSdkFn)); + } else { + fetcherStatements.push( + $.const().object('data').assign(awaitSdkFn), + $.return('data'), + ); + } + + // Build the fetcher key type: readonly [string, ...pathParams, queryType] + // Example: readonly [string, number, { page: number }] + const keyTypeElements = ['string']; + + // Add path param types + Object.keys(pathParams).forEach(() => { + // Use the parameter's type - for simplicity, we'll use the base type + keyTypeElements.push('string'); + }); + + // Add query type - extract query type from the options type + // If the operation has query params, use the query property type from typeData + // Otherwise, use the pagination parameter type + const queryType = hasQueryParams + ? `${typeData}['query']` + : `{ ${pagination.name}: number }`; + keyTypeElements.push(queryType); + + const keyType = `readonly [${keyTypeElements.join(', ')}]`; + + const fetcherFunction = $.func() + .async() + .param('key', (p) => p.type(keyType)) + .do(...fetcherStatements); + + // Build the infinite options object + const swrInfiniteOptionsObj = $.object() + .pretty() + .prop('getKey', getKeyFunction) + .prop('fetcher', fetcherFunction); + + // Register the infinite options symbol + const symbolSwrInfiniteOptionsFn = plugin.registerSymbol({ + exported: plugin.config.swrInfiniteOptions.exported, + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'swrInfiniteOptions', + tool: plugin.name, + }, + name: buildName({ + config: plugin.config.swrInfiniteOptions, + name: operation.id, + }), + }); + + const statement = $.const(symbolSwrInfiniteOptionsFn.placeholder) + .export(symbolSwrInfiniteOptionsFn.exported) + .$if( + plugin.config.comments && createOperationComment({ operation }), + (c, v) => c.describe(v as Array), + ) + .assign( + $.func() + .param(optionsParamName, (p) => + p.optional(!isRequiredOptions).type(typeData), + ) + .do($.return(swrInfiniteOptionsObj)), + ); + + plugin.setSymbolValue(symbolSwrInfiniteOptionsFn, statement); +}; diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts b/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts new file mode 100644 index 0000000000..b217224cb4 --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts @@ -0,0 +1,157 @@ +import type { Symbol } from '@hey-api/codegen-core'; +import ts from 'typescript'; + +import { hasOperationDataRequired } from '~/ir/operation'; +import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; +import { $ } from '~/ts-dsl'; + +import type { PluginInstance } from '../types'; +import { useTypeData } from '../useType'; + +/** + * Generate a SWR key statement for a given operation. + * + * For SWR, keys follow the official recommended pattern with primitive values: + * - Simple cases: string key like '/api/user' + * - With params: array key like ['/api/user', userId] with primitive values + * - Conditional fetching: controlled by the consumer, not the key function + * + * This generates a function that always returns a valid key array. + * Following SWR best practices: "use arrays with primitive values instead of objects" + * + * Example outputs: + * - No params: ['/api/users'] + * - Single path param: ['/api/users', options.path.id] + * - Multiple path params: ['/api/users', options.path.userId, options.path.orgId] + * - Path + query: ['/api/users', options.path.id, options.query] + * - Optional params: ['/api/users', options?.query] (uses optional chaining) + * + * Note: Conditional fetching should be controlled at the usage site: + * useSWR(shouldFetch ? getKey(options) : null, fetcher) + */ +export const swrKeyStatement = ({ + operation, + plugin, + symbol, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; + symbol: Symbol; +}) => { + const typeData = useTypeData({ operation, plugin }); + const isRequired = hasOperationDataRequired(operation); + + // Build the key based on what parameters exist + // Following SWR's pattern: use primitive values for better serialization + const pathParams = operation.parameters?.path || {}; + const hasQueryParams = + operation.parameters?.query && + Object.keys(operation.parameters.query).length > 0; + + // Build array elements for the key using ts-dsl + const baseKeyElements: ts.Expression[] = [ + $.literal(operation.path).$render(), + ]; + + // Extract each path parameter as a separate primitive value + // This follows SWR best practice: ['/api/users', userId] not ['/api/users', { userId }] + // Use parameter.name (the transformed TypeScript property name) not the key (original OpenAPI name) + const pathKeyElements: ts.Expression[] = []; + for (const key in pathParams) { + const parameter = pathParams[key]!; + pathKeyElements.push( + $('options').attr('path').attr(parameter.name).$render(), + ); + } + + // For query parameters, we keep them as an object since they can be complex + // and are typically used together for filtering/pagination + const queryKeyElement = hasQueryParams + ? $('options').attr('query').$render() + : null; + + // Determine the key expression based on whether parameters are required + let keyExpression: ts.Expression; + + const hasParams = pathKeyElements.length > 0 || hasQueryParams; + + if (isRequired || !hasParams) { + // If required OR no params at all, always return the full key array + const allElements = [...baseKeyElements, ...pathKeyElements]; + if (queryKeyElement) { + allElements.push(queryKeyElement); + } + keyExpression = ts.factory.createArrayLiteralExpression(allElements); + } else { + // If optional and has params, use optional chaining to safely access nested properties + // Build the key array with optional chaining for safety + const allElements = [...baseKeyElements]; + + for (const key in pathParams) { + const parameter = pathParams[key]!; + allElements.push( + ts.factory.createPropertyAccessChain( + ts.factory.createPropertyAccessChain( + ts.factory.createIdentifier('options'), + ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), + ts.factory.createIdentifier('path'), + ), + undefined, + ts.factory.createIdentifier(parameter.name), + ), + ); + } + + if (hasQueryParams) { + allElements.push( + ts.factory.createPropertyAccessChain( + ts.factory.createIdentifier('options'), + ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), + ts.factory.createIdentifier('query'), + ), + ); + } + + keyExpression = ts.factory.createArrayLiteralExpression(allElements); + } + + const statement = $.const(symbol.placeholder) + .export(symbol.exported) + .assign( + $.func() + .param('options', (p) => p.optional(!isRequired).type(typeData)) + .do($(keyExpression).return()), + ); + + return statement; +}; + +/** + * Register a SWR key symbol for a given operation. + */ +export const registerSwrKey = ({ + operation, + plugin, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; +}): Symbol => { + const symbol = plugin.registerSymbol({ + exported: true, + name: buildName({ + config: plugin.config.swrKeys, + name: operation.id, + }), + }); + + const node = swrKeyStatement({ + operation, + plugin, + symbol, + }); + + plugin.setSymbolValue(symbol, node); + + return symbol; +}; diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts new file mode 100644 index 0000000000..3a98ed0066 --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts @@ -0,0 +1,162 @@ +import ts from 'typescript'; + +import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; +import { createOperationComment } from '~/plugins/shared/utils/operation'; +import type { TsDsl } from '~/ts-dsl'; +import { $ } from '~/ts-dsl'; + +import type { PluginInstance } from '../types'; +import { useTypeData } from '../useType'; + +const optionsParamName = 'options'; + +/** + * Create useSWRMutation options for a given operation. + * + * This generates a function that returns an object with: + * - key: The mutation key following SWR patterns (array with path + path params) + * - fetcher: Async function that calls the SDK function with arg parameter + * + * Following SWR best practices: + * - No path params: string key like '/api/users' + * - With path params: array key like ['/api/users/{id}', userId] + * - This matches the query key structure for proper cache integration + * + * Example outputs: + * // No path parameters + * export const createUserMutation = (options?: CreateUserOptions) => ({ + * key: '/api/users', + * fetcher: async (_key, arg) => { ... }, + * }); + * + * // With path parameters + * export const deletePetMutation = (options?: DeletePetOptions) => ({ + * key: options?.path ? ['/pet/{petId}', options.path.petId] : '/pet/{petId}', + * fetcher: async (_key, arg) => { ... }, + * }); + */ +export const createSwrMutationOptions = ({ + operation, + plugin, + sdkFn, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; + sdkFn: string; +}): void => { + const typeData = useTypeData({ operation, plugin }); + + // Create the SDK function call with arg parameter + const awaitSdkFn = $(sdkFn) + .call( + $.object() + .spread(optionsParamName) + .spread('arg') + .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'), + ); + } + + // Build mutation key following SWR patterns + // - If path params exist: use array [path, ...pathParams] + // - If no path params: use simple string key + const pathParams = operation.parameters?.path || {}; + const hasPathParams = Object.keys(pathParams).length > 0; + + let mutationKey: TsDsl; + let keyType: string; + + if (hasPathParams) { + // Build array key: [path, param1, param2, ...] + const keyElements: ts.Expression[] = [$.literal(operation.path).$render()]; + + // Add each path parameter as a separate primitive value + for (const key in pathParams) { + const parameter = pathParams[key]!; + keyElements.push( + $('options').attr('path').attr(parameter.name).$render(), + ); + } + + // Wrap in conditional: options?.path ? [...] : path + mutationKey = $( + ts.factory.createConditionalExpression( + ts.factory.createPropertyAccessChain( + $('options').$render(), + ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), + 'path', + ), + ts.factory.createToken(ts.SyntaxKind.QuestionToken), + ts.factory.createArrayLiteralExpression(keyElements), + ts.factory.createToken(ts.SyntaxKind.ColonToken), + $.literal(operation.path).$render(), + ), + ); + // Key type is either array or string depending on whether path params are provided + keyType = 'string | readonly [string, ...Array]'; + } else { + // Simple string key for operations without path params + mutationKey = $.literal(operation.path); + keyType = 'string'; + } + + // Build the options object + const swrMutationOptionsObj = $.object() + .pretty() + .prop('key', mutationKey) + .prop( + 'fetcher', + $.func() + .async() + .param('_key', (p) => p.type(keyType)) + .param((p) => + p.object('arg').type( + $.type.object((t) => { + t.prop('arg', (p) => p.type(typeData)); + }), + ), + ) + .do(...statements), + ); + + // Register the mutation options symbol + const symbolSwrMutationOptionsFn = plugin.registerSymbol({ + exported: plugin.config.swrMutationOptions.exported, + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'swrMutationOptions', + tool: plugin.name, + }, + name: buildName({ + config: plugin.config.swrMutationOptions, + name: operation.id, + }), + }); + + const statement = $.const(symbolSwrMutationOptionsFn.placeholder) + .export(symbolSwrMutationOptionsFn.exported) + .$if( + plugin.config.comments && createOperationComment({ operation }), + (c, v) => c.describe(v as Array), + ) + .assign( + $.func() + .param(optionsParamName, (p) => p.optional(true).type(typeData)) + .do($.return(swrMutationOptionsObj)), + ); + + plugin.setSymbolValue(symbolSwrMutationOptionsFn, statement); +}; diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts new file mode 100644 index 0000000000..f2bd327958 --- /dev/null +++ b/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts @@ -0,0 +1,134 @@ +import type { IR } from '~/ir/types'; +import { buildName } from '~/openApi/shared/utils/name'; +import { + createOperationComment, + hasOperationSse, + isOperationOptionsRequired, +} from '~/plugins/shared/utils/operation'; +import type { TsDsl } from '~/ts-dsl'; +import { $ } from '~/ts-dsl'; + +import type { PluginInstance } from '../types'; +import { useTypeData } from '../useType'; +import { registerSwrKey } from './swrKey'; + +const optionsParamName = 'options'; + +/** + * Create useSWR options for a given operation. + * + * This generates a function that returns an object with: + * - key: The SWR key (always returns a valid key array, never null) + * - fetcher: Async function that calls the SDK function + * + * The key is generated by the registered swrKey function, which follows these patterns: + * - No params: ['/api/users'] + * - Required params: ['/api/users/{id}', options.path.id] + * - Optional params: ['/api/users', options?.query] (uses optional chaining) + * + * Note: Conditional fetching should be controlled by the consumer: + * useSWR(condition ? getUserOptions() : null, fetcher) + * + * Example outputs: + * // Required parameters + * export const getUserByIdOptions = (options: GetUserByIdOptions) => ({ + * key: getUserByIdKey(options), + * fetcher: async () => { + * const { data } = await getUserById({ ...options, throwOnError: true }); + * return data; + * }, + * }); + * + * // Optional parameters + * export const getInventoryOptions = (options?: GetInventoryOptions) => ({ + * key: getInventoryKey(options), + * fetcher: async () => { + * const { data } = await getInventory({ ...options, throwOnError: true }); + * return data; + * }, + * }); + */ +export const createSwrOptions = ({ + operation, + plugin, + sdkFn, +}: { + operation: IR.OperationObject; + plugin: PluginInstance; + sdkFn: string; +}): void => { + if (hasOperationSse({ operation })) { + return; + } + + const isRequiredOptions = isOperationOptionsRequired({ + context: plugin.context, + operation, + }); + + // Register SWR key first + const symbolSwrKey = registerSwrKey({ operation, plugin }); + + const typeData = useTypeData({ operation, plugin }); + + // Create the SDK function call + const awaitSdkFn = $(sdkFn) + .call( + $.object().spread(optionsParamName).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'), + ); + } + + // Build the options object + const swrOptionsObj = $.object() + .pretty() + .prop('key', $(symbolSwrKey.placeholder).call(optionsParamName)) + .prop( + 'fetcher', + $.func() + .async() + .do(...statements), + ); + + // Register the options symbol + const symbolSwrOptionsFn = plugin.registerSymbol({ + exported: plugin.config.swrOptions.exported, + meta: { + category: 'hook', + resource: 'operation', + resourceId: operation.id, + role: 'swrOptions', + tool: plugin.name, + }, + name: buildName({ + config: plugin.config.swrOptions, + name: operation.id, + }), + }); + + const statement = $.const(symbolSwrOptionsFn.placeholder) + .export(symbolSwrOptionsFn.exported) + .$if( + plugin.config.comments && createOperationComment({ operation }), + (c, v) => c.describe(v as Array), + ) + .assign( + $.func() + .param(optionsParamName, (p) => + p.optional(!isRequiredOptions).type(typeData), + ) + .do($.return(swrOptionsObj)), + ); + + plugin.setSymbolValue(symbolSwrOptionsFn, statement); +}; From aa0a60da93eaa91ed5915c52a882e20745a21bde Mon Sep 17 00:00:00 2001 From: Pewww Date: Thu, 13 Nov 2025 14:25:53 +0900 Subject: [PATCH 5/9] refactor: handling logic for SWR query key options --- examples/openapi-ts-swr/src/client/swr.gen.ts | 67 +- .../axios/client/client.gen.ts | 1 + .../react-query/axios/client/client.gen.ts | 1 + .../solid-query/axios/client/client.gen.ts | 1 + .../svelte-query/axios/client/client.gen.ts | 1 + .../vue-query/axios/client/client.gen.ts | 1 + .../2.0.x/plugins/swr/asClass/swr.gen.ts | 183 +- .../plugins/swr/axios/client/client.gen.ts | 1 + .../2.0.x/plugins/swr/axios/swr.gen.ts | 1067 +++++------ .../2.0.x/plugins/swr/fetch/swr.gen.ts | 1067 +++++------ .../3.0.x/content-types/client/client.gen.ts | 1 + .../client/client.gen.ts | 1 + .../axios/client/client.gen.ts | 1 + .../react-query/axios/client/client.gen.ts | 1 + .../solid-query/axios/client/client.gen.ts | 1 + .../svelte-query/axios/client/client.gen.ts | 1 + .../vue-query/axios/client/client.gen.ts | 1 + .../3.0.x/plugins/swr/asClass/swr.gen.ts | 183 +- .../plugins/swr/axios/client/client.gen.ts | 1 + .../3.0.x/plugins/swr/axios/swr.gen.ts | 1570 ++++++----------- .../3.0.x/plugins/swr/fetch/swr.gen.ts | 1570 ++++++----------- .../base-url-false/client/client.gen.ts | 1 + .../base-url-number/client/client.gen.ts | 1 + .../base-url-strict/client/client.gen.ts | 1 + .../base-url-string/client/client.gen.ts | 1 + .../clean-false/client/client.gen.ts | 1 + .../client-axios/default/client/client.gen.ts | 1 + .../client/client.gen.ts | 1 + .../sdk-client-optional/client/client.gen.ts | 1 + .../sdk-client-required/client/client.gen.ts | 1 + .../client/client.gen.ts | 1 + .../3.1.x/content-types/client/client.gen.ts | 1 + .../client/client.gen.ts | 1 + .../axios/client/client.gen.ts | 1 + .../react-query/axios/client/client.gen.ts | 1 + .../solid-query/axios/client/client.gen.ts | 1 + .../svelte-query/axios/client/client.gen.ts | 1 + .../vue-query/axios/client/client.gen.ts | 1 + .../3.1.x/plugins/swr/asClass/swr.gen.ts | 183 +- .../plugins/swr/axios/client/client.gen.ts | 1 + .../3.1.x/plugins/swr/axios/swr.gen.ts | 1570 ++++++----------- .../3.1.x/plugins/swr/fetch/swr.gen.ts | 1570 ++++++----------- .../3.1.x/sse-axios/client/client.gen.ts | 1 + .../test/plugins/swr/basic-generation.test.ts | 7 +- .../main/test/plugins/swr/edge-cases.test.ts | 14 +- .../openapi-ts/src/plugins/swr/v2/plugin.ts | 24 + .../src/plugins/swr/v2/swrInfiniteOptions.ts | 153 +- .../openapi-ts/src/plugins/swr/v2/swrKey.ts | 107 +- .../src/plugins/swr/v2/swrMutationOptions.ts | 70 +- 49 files changed, 3556 insertions(+), 5882 deletions(-) diff --git a/examples/openapi-ts-swr/src/client/swr.gen.ts b/examples/openapi-ts-swr/src/client/swr.gen.ts index adb6a24aee..0be659ac24 100644 --- a/examples/openapi-ts-swr/src/client/swr.gen.ts +++ b/examples/openapi-ts-swr/src/client/swr.gen.ts @@ -44,6 +44,7 @@ import type { UploadFileData, } from './types.gen'; +/* eslint-disable @typescript-eslint/no-unused-vars */ /** * Add a new pet to the store. * @@ -51,7 +52,7 @@ import type { */ export const addPetMutation = (options?: Options) => ({ fetcher: async ( - _key: string, + _key: readonly [string], { arg, }: { @@ -65,7 +66,7 @@ export const addPetMutation = (options?: Options) => ({ }); return data; }, - key: '/pet', + key: ['/pet'], }); /** @@ -75,7 +76,7 @@ export const addPetMutation = (options?: Options) => ({ */ export const updatePetMutation = (options?: Options) => ({ fetcher: async ( - _key: string, + _key: readonly [string], { arg, }: { @@ -89,12 +90,12 @@ export const updatePetMutation = (options?: Options) => ({ }); return data; }, - key: '/pet', + key: ['/pet'], }); export const findPetsByStatusKey = (options: Options) => [ '/pet/findByStatus', - options.query, + options, ]; /** @@ -114,7 +115,7 @@ export const findPetsByStatusOptions = ( export const findPetsByTagsKey = (options: Options) => [ '/pet/findByTags', - options.query, + options, ]; /** @@ -139,7 +140,7 @@ export const findPetsByTagsOptions = ( */ export const deletePetMutation = (options?: Options) => ({ fetcher: async ( - _key: string | readonly [string, ...Array], + _key: readonly [string] | readonly [string, Options], { arg, }: { @@ -153,12 +154,12 @@ export const deletePetMutation = (options?: Options) => ({ }); return data; }, - key: options?.path ? ['/pet/{petId}', options.path.petId] : '/pet/{petId}', + key: options?.path ? ['/pet/{petId}', options] : ['/pet/{petId}'], }); export const getPetByIdKey = (options: Options) => [ '/pet/{petId}', - options.path.petId, + options, ]; /** @@ -183,7 +184,7 @@ export const updatePetWithFormMutation = ( options?: Options, ) => ({ fetcher: async ( - _key: string | readonly [string, ...Array], + _key: readonly [string] | readonly [string, Options], { arg, }: { @@ -197,7 +198,7 @@ export const updatePetWithFormMutation = ( }); return data; }, - key: options?.path ? ['/pet/{petId}', options.path.petId] : '/pet/{petId}', + key: options?.path ? ['/pet/{petId}', options] : ['/pet/{petId}'], }); /** @@ -207,7 +208,7 @@ export const updatePetWithFormMutation = ( */ export const uploadFileMutation = (options?: Options) => ({ fetcher: async ( - _key: string | readonly [string, ...Array], + _key: readonly [string] | readonly [string, Options], { arg, }: { @@ -222,13 +223,12 @@ export const uploadFileMutation = (options?: Options) => ({ return data; }, key: options?.path - ? ['/pet/{petId}/uploadImage', options.path.petId] - : '/pet/{petId}/uploadImage', + ? ['/pet/{petId}/uploadImage', options] + : ['/pet/{petId}/uploadImage'], }); export const getInventoryKey = (options?: Options) => [ '/store/inventory', - options?.query, ]; /** @@ -251,7 +251,7 @@ export const getInventoryOptions = (options?: Options) => ({ */ export const placeOrderMutation = (options?: Options) => ({ fetcher: async ( - _key: string, + _key: readonly [string], { arg, }: { @@ -265,7 +265,7 @@ export const placeOrderMutation = (options?: Options) => ({ }); return data; }, - key: '/store/order', + key: ['/store/order'], }); /** @@ -275,7 +275,7 @@ export const placeOrderMutation = (options?: Options) => ({ */ export const deleteOrderMutation = (options?: Options) => ({ fetcher: async ( - _key: string | readonly [string, ...Array], + _key: readonly [string] | readonly [string, Options], { arg, }: { @@ -290,13 +290,13 @@ export const deleteOrderMutation = (options?: Options) => ({ return data; }, key: options?.path - ? ['/store/order/{orderId}', options.path.orderId] - : '/store/order/{orderId}', + ? ['/store/order/{orderId}', options] + : ['/store/order/{orderId}'], }); export const getOrderByIdKey = (options: Options) => [ '/store/order/{orderId}', - options.path.orderId, + options, ]; /** @@ -319,7 +319,7 @@ export const getOrderByIdOptions = (options: Options) => ({ */ export const createUserMutation = (options?: Options) => ({ fetcher: async ( - _key: string, + _key: readonly [string], { arg, }: { @@ -333,7 +333,7 @@ export const createUserMutation = (options?: Options) => ({ }); return data; }, - key: '/user', + key: ['/user'], }); /** @@ -345,7 +345,7 @@ export const createUsersWithListInputMutation = ( options?: Options, ) => ({ fetcher: async ( - _key: string, + _key: readonly [string], { arg, }: { @@ -359,12 +359,12 @@ export const createUsersWithListInputMutation = ( }); return data; }, - key: '/user/createWithList', + key: ['/user/createWithList'], }); export const loginUserKey = (options?: Options) => [ '/user/login', - options?.query, + options, ]; /** @@ -382,7 +382,6 @@ export const loginUserOptions = (options?: Options) => ({ export const logoutUserKey = (options?: Options) => [ '/user/logout', - options?.query, ]; /** @@ -405,7 +404,7 @@ export const logoutUserOptions = (options?: Options) => ({ */ export const deleteUserMutation = (options?: Options) => ({ fetcher: async ( - _key: string | readonly [string, ...Array], + _key: readonly [string] | readonly [string, Options], { arg, }: { @@ -419,14 +418,12 @@ export const deleteUserMutation = (options?: Options) => ({ }); return data; }, - key: options?.path - ? ['/user/{username}', options.path.username] - : '/user/{username}', + key: options?.path ? ['/user/{username}', options] : ['/user/{username}'], }); export const getUserByNameKey = (options: Options) => [ '/user/{username}', - options.path.username, + options, ]; /** @@ -449,7 +446,7 @@ export const getUserByNameOptions = (options: Options) => ({ */ export const updateUserMutation = (options?: Options) => ({ fetcher: async ( - _key: string | readonly [string, ...Array], + _key: readonly [string] | readonly [string, Options], { arg, }: { @@ -463,7 +460,5 @@ export const updateUserMutation = (options?: Options) => ({ }); return data; }, - key: options?.path - ? ['/user/{username}', options.path.username] - : '/user/{username}', + key: options?.path ? ['/user/{username}', options] : ['/user/{username}'], }); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts index 586defdb49..df351d6b75 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts @@ -3,124 +3,81 @@ import { BarBazService, FooBazService, type Options } from './sdk.gen'; import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarData, GetFooData } from './types.gen'; -export const getFooKey = (options?: Options) => { - const key: any[] = [ - '/foo' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; -export const getFooOptions = (options?: Options) => { - return { - key: getFooKey(options), - fetcher: async () => { - const { data } = await FooBazService.getFoo({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooKey = (options?: Options) => ["/foo"]; -export const fooPostMutation = (options?: Options) => { - return { - key: '/foo', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooPutMutation = (options?: Options) => { - return { - key: '/foo', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.put({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getFooBarKey = (options?: Options) => { - const key: any[] = [ - '/foo/bar' - ]; - if (options?.path) { - key.push({ path: options.path }); +export const getFooOptions = (options?: Options) => ({ + key: getFooKey(options), + fetcher: async () => { + const { data } = await FooBazService.getFoo({ ...options, throwOnError: true }); + return data; } - if (options?.query) { - key.push({ query: options.query }); +}); + +export const fooPostMutation = (options?: Options) => ({ + key: ["/foo"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; } - if (options?.body) { - key.push({ body: options.body }); +}); + +export const fooPutMutation = (options?: Options) => ({ + key: ["/foo"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; } - return key; -}; +}); -export const getFooBarOptions = (options?: Options) => { - return { - key: getFooBarKey(options), - fetcher: async () => { - const { data } = await BarBazService.getFooBar({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooBarKey = (options?: Options) => ["/foo/bar"]; -export const fooBarPostMutation = (options?: Options) => { - return { - key: '/foo/bar', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooBarOptions = (options?: Options) => ({ + key: getFooBarKey(options), + fetcher: async () => { + const { data } = await BarBazService.getFooBar({ ...options, throwOnError: true }); + return data; + } +}); -export const fooBarPutMutation = (options?: Options) => { - return { - key: '/foo/bar', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.barService.put({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const fooBarPostMutation = (options?: Options) => ({ + key: ["/foo/bar"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooBarPutMutation = (options?: Options) => ({ + key: ["/foo/bar"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts index e36cf187f8..122e577b6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts @@ -3,675 +3,410 @@ 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, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from './types.gen'; -export const serviceWithEmptyTagKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no+tag' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const serviceWithEmptyTagOptions = (options?: Options) => { - return { - key: serviceWithEmptyTagKey(options), - fetcher: async () => { - const { data } = await serviceWithEmptyTag({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchApiVbyApiVersionNoTag({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooWowMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await fooWow({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithoutParametersAndResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { - return { - key: getCallWithoutParametersAndResponseKey(options), - fetcher: async () => { - const { data } = await getCallWithoutParametersAndResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDescriptionsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/descriptions/', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDescriptions({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameterPath}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithWeirdParameterNamesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultParametersKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/defaults' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithDefaultParametersOptions = (options: Options) => { - return { - key: callWithDefaultParametersKey(options), - fetcher: async () => { - const { data } = await callWithDefaultParameters({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultOptionalParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callToTestOrderOfParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callToTestOrderOfParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateNameMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName2Key = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/duplicate' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const duplicateName2Options = (options?: Options) => { - return { - key: duplicateName2Key(options), - fetcher: async () => { - const { data } = await duplicateName2({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName3Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName3({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName4Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName4({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithNoContentResponseOptions = (options?: Options) => { - return { - key: callWithNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseAndNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/response-and-no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { - return { - key: callWithResponseAndNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponseAndNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyAKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/a' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyAOptions = (options?: Options) => { - return { - key: dummyAKey(options), - fetcher: async () => { - const { data } = await dummyA({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyBKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/b' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyBOptions = (options?: Options) => { - return { - key: dummyBKey(options), - fetcher: async () => { - const { data } = await dummyB({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/response' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseOptions = (options?: Options) => { - return { - key: callWithResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDuplicateResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const collectionFormatKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/collectionFormat' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const collectionFormatOptions = (options: Options) => { - return { - key: collectionFormatKey(options), - fetcher: async () => { - const { data } = await collectionFormat({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const typesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/types' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const typesOptions = (options: Options) => { - return { - key: typesKey(options), - fetcher: async () => { - const { data } = await types({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexTypesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/complex' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const complexTypesOptions = (options: Options) => { - return { - key: complexTypesKey(options), - fetcher: async () => { - const { data } = await complexTypes({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResultFromHeaderMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/header', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const testErrorCodeMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/error', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await testErrorCode({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; + +export const serviceWithEmptyTagKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; + +export const serviceWithEmptyTagOptions = (options?: Options) => ({ + key: serviceWithEmptyTagKey(options), + fetcher: async () => { + const { data } = await serviceWithEmptyTag({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooWowMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDescriptionsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/descriptions/", options] : ["/api/v{api-version}/descriptions/"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithWeirdParameterNamesMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDefaultParametersKey = (options: Options) => ["/api/v{api-version}/defaults", options]; + +export const callWithDefaultParametersOptions = (options: Options) => ({ + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callToTestOrderOfParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateNameMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; + +export const duplicateName2Options = (options?: Options) => ({ + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ ...options, throwOnError: true }); + return data; + } +}); + +export const duplicateName3Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName4Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; + +export const callWithNoContentResponseOptions = (options?: Options) => ({ + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; + +export const dummyAOptions = (options?: Options) => ({ + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; + +export const dummyBOptions = (options?: Options) => ({ + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; + +export const callWithResponseOptions = (options?: Options) => ({ + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDuplicateResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const collectionFormatKey = (options: Options) => ["/api/v{api-version}/collectionFormat", options]; + +export const collectionFormatOptions = (options: Options) => ({ + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ ...options, throwOnError: true }); + return data; + } +}); + +export const typesKey = (options: Options) => ["/api/v{api-version}/types", options]; + +export const typesOptions = (options: Options) => ({ + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ ...options, throwOnError: true }); + return data; + } +}); + +export const complexTypesKey = (options: Options) => ["/api/v{api-version}/complex", options]; + +export const complexTypesOptions = (options: Options) => ({ + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResultFromHeaderMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/header"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const testErrorCodeMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * Body should not be unknown * * Body should not be unknown */ -export const postApiVbyApiVersionBodyMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/body', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const postApiVbyApiVersionBodyMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/body"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts index e36cf187f8..122e577b6a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts @@ -3,675 +3,410 @@ 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, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from './types.gen'; -export const serviceWithEmptyTagKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no+tag' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const serviceWithEmptyTagOptions = (options?: Options) => { - return { - key: serviceWithEmptyTagKey(options), - fetcher: async () => { - const { data } = await serviceWithEmptyTag({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchApiVbyApiVersionNoTag({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooWowMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await fooWow({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithoutParametersAndResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { - return { - key: getCallWithoutParametersAndResponseKey(options), - fetcher: async () => { - const { data } = await getCallWithoutParametersAndResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDescriptionsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/descriptions/', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDescriptions({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameterPath}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithWeirdParameterNamesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultParametersKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/defaults' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithDefaultParametersOptions = (options: Options) => { - return { - key: callWithDefaultParametersKey(options), - fetcher: async () => { - const { data } = await callWithDefaultParameters({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultOptionalParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callToTestOrderOfParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callToTestOrderOfParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateNameMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName2Key = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/duplicate' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const duplicateName2Options = (options?: Options) => { - return { - key: duplicateName2Key(options), - fetcher: async () => { - const { data } = await duplicateName2({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName3Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName3({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName4Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName4({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithNoContentResponseOptions = (options?: Options) => { - return { - key: callWithNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseAndNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/response-and-no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { - return { - key: callWithResponseAndNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponseAndNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyAKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/a' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyAOptions = (options?: Options) => { - return { - key: dummyAKey(options), - fetcher: async () => { - const { data } = await dummyA({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyBKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/b' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyBOptions = (options?: Options) => { - return { - key: dummyBKey(options), - fetcher: async () => { - const { data } = await dummyB({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/response' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseOptions = (options?: Options) => { - return { - key: callWithResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDuplicateResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const collectionFormatKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/collectionFormat' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const collectionFormatOptions = (options: Options) => { - return { - key: collectionFormatKey(options), - fetcher: async () => { - const { data } = await collectionFormat({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const typesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/types' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const typesOptions = (options: Options) => { - return { - key: typesKey(options), - fetcher: async () => { - const { data } = await types({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexTypesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/complex' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const complexTypesOptions = (options: Options) => { - return { - key: complexTypesKey(options), - fetcher: async () => { - const { data } = await complexTypes({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResultFromHeaderMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/header', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const testErrorCodeMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/error', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await testErrorCode({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; + +export const serviceWithEmptyTagKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; + +export const serviceWithEmptyTagOptions = (options?: Options) => ({ + key: serviceWithEmptyTagKey(options), + fetcher: async () => { + const { data } = await serviceWithEmptyTag({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooWowMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDescriptionsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/descriptions/", options] : ["/api/v{api-version}/descriptions/"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithWeirdParameterNamesMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDefaultParametersKey = (options: Options) => ["/api/v{api-version}/defaults", options]; + +export const callWithDefaultParametersOptions = (options: Options) => ({ + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callToTestOrderOfParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateNameMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; + +export const duplicateName2Options = (options?: Options) => ({ + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ ...options, throwOnError: true }); + return data; + } +}); + +export const duplicateName3Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName4Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; + +export const callWithNoContentResponseOptions = (options?: Options) => ({ + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; + +export const dummyAOptions = (options?: Options) => ({ + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; + +export const dummyBOptions = (options?: Options) => ({ + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; + +export const callWithResponseOptions = (options?: Options) => ({ + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDuplicateResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const collectionFormatKey = (options: Options) => ["/api/v{api-version}/collectionFormat", options]; + +export const collectionFormatOptions = (options: Options) => ({ + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ ...options, throwOnError: true }); + return data; + } +}); + +export const typesKey = (options: Options) => ["/api/v{api-version}/types", options]; + +export const typesOptions = (options: Options) => ({ + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ ...options, throwOnError: true }); + return data; + } +}); + +export const complexTypesKey = (options: Options) => ["/api/v{api-version}/complex", options]; + +export const complexTypesOptions = (options: Options) => ({ + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResultFromHeaderMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/header"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const testErrorCodeMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * Body should not be unknown * * Body should not be unknown */ -export const postApiVbyApiVersionBodyMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/body', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const postApiVbyApiVersionBodyMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/body"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts index 586defdb49..df351d6b75 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts @@ -3,124 +3,81 @@ import { BarBazService, FooBazService, type Options } from './sdk.gen'; import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarData, GetFooData } from './types.gen'; -export const getFooKey = (options?: Options) => { - const key: any[] = [ - '/foo' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; -export const getFooOptions = (options?: Options) => { - return { - key: getFooKey(options), - fetcher: async () => { - const { data } = await FooBazService.getFoo({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooKey = (options?: Options) => ["/foo"]; -export const fooPostMutation = (options?: Options) => { - return { - key: '/foo', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooPutMutation = (options?: Options) => { - return { - key: '/foo', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.put({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getFooBarKey = (options?: Options) => { - const key: any[] = [ - '/foo/bar' - ]; - if (options?.path) { - key.push({ path: options.path }); +export const getFooOptions = (options?: Options) => ({ + key: getFooKey(options), + fetcher: async () => { + const { data } = await FooBazService.getFoo({ ...options, throwOnError: true }); + return data; } - if (options?.query) { - key.push({ query: options.query }); +}); + +export const fooPostMutation = (options?: Options) => ({ + key: ["/foo"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; } - if (options?.body) { - key.push({ body: options.body }); +}); + +export const fooPutMutation = (options?: Options) => ({ + key: ["/foo"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; } - return key; -}; +}); -export const getFooBarOptions = (options?: Options) => { - return { - key: getFooBarKey(options), - fetcher: async () => { - const { data } = await BarBazService.getFooBar({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooBarKey = (options?: Options) => ["/foo/bar"]; -export const fooBarPostMutation = (options?: Options) => { - return { - key: '/foo/bar', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooBarOptions = (options?: Options) => ({ + key: getFooBarKey(options), + fetcher: async () => { + const { data } = await BarBazService.getFooBar({ ...options, throwOnError: true }); + return data; + } +}); -export const fooBarPutMutation = (options?: Options) => { - return { - key: '/foo/bar', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.barService.put({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const fooBarPostMutation = (options?: Options) => ({ + key: ["/foo/bar"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooBarPutMutation = (options?: Options) => ({ + key: ["/foo/bar"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts index 1fb85af58b..0596eef0ce 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts @@ -3,997 +3,595 @@ 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData } from './types.gen'; -export const exportKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no+tag' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const exportOptions = (options?: Options) => { - return { - key: exportKey(options), - fetcher: async () => { - const { data } = await export_({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchApiVbyApiVersionNoTag({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const importMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await import_({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooWowMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await fooWow({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const apiVVersionODataControllerCountKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple/$count' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const apiVVersionODataControllerCountOptions = (options?: Options) => { - return { - key: apiVVersionODataControllerCountKey(options), - fetcher: async () => { - const { data } = await apiVVersionODataControllerCount({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple:operation' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => { - return { - key: getApiVbyApiVersionSimpleOperationKey(options), - fetcher: async () => { - const { data } = await getApiVbyApiVersionSimpleOperation({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithoutParametersAndResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { - return { - key: getCallWithoutParametersAndResponseKey(options), - fetcher: async () => { - const { data } = await getCallWithoutParametersAndResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteFooMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteFoo({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDescriptionsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/descriptions', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDescriptions({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; + +export const exportKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; + +export const exportOptions = (options?: Options) => ({ + key: exportKey(options), + fetcher: async () => { + const { data } = await export_({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const importMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await import_({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooWowMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const apiVVersionODataControllerCountKey = (options?: Options) => ["/api/v{api-version}/simple/$count"]; + +export const apiVVersionODataControllerCountOptions = (options?: Options) => ({ + key: apiVVersionODataControllerCountKey(options), + fetcher: async () => { + const { data } = await apiVVersionODataControllerCount({ ...options, throwOnError: true }); + return data; + } +}); + +export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => ["/api/v{api-version}/simple:operation", options]; + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => ({ + key: getApiVbyApiVersionSimpleOperationKey(options), + fetcher: async () => { + const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, throwOnError: true }); + return data; + } +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const deleteFooMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}", options] : ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await deleteFoo({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDescriptionsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/descriptions", options] : ["/api/v{api-version}/descriptions"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * @deprecated */ -export const deprecatedCallMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/deprecated', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deprecatedCall({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameterPath}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithWeirdParameterNamesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithOptionalParamKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/parameters' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithOptionalParamOptions = (options: Options) => { - return { - key: getCallWithOptionalParamKey(options), - fetcher: async () => { - const { data } = await getCallWithOptionalParam({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithOptionalParamInfinite = (options: Options) => { - return { - getKey: (pageIndex: number, previousPageData: any) => { - const pageParam = { - query: { - page: pageIndex - } - }; - const key: any[] = [ - '/api/v{api-version}/parameters' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - const mergedQuery = { ...options?.query, ...pageParam.query }; - key.push({ query: mergedQuery }); - if (options?.body) { - key.push({ body: options.body }); - } - return key; - }, - fetcher: async (key) => { - const params = Object.assign({}, ...key.slice(1)); - const { data } = await getCallWithOptionalParam({ - ...params, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithOptionalParamMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithOptionalParam({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/requestBody', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionRequestBody({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postApiVbyApiVersionFormDataMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/formData', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionFormData({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultParametersKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/defaults' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithDefaultParametersOptions = (options?: Options) => { - return { - key: callWithDefaultParametersKey(options), - fetcher: async () => { - const { data } = await callWithDefaultParameters({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultOptionalParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callToTestOrderOfParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callToTestOrderOfParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateNameMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName2Key = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/duplicate' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const duplicateName2Options = (options?: Options) => { - return { - key: duplicateName2Key(options), - fetcher: async () => { - const { data } = await duplicateName2({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName3Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName3({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName4Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName4({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithNoContentResponseOptions = (options?: Options) => { - return { - key: callWithNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseAndNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/response-and-no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { - return { - key: callWithResponseAndNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponseAndNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyAKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/a' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyAOptions = (options?: Options) => { - return { - key: dummyAKey(options), - fetcher: async () => { - const { data } = await dummyA({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyBKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/b' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyBOptions = (options?: Options) => { - return { - key: dummyBKey(options), - fetcher: async () => { - const { data } = await dummyB({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/response' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseOptions = (options?: Options) => { - return { - key: callWithResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDuplicateResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const collectionFormatKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/collectionFormat' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const collectionFormatOptions = (options: Options) => { - return { - key: collectionFormatKey(options), - fetcher: async () => { - const { data } = await collectionFormat({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const typesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/types' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const typesOptions = (options: Options) => { - return { - key: typesKey(options), - fetcher: async () => { - const { data } = await types({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const uploadFileMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/upload', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await uploadFile({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fileResponseKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/file/{id}' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const fileResponseOptions = (options: Options) => { - return { - key: fileResponseKey(options), - fetcher: async () => { - const { data } = await fileResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexTypesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/complex' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const complexTypesOptions = (options: Options) => { - return { - key: complexTypesKey(options), - fetcher: async () => { - const { data } = await complexTypes({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const multipartResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multipart' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const multipartResponseOptions = (options?: Options) => { - return { - key: multipartResponseKey(options), - fetcher: async () => { - const { data } = await multipartResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const multipartRequestMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/multipart', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await multipartRequest({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/complex/{id}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await complexParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResultFromHeaderMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/header', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const testErrorCodeMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/error', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await testErrorCode({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const deprecatedCallMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/parameters/deprecated"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deprecatedCall({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithWeirdParameterNamesMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithOptionalParamKey = (options: Options) => ["/api/v{api-version}/parameters", options]; + +export const getCallWithOptionalParamOptions = (options: Options) => ({ + key: getCallWithOptionalParamKey(options), + fetcher: async () => { + const { data } = await getCallWithOptionalParam({ ...options, throwOnError: true }); + return data; + } +}); + +export const getCallWithOptionalParamInfinite = (options: Options) => ({ + getKey: (pageIndex: number, previousPageData: unknown | null) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], + fetcher: async (key: readonly [string, Options]) => { + const { data } = await getCallWithOptionalParam({ ...key[1], throwOnError: true }); + return data; + } +}); + +export const postCallWithOptionalParamMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters", options] : ["/api/v{api-version}/parameters"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/requestBody", options] : ["/api/v{api-version}/requestBody"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postApiVbyApiVersionFormDataMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/formData", options] : ["/api/v{api-version}/formData"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDefaultParametersKey = (options?: Options) => ["/api/v{api-version}/defaults", options]; + +export const callWithDefaultParametersOptions = (options?: Options) => ({ + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callToTestOrderOfParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateNameMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; + +export const duplicateName2Options = (options?: Options) => ({ + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ ...options, throwOnError: true }); + return data; + } +}); + +export const duplicateName3Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName4Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; + +export const callWithNoContentResponseOptions = (options?: Options) => ({ + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; + +export const dummyAOptions = (options?: Options) => ({ + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; + +export const dummyBOptions = (options?: Options) => ({ + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; + +export const callWithResponseOptions = (options?: Options) => ({ + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDuplicateResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const collectionFormatKey = (options: Options) => ["/api/v{api-version}/collectionFormat", options]; + +export const collectionFormatOptions = (options: Options) => ({ + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ ...options, throwOnError: true }); + return data; + } +}); + +export const typesKey = (options: Options) => ["/api/v{api-version}/types", options]; + +export const typesOptions = (options: Options) => ({ + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ ...options, throwOnError: true }); + return data; + } +}); + +export const uploadFileMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/upload", options] : ["/api/v{api-version}/upload"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fileResponseKey = (options: Options) => ["/api/v{api-version}/file/{id}", options]; + +export const fileResponseOptions = (options: Options) => ({ + key: fileResponseKey(options), + fetcher: async () => { + const { data } = await fileResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const complexTypesKey = (options: Options) => ["/api/v{api-version}/complex", options]; + +export const complexTypesOptions = (options: Options) => ({ + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ ...options, throwOnError: true }); + return data; + } +}); + +export const multipartResponseKey = (options?: Options) => ["/api/v{api-version}/multipart"]; + +export const multipartResponseOptions = (options?: Options) => ({ + key: multipartResponseKey(options), + fetcher: async () => { + const { data } = await multipartResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const multipartRequestMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/multipart"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await multipartRequest({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const complexParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/complex/{id}", options] : ["/api/v{api-version}/complex/{id}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await complexParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResultFromHeaderMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/header"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const testErrorCodeMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * Login User */ -export const putWithFormUrlEncodedMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putWithFormUrlEncoded({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const putWithFormUrlEncodedMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts index 1fb85af58b..0596eef0ce 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts @@ -3,997 +3,595 @@ 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData } from './types.gen'; -export const exportKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no+tag' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const exportOptions = (options?: Options) => { - return { - key: exportKey(options), - fetcher: async () => { - const { data } = await export_({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchApiVbyApiVersionNoTag({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const importMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await import_({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooWowMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await fooWow({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const apiVVersionODataControllerCountKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple/$count' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const apiVVersionODataControllerCountOptions = (options?: Options) => { - return { - key: apiVVersionODataControllerCountKey(options), - fetcher: async () => { - const { data } = await apiVVersionODataControllerCount({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple:operation' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => { - return { - key: getApiVbyApiVersionSimpleOperationKey(options), - fetcher: async () => { - const { data } = await getApiVbyApiVersionSimpleOperation({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithoutParametersAndResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { - return { - key: getCallWithoutParametersAndResponseKey(options), - fetcher: async () => { - const { data } = await getCallWithoutParametersAndResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteFooMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteFoo({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDescriptionsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/descriptions', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDescriptions({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; + +export const exportKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; + +export const exportOptions = (options?: Options) => ({ + key: exportKey(options), + fetcher: async () => { + const { data } = await export_({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const importMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await import_({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooWowMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const apiVVersionODataControllerCountKey = (options?: Options) => ["/api/v{api-version}/simple/$count"]; + +export const apiVVersionODataControllerCountOptions = (options?: Options) => ({ + key: apiVVersionODataControllerCountKey(options), + fetcher: async () => { + const { data } = await apiVVersionODataControllerCount({ ...options, throwOnError: true }); + return data; + } +}); + +export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => ["/api/v{api-version}/simple:operation", options]; + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => ({ + key: getApiVbyApiVersionSimpleOperationKey(options), + fetcher: async () => { + const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, throwOnError: true }); + return data; + } +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const deleteFooMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}", options] : ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await deleteFoo({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDescriptionsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/descriptions", options] : ["/api/v{api-version}/descriptions"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * @deprecated */ -export const deprecatedCallMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/deprecated', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deprecatedCall({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameterPath}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithWeirdParameterNamesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithOptionalParamKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/parameters' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithOptionalParamOptions = (options: Options) => { - return { - key: getCallWithOptionalParamKey(options), - fetcher: async () => { - const { data } = await getCallWithOptionalParam({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithOptionalParamInfinite = (options: Options) => { - return { - getKey: (pageIndex: number, previousPageData: any) => { - const pageParam = { - query: { - page: pageIndex - } - }; - const key: any[] = [ - '/api/v{api-version}/parameters' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - const mergedQuery = { ...options?.query, ...pageParam.query }; - key.push({ query: mergedQuery }); - if (options?.body) { - key.push({ body: options.body }); - } - return key; - }, - fetcher: async (key) => { - const params = Object.assign({}, ...key.slice(1)); - const { data } = await getCallWithOptionalParam({ - ...params, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithOptionalParamMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithOptionalParam({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/requestBody', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionRequestBody({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postApiVbyApiVersionFormDataMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/formData', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionFormData({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultParametersKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/defaults' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithDefaultParametersOptions = (options?: Options) => { - return { - key: callWithDefaultParametersKey(options), - fetcher: async () => { - const { data } = await callWithDefaultParameters({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultOptionalParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callToTestOrderOfParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callToTestOrderOfParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateNameMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName2Key = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/duplicate' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const duplicateName2Options = (options?: Options) => { - return { - key: duplicateName2Key(options), - fetcher: async () => { - const { data } = await duplicateName2({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName3Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName3({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName4Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName4({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithNoContentResponseOptions = (options?: Options) => { - return { - key: callWithNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseAndNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/response-and-no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { - return { - key: callWithResponseAndNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponseAndNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyAKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/a' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyAOptions = (options?: Options) => { - return { - key: dummyAKey(options), - fetcher: async () => { - const { data } = await dummyA({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyBKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/b' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyBOptions = (options?: Options) => { - return { - key: dummyBKey(options), - fetcher: async () => { - const { data } = await dummyB({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/response' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseOptions = (options?: Options) => { - return { - key: callWithResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDuplicateResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const collectionFormatKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/collectionFormat' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const collectionFormatOptions = (options: Options) => { - return { - key: collectionFormatKey(options), - fetcher: async () => { - const { data } = await collectionFormat({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const typesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/types' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const typesOptions = (options: Options) => { - return { - key: typesKey(options), - fetcher: async () => { - const { data } = await types({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const uploadFileMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/upload', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await uploadFile({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fileResponseKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/file/{id}' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const fileResponseOptions = (options: Options) => { - return { - key: fileResponseKey(options), - fetcher: async () => { - const { data } = await fileResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexTypesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/complex' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const complexTypesOptions = (options: Options) => { - return { - key: complexTypesKey(options), - fetcher: async () => { - const { data } = await complexTypes({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const multipartResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multipart' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const multipartResponseOptions = (options?: Options) => { - return { - key: multipartResponseKey(options), - fetcher: async () => { - const { data } = await multipartResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const multipartRequestMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/multipart', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await multipartRequest({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/complex/{id}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await complexParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResultFromHeaderMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/header', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const testErrorCodeMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/error', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await testErrorCode({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const deprecatedCallMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/parameters/deprecated"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deprecatedCall({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithWeirdParameterNamesMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithOptionalParamKey = (options: Options) => ["/api/v{api-version}/parameters", options]; + +export const getCallWithOptionalParamOptions = (options: Options) => ({ + key: getCallWithOptionalParamKey(options), + fetcher: async () => { + const { data } = await getCallWithOptionalParam({ ...options, throwOnError: true }); + return data; + } +}); + +export const getCallWithOptionalParamInfinite = (options: Options) => ({ + getKey: (pageIndex: number, previousPageData: unknown | null) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], + fetcher: async (key: readonly [string, Options]) => { + const { data } = await getCallWithOptionalParam({ ...key[1], throwOnError: true }); + return data; + } +}); + +export const postCallWithOptionalParamMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters", options] : ["/api/v{api-version}/parameters"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/requestBody", options] : ["/api/v{api-version}/requestBody"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postApiVbyApiVersionFormDataMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/formData", options] : ["/api/v{api-version}/formData"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDefaultParametersKey = (options?: Options) => ["/api/v{api-version}/defaults", options]; + +export const callWithDefaultParametersOptions = (options?: Options) => ({ + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callToTestOrderOfParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateNameMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; + +export const duplicateName2Options = (options?: Options) => ({ + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ ...options, throwOnError: true }); + return data; + } +}); + +export const duplicateName3Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName4Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; + +export const callWithNoContentResponseOptions = (options?: Options) => ({ + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; + +export const dummyAOptions = (options?: Options) => ({ + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; + +export const dummyBOptions = (options?: Options) => ({ + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; + +export const callWithResponseOptions = (options?: Options) => ({ + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDuplicateResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const collectionFormatKey = (options: Options) => ["/api/v{api-version}/collectionFormat", options]; + +export const collectionFormatOptions = (options: Options) => ({ + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ ...options, throwOnError: true }); + return data; + } +}); + +export const typesKey = (options: Options) => ["/api/v{api-version}/types", options]; + +export const typesOptions = (options: Options) => ({ + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ ...options, throwOnError: true }); + return data; + } +}); + +export const uploadFileMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/upload", options] : ["/api/v{api-version}/upload"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fileResponseKey = (options: Options) => ["/api/v{api-version}/file/{id}", options]; + +export const fileResponseOptions = (options: Options) => ({ + key: fileResponseKey(options), + fetcher: async () => { + const { data } = await fileResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const complexTypesKey = (options: Options) => ["/api/v{api-version}/complex", options]; + +export const complexTypesOptions = (options: Options) => ({ + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ ...options, throwOnError: true }); + return data; + } +}); + +export const multipartResponseKey = (options?: Options) => ["/api/v{api-version}/multipart"]; + +export const multipartResponseOptions = (options?: Options) => ({ + key: multipartResponseKey(options), + fetcher: async () => { + const { data } = await multipartResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const multipartRequestMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/multipart"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await multipartRequest({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const complexParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/complex/{id}", options] : ["/api/v{api-version}/complex/{id}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await complexParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResultFromHeaderMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/header"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const testErrorCodeMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * Login User */ -export const putWithFormUrlEncodedMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putWithFormUrlEncoded({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const putWithFormUrlEncodedMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/client.gen.ts index 8bd1d5631c..7fa8716b65 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/client.gen.ts index f0000c3c17..822f12931c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts index 586defdb49..df351d6b75 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts @@ -3,124 +3,81 @@ import { BarBazService, FooBazService, type Options } from './sdk.gen'; import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarData, GetFooData } from './types.gen'; -export const getFooKey = (options?: Options) => { - const key: any[] = [ - '/foo' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; -export const getFooOptions = (options?: Options) => { - return { - key: getFooKey(options), - fetcher: async () => { - const { data } = await FooBazService.getFoo({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooKey = (options?: Options) => ["/foo"]; -export const fooPostMutation = (options?: Options) => { - return { - key: '/foo', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooPutMutation = (options?: Options) => { - return { - key: '/foo', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.put({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getFooBarKey = (options?: Options) => { - const key: any[] = [ - '/foo/bar' - ]; - if (options?.path) { - key.push({ path: options.path }); +export const getFooOptions = (options?: Options) => ({ + key: getFooKey(options), + fetcher: async () => { + const { data } = await FooBazService.getFoo({ ...options, throwOnError: true }); + return data; } - if (options?.query) { - key.push({ query: options.query }); +}); + +export const fooPostMutation = (options?: Options) => ({ + key: ["/foo"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; } - if (options?.body) { - key.push({ body: options.body }); +}); + +export const fooPutMutation = (options?: Options) => ({ + key: ["/foo"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; } - return key; -}; +}); -export const getFooBarOptions = (options?: Options) => { - return { - key: getFooBarKey(options), - fetcher: async () => { - const { data } = await BarBazService.getFooBar({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooBarKey = (options?: Options) => ["/foo/bar"]; -export const fooBarPostMutation = (options?: Options) => { - return { - key: '/foo/bar', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const getFooBarOptions = (options?: Options) => ({ + key: getFooBarKey(options), + fetcher: async () => { + const { data } = await BarBazService.getFooBar({ ...options, throwOnError: true }); + return data; + } +}); -export const fooBarPutMutation = (options?: Options) => { - return { - key: '/foo/bar', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await FooBazService.fooService.barService.put({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const fooBarPostMutation = (options?: Options) => ({ + key: ["/foo/bar"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.post({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooBarPutMutation = (options?: Options) => ({ + key: ["/foo/bar"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await FooBazService.fooService.barService.put({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts index 4f818115be..0596eef0ce 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts @@ -3,997 +3,595 @@ 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData } from './types.gen'; -export const exportKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no+tag' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const exportOptions = (options?: Options) => { - return { - key: exportKey(options), - fetcher: async () => { - const { data } = await export_({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchApiVbyApiVersionNoTag({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const importMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await import_({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooWowMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await fooWow({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const apiVVersionODataControllerCountKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple/$count' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const apiVVersionODataControllerCountOptions = (options?: Options) => { - return { - key: apiVVersionODataControllerCountKey(options), - fetcher: async () => { - const { data } = await apiVVersionODataControllerCount({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple:operation' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => { - return { - key: getApiVbyApiVersionSimpleOperationKey(options), - fetcher: async () => { - const { data } = await getApiVbyApiVersionSimpleOperation({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithoutParametersAndResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { - return { - key: getCallWithoutParametersAndResponseKey(options), - fetcher: async () => { - const { data } = await getCallWithoutParametersAndResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteFooMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteFoo({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDescriptionsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/descriptions', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDescriptions({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; + +export const exportKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; + +export const exportOptions = (options?: Options) => ({ + key: exportKey(options), + fetcher: async () => { + const { data } = await export_({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const importMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await import_({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooWowMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const apiVVersionODataControllerCountKey = (options?: Options) => ["/api/v{api-version}/simple/$count"]; + +export const apiVVersionODataControllerCountOptions = (options?: Options) => ({ + key: apiVVersionODataControllerCountKey(options), + fetcher: async () => { + const { data } = await apiVVersionODataControllerCount({ ...options, throwOnError: true }); + return data; + } +}); + +export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => ["/api/v{api-version}/simple:operation", options]; + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => ({ + key: getApiVbyApiVersionSimpleOperationKey(options), + fetcher: async () => { + const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, throwOnError: true }); + return data; + } +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const deleteFooMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}", options] : ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await deleteFoo({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDescriptionsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/descriptions", options] : ["/api/v{api-version}/descriptions"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * @deprecated */ -export const deprecatedCallMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/deprecated', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deprecatedCall({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameterPath}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithWeirdParameterNamesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithOptionalParamKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/parameters' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithOptionalParamOptions = (options: Options) => { - return { - key: getCallWithOptionalParamKey(options), - fetcher: async () => { - const { data } = await getCallWithOptionalParam({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithOptionalParamInfinite = (options: Options) => { - return { - getKey: (pageIndex: number) => { - const pageParam = { - query: { - page: pageIndex - } - }; - const key: any[] = [ - '/api/v{api-version}/parameters' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - const mergedQuery = { ...options?.query, ...pageParam.query }; - key.push({ query: mergedQuery }); - if (options?.body) { - key.push({ body: options.body }); - } - return key; - }, - fetcher: async (key: unknown[]) => { - const params = Object.assign({}, ...key.slice(1)); - const { data } = await getCallWithOptionalParam({ - ...params, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithOptionalParamMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithOptionalParam({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/requestBody', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionRequestBody({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postApiVbyApiVersionFormDataMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/formData', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionFormData({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultParametersKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/defaults' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithDefaultParametersOptions = (options?: Options) => { - return { - key: callWithDefaultParametersKey(options), - fetcher: async () => { - const { data } = await callWithDefaultParameters({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultOptionalParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callToTestOrderOfParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callToTestOrderOfParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateNameMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName2Key = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/duplicate' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const duplicateName2Options = (options?: Options) => { - return { - key: duplicateName2Key(options), - fetcher: async () => { - const { data } = await duplicateName2({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName3Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName3({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName4Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName4({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithNoContentResponseOptions = (options?: Options) => { - return { - key: callWithNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseAndNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/response-and-no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { - return { - key: callWithResponseAndNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponseAndNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyAKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/a' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyAOptions = (options?: Options) => { - return { - key: dummyAKey(options), - fetcher: async () => { - const { data } = await dummyA({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyBKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/b' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyBOptions = (options?: Options) => { - return { - key: dummyBKey(options), - fetcher: async () => { - const { data } = await dummyB({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/response' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseOptions = (options?: Options) => { - return { - key: callWithResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDuplicateResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const collectionFormatKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/collectionFormat' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const collectionFormatOptions = (options: Options) => { - return { - key: collectionFormatKey(options), - fetcher: async () => { - const { data } = await collectionFormat({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const typesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/types' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const typesOptions = (options: Options) => { - return { - key: typesKey(options), - fetcher: async () => { - const { data } = await types({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const uploadFileMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/upload', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await uploadFile({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fileResponseKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/file/{id}' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const fileResponseOptions = (options: Options) => { - return { - key: fileResponseKey(options), - fetcher: async () => { - const { data } = await fileResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexTypesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/complex' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const complexTypesOptions = (options: Options) => { - return { - key: complexTypesKey(options), - fetcher: async () => { - const { data } = await complexTypes({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const multipartResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multipart' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const multipartResponseOptions = (options?: Options) => { - return { - key: multipartResponseKey(options), - fetcher: async () => { - const { data } = await multipartResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const multipartRequestMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/multipart', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await multipartRequest({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/complex/{id}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await complexParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResultFromHeaderMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/header', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const testErrorCodeMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/error', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await testErrorCode({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const deprecatedCallMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/parameters/deprecated"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deprecatedCall({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithWeirdParameterNamesMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithOptionalParamKey = (options: Options) => ["/api/v{api-version}/parameters", options]; + +export const getCallWithOptionalParamOptions = (options: Options) => ({ + key: getCallWithOptionalParamKey(options), + fetcher: async () => { + const { data } = await getCallWithOptionalParam({ ...options, throwOnError: true }); + return data; + } +}); + +export const getCallWithOptionalParamInfinite = (options: Options) => ({ + getKey: (pageIndex: number, previousPageData: unknown | null) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], + fetcher: async (key: readonly [string, Options]) => { + const { data } = await getCallWithOptionalParam({ ...key[1], throwOnError: true }); + return data; + } +}); + +export const postCallWithOptionalParamMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters", options] : ["/api/v{api-version}/parameters"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/requestBody", options] : ["/api/v{api-version}/requestBody"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postApiVbyApiVersionFormDataMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/formData", options] : ["/api/v{api-version}/formData"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDefaultParametersKey = (options?: Options) => ["/api/v{api-version}/defaults", options]; + +export const callWithDefaultParametersOptions = (options?: Options) => ({ + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callToTestOrderOfParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateNameMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; + +export const duplicateName2Options = (options?: Options) => ({ + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ ...options, throwOnError: true }); + return data; + } +}); + +export const duplicateName3Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName4Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; + +export const callWithNoContentResponseOptions = (options?: Options) => ({ + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; + +export const dummyAOptions = (options?: Options) => ({ + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; + +export const dummyBOptions = (options?: Options) => ({ + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; + +export const callWithResponseOptions = (options?: Options) => ({ + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDuplicateResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const collectionFormatKey = (options: Options) => ["/api/v{api-version}/collectionFormat", options]; + +export const collectionFormatOptions = (options: Options) => ({ + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ ...options, throwOnError: true }); + return data; + } +}); + +export const typesKey = (options: Options) => ["/api/v{api-version}/types", options]; + +export const typesOptions = (options: Options) => ({ + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ ...options, throwOnError: true }); + return data; + } +}); + +export const uploadFileMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/upload", options] : ["/api/v{api-version}/upload"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fileResponseKey = (options: Options) => ["/api/v{api-version}/file/{id}", options]; + +export const fileResponseOptions = (options: Options) => ({ + key: fileResponseKey(options), + fetcher: async () => { + const { data } = await fileResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const complexTypesKey = (options: Options) => ["/api/v{api-version}/complex", options]; + +export const complexTypesOptions = (options: Options) => ({ + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ ...options, throwOnError: true }); + return data; + } +}); + +export const multipartResponseKey = (options?: Options) => ["/api/v{api-version}/multipart"]; + +export const multipartResponseOptions = (options?: Options) => ({ + key: multipartResponseKey(options), + fetcher: async () => { + const { data } = await multipartResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const multipartRequestMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/multipart"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await multipartRequest({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const complexParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/complex/{id}", options] : ["/api/v{api-version}/complex/{id}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await complexParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResultFromHeaderMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/header"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const testErrorCodeMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * Login User */ -export const putWithFormUrlEncodedMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putWithFormUrlEncoded({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const putWithFormUrlEncodedMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts index 1fb85af58b..0596eef0ce 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts @@ -3,997 +3,595 @@ 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData } from './types.gen'; -export const exportKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no+tag' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const exportOptions = (options?: Options) => { - return { - key: exportKey(options), - fetcher: async () => { - const { data } = await export_({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchApiVbyApiVersionNoTag({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const importMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await import_({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fooWowMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/no+tag', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await fooWow({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const apiVVersionODataControllerCountKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple/$count' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const apiVVersionODataControllerCountOptions = (options?: Options) => { - return { - key: apiVVersionODataControllerCountKey(options), - fetcher: async () => { - const { data } = await apiVVersionODataControllerCount({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple:operation' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => { - return { - key: getApiVbyApiVersionSimpleOperationKey(options), - fetcher: async () => { - const { data } = await getApiVbyApiVersionSimpleOperation({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithoutParametersAndResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/simple' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => { - return { - key: getCallWithoutParametersAndResponseKey(options), - fetcher: async () => { - const { data } = await getCallWithoutParametersAndResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await patchCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const putCallWithoutParametersAndResponseMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/simple', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putCallWithoutParametersAndResponse({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const deleteFooMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deleteFoo({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDescriptionsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/descriptions', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDescriptions({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +/* eslint-disable @typescript-eslint/no-unused-vars */ +; + +export const exportKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; + +export const exportOptions = (options?: Options) => ({ + key: exportKey(options), + fetcher: async () => { + const { data } = await export_({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchApiVbyApiVersionNoTag({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const importMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await import_({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fooWowMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/no+tag"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await fooWow({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const apiVVersionODataControllerCountKey = (options?: Options) => ["/api/v{api-version}/simple/$count"]; + +export const apiVVersionODataControllerCountOptions = (options?: Options) => ({ + key: apiVVersionODataControllerCountKey(options), + fetcher: async () => { + const { data } = await apiVVersionODataControllerCount({ ...options, throwOnError: true }); + return data; + } +}); + +export const getApiVbyApiVersionSimpleOperationKey = (options: Options) => ["/api/v{api-version}/simple:operation", options]; + +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => ({ + key: getApiVbyApiVersionSimpleOperationKey(options), + fetcher: async () => { + const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, throwOnError: true }); + return data; + } +}); + +export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deleteCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; + +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ + key: getCallWithoutParametersAndResponseKey(options), + fetcher: async () => { + const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const patchCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await patchCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/simple"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putCallWithoutParametersAndResponse({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const deleteFooMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}", options] : ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await deleteFoo({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDescriptionsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/descriptions", options] : ["/api/v{api-version}/descriptions"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDescriptions({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * @deprecated */ -export const deprecatedCallMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/deprecated', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await deprecatedCall({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameterPath}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithWeirdParameterNamesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithOptionalParamKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/parameters' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const getCallWithOptionalParamOptions = (options: Options) => { - return { - key: getCallWithOptionalParamKey(options), - fetcher: async () => { - const { data } = await getCallWithOptionalParam({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const getCallWithOptionalParamInfinite = (options: Options) => { - return { - getKey: (pageIndex: number, previousPageData: any) => { - const pageParam = { - query: { - page: pageIndex - } - }; - const key: any[] = [ - '/api/v{api-version}/parameters' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - const mergedQuery = { ...options?.query, ...pageParam.query }; - key.push({ query: mergedQuery }); - if (options?.body) { - key.push({ body: options.body }); - } - return key; - }, - fetcher: async (key) => { - const params = Object.assign({}, ...key.slice(1)); - const { data } = await getCallWithOptionalParam({ - ...params, - throwOnError: true - }); - return data; - } - }; -}; - -export const postCallWithOptionalParamMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/parameters', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postCallWithOptionalParam({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/requestBody', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionRequestBody({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const postApiVbyApiVersionFormDataMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/formData', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await postApiVbyApiVersionFormData({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultParametersKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/defaults' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithDefaultParametersOptions = (options?: Options) => { - return { - key: callWithDefaultParametersKey(options), - fetcher: async () => { - const { data } = await callWithDefaultParameters({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDefaultOptionalParametersMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callToTestOrderOfParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/defaults', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callToTestOrderOfParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateNameMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName2Key = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/duplicate' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const duplicateName2Options = (options?: Options) => { - return { - key: duplicateName2Key(options), - fetcher: async () => { - const { data } = await duplicateName2({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName3Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName3({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const duplicateName4Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/duplicate', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await duplicateName4({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithNoContentResponseOptions = (options?: Options) => { - return { - key: callWithNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseAndNoContentResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/response-and-no-content' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => { - return { - key: callWithResponseAndNoContentResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponseAndNoContentResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyAKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/a' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyAOptions = (options?: Options) => { - return { - key: dummyAKey(options), - fetcher: async () => { - const { data } = await dummyA({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const dummyBKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multiple-tags/b' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const dummyBOptions = (options?: Options) => { - return { - key: dummyBKey(options), - fetcher: async () => { - const { data } = await dummyB({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/response' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const callWithResponseOptions = (options?: Options) => { - return { - key: callWithResponseKey(options), - fetcher: async () => { - const { data } = await callWithResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithDuplicateResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResponsesMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/response', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResponses({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const collectionFormatKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/collectionFormat' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const collectionFormatOptions = (options: Options) => { - return { - key: collectionFormatKey(options), - fetcher: async () => { - const { data } = await collectionFormat({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const typesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/types' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const typesOptions = (options: Options) => { - return { - key: typesKey(options), - fetcher: async () => { - const { data } = await types({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const uploadFileMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/upload', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await uploadFile({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const fileResponseKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/file/{id}' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const fileResponseOptions = (options: Options) => { - return { - key: fileResponseKey(options), - fetcher: async () => { - const { data } = await fileResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexTypesKey = (options: Options) => { - const key: any[] = [ - '/api/v{api-version}/complex' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const complexTypesOptions = (options: Options) => { - return { - key: complexTypesKey(options), - fetcher: async () => { - const { data } = await complexTypes({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const multipartResponseKey = (options?: Options) => { - const key: any[] = [ - '/api/v{api-version}/multipart' - ]; - if (options?.path) { - key.push({ path: options.path }); - } - if (options?.query) { - key.push({ query: options.query }); - } - if (options?.body) { - key.push({ body: options.body }); - } - return key; -}; - -export const multipartResponseOptions = (options?: Options) => { - return { - key: multipartResponseKey(options), - fetcher: async () => { - const { data } = await multipartResponse({ - ...options, - throwOnError: true - }); - return data; - } - }; -}; - -export const multipartRequestMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/multipart', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await multipartRequest({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const complexParamsMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/complex/{id}', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await complexParams({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const callWithResultFromHeaderMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/header', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const testErrorCodeMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/error', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await testErrorCode({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; - -export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const deprecatedCallMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/parameters/deprecated"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await deprecatedCall({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithWeirdParameterNamesMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const getCallWithOptionalParamKey = (options: Options) => ["/api/v{api-version}/parameters", options]; + +export const getCallWithOptionalParamOptions = (options: Options) => ({ + key: getCallWithOptionalParamKey(options), + fetcher: async () => { + const { data } = await getCallWithOptionalParam({ ...options, throwOnError: true }); + return data; + } +}); + +export const getCallWithOptionalParamInfinite = (options: Options) => ({ + getKey: (pageIndex: number, previousPageData: unknown | null) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], + fetcher: async (key: readonly [string, Options]) => { + const { data } = await getCallWithOptionalParam({ ...key[1], throwOnError: true }); + return data; + } +}); + +export const postCallWithOptionalParamMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/parameters", options] : ["/api/v{api-version}/parameters"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postCallWithOptionalParam({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/requestBody", options] : ["/api/v{api-version}/requestBody"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionRequestBody({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const postApiVbyApiVersionFormDataMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/formData", options] : ["/api/v{api-version}/formData"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await postApiVbyApiVersionFormData({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithDefaultParametersKey = (options?: Options) => ["/api/v{api-version}/defaults", options]; + +export const callWithDefaultParametersOptions = (options?: Options) => ({ + key: callWithDefaultParametersKey(options), + fetcher: async () => { + const { data } = await callWithDefaultParameters({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDefaultOptionalParameters({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callToTestOrderOfParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await callToTestOrderOfParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateNameMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; + +export const duplicateName2Options = (options?: Options) => ({ + key: duplicateName2Key(options), + fetcher: async () => { + const { data } = await duplicateName2({ ...options, throwOnError: true }); + return data; + } +}); + +export const duplicateName3Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName3({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const duplicateName4Mutation = (options?: Options) => ({ + key: ["/api/v{api-version}/duplicate"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await duplicateName4({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; + +export const callWithNoContentResponseOptions = (options?: Options) => ({ + key: callWithNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; + +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ + key: callWithResponseAndNoContentResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; + +export const dummyAOptions = (options?: Options) => ({ + key: dummyAKey(options), + fetcher: async () => { + const { data } = await dummyA({ ...options, throwOnError: true }); + return data; + } +}); + +export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; + +export const dummyBOptions = (options?: Options) => ({ + key: dummyBKey(options), + fetcher: async () => { + const { data } = await dummyB({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; + +export const callWithResponseOptions = (options?: Options) => ({ + key: callWithResponseKey(options), + fetcher: async () => { + const { data } = await callWithResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const callWithDuplicateResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithDuplicateResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResponsesMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/response"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResponses({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const collectionFormatKey = (options: Options) => ["/api/v{api-version}/collectionFormat", options]; + +export const collectionFormatOptions = (options: Options) => ({ + key: collectionFormatKey(options), + fetcher: async () => { + const { data } = await collectionFormat({ ...options, throwOnError: true }); + return data; + } +}); + +export const typesKey = (options: Options) => ["/api/v{api-version}/types", options]; + +export const typesOptions = (options: Options) => ({ + key: typesKey(options), + fetcher: async () => { + const { data } = await types({ ...options, throwOnError: true }); + return data; + } +}); + +export const uploadFileMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/upload", options] : ["/api/v{api-version}/upload"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await uploadFile({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const fileResponseKey = (options: Options) => ["/api/v{api-version}/file/{id}", options]; + +export const fileResponseOptions = (options: Options) => ({ + key: fileResponseKey(options), + fetcher: async () => { + const { data } = await fileResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const complexTypesKey = (options: Options) => ["/api/v{api-version}/complex", options]; + +export const complexTypesOptions = (options: Options) => ({ + key: complexTypesKey(options), + fetcher: async () => { + const { data } = await complexTypes({ ...options, throwOnError: true }); + return data; + } +}); + +export const multipartResponseKey = (options?: Options) => ["/api/v{api-version}/multipart"]; + +export const multipartResponseOptions = (options?: Options) => ({ + key: multipartResponseKey(options), + fetcher: async () => { + const { data } = await multipartResponse({ ...options, throwOnError: true }); + return data; + } +}); + +export const multipartRequestMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/multipart"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await multipartRequest({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const complexParamsMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/complex/{id}", options] : ["/api/v{api-version}/complex/{id}"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await complexParams({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const callWithResultFromHeaderMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/header"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await callWithResultFromHeader({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const testErrorCodeMutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await testErrorCode({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); + +export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ + key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + arg: Options; + }) => { + const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); /** * Login User */ -export const putWithFormUrlEncodedMutation = (options?: Options) => { - return { - key: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', - fetcher: async (_key: unknown, { arg }: { - arg: Options; - }) => { - const { data } = await putWithFormUrlEncoded({ - ...options, - ...arg, - throwOnError: true - }); - return data; - } - }; -}; +export const putWithFormUrlEncodedMutation = (options?: Options) => ({ + key: ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], + fetcher: async (_key: readonly [string], { arg }: { + arg: Options; + }) => { + const { data } = await putWithFormUrlEncoded({ + ...options, + ...arg, + throwOnError: true + }); + return data; + } +}); diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/client.gen.ts index f81a9e7863..b0628d02ab 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/client.gen.ts @@ -76,6 +76,7 @@ export const createClient = (config: Config = {}): Client => { try { // assign Axios here for consistency with fetch const _axios = opts.axios!; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { auth, ...optsWithoutAuth } = opts; const response = await _axios({ diff --git a/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts b/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts index 4fc0595d9c..ef0ad17dc0 100644 --- a/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts +++ b/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts @@ -141,11 +141,14 @@ describe('SWR Plugin Basic Generation', () => { expect(fileContent).toContain('Mutation ='); // Verify mutation fetcher signature with _key and arg - expect(fileContent).toContain('_key: unknown'); + // _key is now typed as readonly [string] instead of unknown + expect(fileContent).toContain('_key: readonly [string]'); expect(fileContent).toContain('{ arg }'); // Verify async fetcher for mutations with proper typing - expect(fileContent).toMatch(/fetcher: async \(_key: unknown, { arg }/); + expect(fileContent).toMatch( + /fetcher: async \(_key: readonly \[string\].*{ arg }/, + ); // Verify key and fetcher structure expect(fileContent).toContain('key:'); diff --git a/packages/openapi-ts-tests/main/test/plugins/swr/edge-cases.test.ts b/packages/openapi-ts-tests/main/test/plugins/swr/edge-cases.test.ts index ca99a94516..21e63a39a4 100644 --- a/packages/openapi-ts-tests/main/test/plugins/swr/edge-cases.test.ts +++ b/packages/openapi-ts-tests/main/test/plugins/swr/edge-cases.test.ts @@ -86,8 +86,9 @@ describe('SWR Plugin Edge Cases', () => { // Path parameters should be required expect(fileContent).toMatch(/\(options: Options \["\/[^"]*\{[^}]+\}[^"]*",\s*options\]/); } }); @@ -279,12 +280,13 @@ describe('SWR Plugin Edge Cases', () => { // Key functions should be generated expect(fileContent).toContain('Key ='); - // Keys should be functions that construct arrays (SWR format) - // Pattern: const key: any[] = [ '/path', ... - expect(fileContent).toMatch(/const key: any\[\] = \[/); + // Keys should be functions that return arrays (SWR format) + // With new refactoring: ['/path', options] or just ['/path'] + // Check for arrow function returning array: => ['/path'] or => ['/path', options] + expect(fileContent).toMatch(/=> \[["']\/[^"']*["']/); // Keys should contain path strings - expect(fileContent).toMatch(/'\/(api\/)?[^']*'/); + expect(fileContent).toMatch(/["']\/(?:api\/)?[^"']*["']/); } }); }); diff --git a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts index 139f956a46..9c9a660c42 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts @@ -1,3 +1,5 @@ +import ts from 'typescript'; + import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation'; import { stringCase } from '~/utils/stringCase'; @@ -13,6 +15,28 @@ import { createSwrOptions } from './swrOptions'; * It follows SWR's official recommended patterns for key design and data fetching. */ export const handlerV2: PluginHandler = ({ plugin }) => { + // Add file-level eslint-disable comment for unused vars + // This is more stable than adding inline comments which can be misplaced by formatters + const eslintDisableSymbol = plugin.registerSymbol({ + exported: false, + meta: { + category: 'utility', + resource: 'eslint-config', + }, + name: '__eslintDisable', + }); + + // Create an empty statement with the eslint-disable comment + const eslintDisableComment = ts.factory.createEmptyStatement(); + ts.addSyntheticLeadingComment( + eslintDisableComment, + ts.SyntaxKind.MultiLineCommentTrivia, + ' eslint-disable @typescript-eslint/no-unused-vars ', + true, + ); + + plugin.setSymbolValue(eslintDisableSymbol, eslintDisableComment); + // Register external symbols from axios (for error types) plugin.registerSymbol({ external: 'axios', diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts index 069c2ac4aa..ba716474a0 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts @@ -27,10 +27,8 @@ const optionsParamName = 'options'; * The getKey function signature matches SWR's requirements: * (pageIndex: number, previousPageData: ResponseType | null) => Key | null * - * The key structure uses primitive values for optimal caching: - * [path, ...pathParams, queryObject] - * - * Optional parameters use optional chaining (options?.query) for safe access. + * The key structure uses object serialization (since SWR 1.1.0): + * [path, { ...options, [paginationParam]: pageIndex }] * * Usage with useSWRInfinite: * const { getKey, fetcher } = getUsersInfinite({ query: { status: 'active' } }); @@ -44,10 +42,9 @@ const optionsParamName = 'options'; * Without path params (optional): * export const getUsersInfinite = (options?: GetUsersData) => ({ * getKey: (pageIndex: number, previousPageData: GetUsersResponse | null) => - * ['/users', { ...options?.query, page: pageIndex }], - * fetcher: async (key: readonly [string, GetUsersData['query']]) => { - * const params = { query: key[1] }; - * const { data } = await getUsers({ ...params, throwOnError: true }); + * ['/users', { ...options, query: { ...options?.query, page: pageIndex } }], + * fetcher: async (key: readonly [string, GetUsersData]) => { + * const { data } = await getUsers({ ...key[1], throwOnError: true }); * return data; * } * }); @@ -55,10 +52,9 @@ const optionsParamName = 'options'; * With path params (options required): * export const getOrgUsersInfinite = (options: GetOrgUsersData) => ({ * getKey: (pageIndex: number, previousPageData: GetOrgUsersResponse | null) => - * ['/orgs/{orgId}/users', options.path.orgId, { ...options.query, page: pageIndex }], - * fetcher: async (key: readonly [string, string, GetOrgUsersData['query']]) => { - * const params = { path: { orgId: key[1] }, query: key[2] }; - * const { data } = await getOrgUsers({ ...params, throwOnError: true }); + * ['/orgs/{orgId}/users', { ...options, query: { ...options.query, page: pageIndex } }], + * fetcher: async (key: readonly [string, GetOrgUsersData]) => { + * const { data } = await getOrgUsers({ ...key[1], throwOnError: true }); * return data; * } * }); @@ -100,52 +96,22 @@ export const createSwrInfiniteOptions = ({ const typeResponse = useTypeResponse({ operation, plugin }); // Create the getKey function - // Following SWR's useSWRInfinite pattern: + // Following SWR's useSWRInfinite pattern with object serialization: // getKey: (pageIndex: number, previousPageData: ResponseType | null) => Key | null // - // The getKey function should: - // 1. Return null to stop fetching (when previousPageData is empty/end reached) - // 2. Return key array with primitive values for each page - // 3. Match the pattern from swrKey.ts: ['/path', ...pathParams, queryObject] + // The getKey function returns: ['/path', { ...options, query: { ...query, page: pageIndex } }] + // This leverages SWR 1.1.0+ automatic object serialization const getKeyStatements: Array> = []; - // Build the key array following the same pattern as regular keys - const pathParams = operation.parameters?.path || {}; const hasQueryParams = operation.parameters?.query && Object.keys(operation.parameters.query).length > 0; - const keyElements: ts.Expression[] = [$.literal(operation.path).$render()]; + // Build the options object with pagination merged into query + let paginatedOptions: TsDsl; - // Extract each path parameter as a separate primitive value - for (const key in pathParams) { - const parameter = pathParams[key]!; - // Use optional chaining if options is optional - if (isRequiredOptions) { - keyElements.push( - $('options').attr('path').attr(parameter.name).$render(), - ); - } else { - // Create options?.path.{paramName} with optional chaining - keyElements.push( - $( - ts.factory.createPropertyAccessExpression( - ts.factory.createPropertyAccessChain( - $('options').$render(), - ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), - ts.factory.createIdentifier('path'), - ), - ts.factory.createIdentifier(parameter.name), - ), - ).$render(), - ); - } - } - - // For query parameters, merge with pagination if (hasQueryParams) { - // Create merged query object: { ...options?.query, [paginationName]: pageIndex } - // Need to use optional chaining for options.query when options is optional + // Merge pagination param into existing query params const queryAccess = isRequiredOptions ? $('options').attr('query') : $( @@ -155,17 +121,26 @@ export const createSwrInfiniteOptions = ({ ts.factory.createIdentifier('query'), ), ); + const mergedQuery = $.object() .spread(queryAccess) .prop(pagination.name, 'pageIndex'); - keyElements.push(mergedQuery.$render()); + + paginatedOptions = $.object().spread('options').prop('query', mergedQuery); } else { - // If no existing query params, just add pagination as an object - keyElements.push($.object().prop(pagination.name, 'pageIndex').$render()); + // No existing query params, create query object with just pagination + const queryObj = $.object().prop(pagination.name, 'pageIndex'); + + paginatedOptions = $.object().spread('options').prop('query', queryObj); } - // Create the array: ['/path', ...pathParams, queryWithPagination] - const keyArrayExpr = $(ts.factory.createArrayLiteralExpression(keyElements)); + // Create the key array: ['/path', paginatedOptions] + const keyArrayExpr = $( + ts.factory.createArrayLiteralExpression([ + $.literal(operation.path).$render(), + paginatedOptions.$render(), + ]), + ); // Return the key array getKeyStatements.push(keyArrayExpr.return()); @@ -175,52 +150,26 @@ export const createSwrInfiniteOptions = ({ .param('previousPageData', (p) => p.type(`${typeResponse} | null`)) .do(...getKeyStatements); + const getKeyNode = getKeyFunction.$render(); + // Create the fetcher function - // Fetcher receives the key array and reconstructs the options object + // Fetcher receives the key array: [path, options] + // Since we pass the options object directly in the key, we can extract it easily const fetcherStatements: Array> = []; - // Reconstruct the options object from the key array - // Key structure: ['/path', ...pathParams, queryObj] - // We need to build: { path: { param1: value1, ... }, query: queryObj } - const pathParamsCount = Object.keys(pathParams).length; - - // Build the reconstructed options object - let reconstructedOptions = $.object(); - - // Add path params if they exist - if (pathParamsCount > 0) { - let pathObj = $.object(); - let paramIndex = 1; // Start after the path string - for (const key in pathParams) { - const parameter = pathParams[key]!; - // Create element access: key[index] - const elementAccess = $( - ts.factory.createElementAccessExpression( - $('key').$render(), - ts.factory.createNumericLiteral(paramIndex), - ), - ); - pathObj = pathObj.prop(parameter.name, elementAccess); - paramIndex++; - } - reconstructedOptions = reconstructedOptions.prop('path', pathObj); - } - - // Add query params (last element in key array) - // Query is at index: 1 + pathParamsCount - const queryIndex = 1 + pathParamsCount; - const queryAccess = $( + // Extract options from key[1] + const optionsFromKey = $( ts.factory.createElementAccessExpression( $('key').$render(), - ts.factory.createNumericLiteral(queryIndex), + ts.factory.createNumericLiteral(1), ), ); - reconstructedOptions = reconstructedOptions.prop('query', queryAccess); - - fetcherStatements.push($.const('params').assign(reconstructedOptions)); + // Call SDK function with the options from the key const awaitSdkFn = $(sdkFn) - .call($.object().spread('params').prop('throwOnError', $.literal(true))) + .call( + $.object().spread(optionsFromKey).prop('throwOnError', $.literal(true)), + ) .await(); if (plugin.getPluginOrThrow('@hey-api/sdk').config.responseStyle === 'data') { @@ -232,25 +181,9 @@ export const createSwrInfiniteOptions = ({ ); } - // Build the fetcher key type: readonly [string, ...pathParams, queryType] - // Example: readonly [string, number, { page: number }] - const keyTypeElements = ['string']; - - // Add path param types - Object.keys(pathParams).forEach(() => { - // Use the parameter's type - for simplicity, we'll use the base type - keyTypeElements.push('string'); - }); - - // Add query type - extract query type from the options type - // If the operation has query params, use the query property type from typeData - // Otherwise, use the pagination parameter type - const queryType = hasQueryParams - ? `${typeData}['query']` - : `{ ${pagination.name}: number }`; - keyTypeElements.push(queryType); - - const keyType = `readonly [${keyTypeElements.join(', ')}]`; + // Build the fetcher key type: readonly [string, optionsType] + // Much simpler since we pass the entire options object + const keyType = `readonly [string, ${typeData}]`; const fetcherFunction = $.func() .async() @@ -260,7 +193,7 @@ export const createSwrInfiniteOptions = ({ // Build the infinite options object const swrInfiniteOptionsObj = $.object() .pretty() - .prop('getKey', getKeyFunction) + .prop('getKey', $(getKeyNode)) .prop('fetcher', fetcherFunction); // Register the infinite options symbol diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts b/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts index b217224cb4..62a4ad3ee6 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts @@ -12,20 +12,18 @@ import { useTypeData } from '../useType'; /** * Generate a SWR key statement for a given operation. * - * For SWR, keys follow the official recommended pattern with primitive values: - * - Simple cases: string key like '/api/user' - * - With params: array key like ['/api/user', userId] with primitive values + * For SWR, keys follow the official recommended pattern using array keys with objects: + * - Simple cases: ['/api/user'] (no params) + * - With params: ['/api/user', options] (object serialized automatically since SWR 1.1.0) * - Conditional fetching: controlled by the consumer, not the key function * * This generates a function that always returns a valid key array. - * Following SWR best practices: "use arrays with primitive values instead of objects" + * Since SWR 1.1.0+, objects in array keys are automatically serialized. * * Example outputs: * - No params: ['/api/users'] - * - Single path param: ['/api/users', options.path.id] - * - Multiple path params: ['/api/users', options.path.userId, options.path.orgId] - * - Path + query: ['/api/users', options.path.id, options.query] - * - Optional params: ['/api/users', options?.query] (uses optional chaining) + * - With params: ['/api/users/{id}', options] (SWR handles object serialization) + * - Optional params: ['/api/users', options] (uses optional chaining for safety) * * Note: Conditional fetching should be controlled at the usage site: * useSWR(shouldFetch ? getKey(options) : null, fetcher) @@ -42,78 +40,33 @@ export const swrKeyStatement = ({ const typeData = useTypeData({ operation, plugin }); const isRequired = hasOperationDataRequired(operation); - // Build the key based on what parameters exist - // Following SWR's pattern: use primitive values for better serialization - const pathParams = operation.parameters?.path || {}; - const hasQueryParams = - operation.parameters?.query && - Object.keys(operation.parameters.query).length > 0; + // Build the key using array with path and options object + // Since SWR 1.1.0+, objects in array keys are automatically serialized + const hasParams = + (operation.parameters?.path && + Object.keys(operation.parameters.path).length > 0) || + (operation.parameters?.query && + Object.keys(operation.parameters.query).length > 0); - // Build array elements for the key using ts-dsl - const baseKeyElements: ts.Expression[] = [ - $.literal(operation.path).$render(), - ]; - - // Extract each path parameter as a separate primitive value - // This follows SWR best practice: ['/api/users', userId] not ['/api/users', { userId }] - // Use parameter.name (the transformed TypeScript property name) not the key (original OpenAPI name) - const pathKeyElements: ts.Expression[] = []; - for (const key in pathParams) { - const parameter = pathParams[key]!; - pathKeyElements.push( - $('options').attr('path').attr(parameter.name).$render(), - ); - } - - // For query parameters, we keep them as an object since they can be complex - // and are typically used together for filtering/pagination - const queryKeyElement = hasQueryParams - ? $('options').attr('query').$render() - : null; - - // Determine the key expression based on whether parameters are required let keyExpression: ts.Expression; - const hasParams = pathKeyElements.length > 0 || hasQueryParams; - - if (isRequired || !hasParams) { - // If required OR no params at all, always return the full key array - const allElements = [...baseKeyElements, ...pathKeyElements]; - if (queryKeyElement) { - allElements.push(queryKeyElement); - } - keyExpression = ts.factory.createArrayLiteralExpression(allElements); + if (!hasParams) { + // No parameters: just return ['/path'] + keyExpression = ts.factory.createArrayLiteralExpression([ + $.literal(operation.path).$render(), + ]); + } else if (isRequired) { + // Required parameters: ['/path', options] + keyExpression = ts.factory.createArrayLiteralExpression([ + $.literal(operation.path).$render(), + $('options').$render(), + ]); } else { - // If optional and has params, use optional chaining to safely access nested properties - // Build the key array with optional chaining for safety - const allElements = [...baseKeyElements]; - - for (const key in pathParams) { - const parameter = pathParams[key]!; - allElements.push( - ts.factory.createPropertyAccessChain( - ts.factory.createPropertyAccessChain( - ts.factory.createIdentifier('options'), - ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), - ts.factory.createIdentifier('path'), - ), - undefined, - ts.factory.createIdentifier(parameter.name), - ), - ); - } - - if (hasQueryParams) { - allElements.push( - ts.factory.createPropertyAccessChain( - ts.factory.createIdentifier('options'), - ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), - ts.factory.createIdentifier('query'), - ), - ); - } - - keyExpression = ts.factory.createArrayLiteralExpression(allElements); + // Optional parameters: ['/path', options] (with optional chaining for safety) + keyExpression = ts.factory.createArrayLiteralExpression([ + $.literal(operation.path).$render(), + $('options').$render(), + ]); } const statement = $.const(symbol.placeholder) @@ -124,7 +77,7 @@ export const swrKeyStatement = ({ .do($(keyExpression).return()), ); - return statement; + return statement.$render(); }; /** diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts index 3a98ed0066..f72a681231 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts @@ -15,24 +15,24 @@ const optionsParamName = 'options'; * Create useSWRMutation options for a given operation. * * This generates a function that returns an object with: - * - key: The mutation key following SWR patterns (array with path + path params) + * - key: The mutation key following SWR patterns (array with path + options object) * - fetcher: Async function that calls the SDK function with arg parameter * - * Following SWR best practices: - * - No path params: string key like '/api/users' - * - With path params: array key like ['/api/users/{id}', userId] + * Following SWR best practices with automatic object serialization (since SWR 1.1.0): + * - No params: ['/api/users'] + * - With params: ['/api/users/{id}', options] (object serialized automatically) * - This matches the query key structure for proper cache integration * * Example outputs: * // No path parameters * export const createUserMutation = (options?: CreateUserOptions) => ({ - * key: '/api/users', + * key: ['/api/users'], * fetcher: async (_key, arg) => { ... }, * }); * * // With path parameters * export const deletePetMutation = (options?: DeletePetOptions) => ({ - * key: options?.path ? ['/pet/{petId}', options.path.petId] : '/pet/{petId}', + * key: ['/pet/{petId}', options], * fetcher: async (_key, arg) => { ... }, * }); */ @@ -68,28 +68,20 @@ export const createSwrMutationOptions = ({ ); } - // Build mutation key following SWR patterns - // - If path params exist: use array [path, ...pathParams] - // - If no path params: use simple string key - const pathParams = operation.parameters?.path || {}; - const hasPathParams = Object.keys(pathParams).length > 0; + // Build mutation key following SWR patterns with object serialization + // Since SWR 1.1.0+, we can pass options object directly in the array key + const hasParams = + (operation.parameters?.path && + Object.keys(operation.parameters.path).length > 0) || + (operation.parameters?.query && + Object.keys(operation.parameters.query).length > 0); let mutationKey: TsDsl; let keyType: string; - if (hasPathParams) { - // Build array key: [path, param1, param2, ...] - const keyElements: ts.Expression[] = [$.literal(operation.path).$render()]; - - // Add each path parameter as a separate primitive value - for (const key in pathParams) { - const parameter = pathParams[key]!; - keyElements.push( - $('options').attr('path').attr(parameter.name).$render(), - ); - } - - // Wrap in conditional: options?.path ? [...] : path + if (hasParams) { + // With parameters: conditional key based on whether options is provided + // options?.path ? [path, options] : [path] mutationKey = $( ts.factory.createConditionalExpression( ts.factory.createPropertyAccessChain( @@ -98,17 +90,25 @@ export const createSwrMutationOptions = ({ 'path', ), ts.factory.createToken(ts.SyntaxKind.QuestionToken), - ts.factory.createArrayLiteralExpression(keyElements), + ts.factory.createArrayLiteralExpression([ + $.literal(operation.path).$render(), + $('options').$render(), + ]), ts.factory.createToken(ts.SyntaxKind.ColonToken), - $.literal(operation.path).$render(), + ts.factory.createArrayLiteralExpression([ + $.literal(operation.path).$render(), + ]), ), ); - // Key type is either array or string depending on whether path params are provided - keyType = 'string | readonly [string, ...Array]'; + keyType = `readonly [string] | readonly [string, ${typeData}]`; } else { - // Simple string key for operations without path params - mutationKey = $.literal(operation.path); - keyType = 'string'; + // No parameters: simple array key [path] + mutationKey = $( + ts.factory.createArrayLiteralExpression([ + $.literal(operation.path).$render(), + ]), + ); + keyType = 'readonly [string]'; } // Build the options object @@ -121,11 +121,9 @@ export const createSwrMutationOptions = ({ .async() .param('_key', (p) => p.type(keyType)) .param((p) => - p.object('arg').type( - $.type.object((t) => { - t.prop('arg', (p) => p.type(typeData)); - }), - ), + p + .object('arg') + .type($.type.object().prop('arg', (p) => p.type(typeData))), ) .do(...statements), ); From 63118215f45bd6179ecc754bbee04704b333d462 Mon Sep 17 00:00:00 2001 From: Pewww Date: Thu, 13 Nov 2025 14:36:53 +0900 Subject: [PATCH 6/9] fix: sync test and snapshots --- .../src/client/client/client.gen.ts | 35 +-------- .../src/client/client/client.gen.ts | 35 +-------- .../src/client/client/client.gen.ts | 35 +-------- .../src/client/client/client.gen.ts | 30 +------- .../angular-query-experimental.gen.ts | 63 +++------------- .../src/client/@tanstack/react-query.gen.ts | 63 +++------------- .../src/client/client/client.gen.ts | 35 +-------- .../src/client/@tanstack/svelte-query.gen.ts | 63 +++------------- .../src/client/client/client.gen.ts | 35 +-------- .../src/client/@tanstack/vue-query.gen.ts | 58 +++------------ .../src/client/client/client.gen.ts | 30 +------- .../client/client.gen.ts | 35 +-------- .../2.0.x/form-data/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../sdk-nested-classes/client/client.gen.ts | 35 +-------- .../@hey-api/sdk/default/client/client.gen.ts | 35 +-------- .../sdk/instance/client/client.gen.ts | 35 +-------- .../sdk/throwOnError/client/client.gen.ts | 35 +-------- .../type-format-valibot/client/client.gen.ts | 35 +-------- .../type-format-zod/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../colada/asClass/client/client.gen.ts | 35 +-------- .../@pinia/colada/fetch/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 10 +-- .../asClass/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 50 ++++++------- .../angular-query-experimental.gen.ts | 50 ++++++------- .../fetch/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/react-query.gen.ts | 10 +-- .../react-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/react-query.gen.ts | 50 ++++++------- .../fetch/@tanstack/react-query.gen.ts | 50 ++++++------- .../react-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/react-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/solid-query.gen.ts | 10 +-- .../solid-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/solid-query.gen.ts | 50 ++++++------- .../fetch/@tanstack/solid-query.gen.ts | 50 ++++++------- .../solid-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/solid-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/svelte-query.gen.ts | 10 +-- .../svelte-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/svelte-query.gen.ts | 50 ++++++------- .../fetch/@tanstack/svelte-query.gen.ts | 50 ++++++------- .../svelte-query/fetch/client/client.gen.ts | 35 +-------- .../@tanstack/svelte-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/vue-query.gen.ts | 10 +-- .../vue-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/vue-query.gen.ts | 50 ++++++------- .../fetch/@tanstack/vue-query.gen.ts | 50 ++++++------- .../vue-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/vue-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../2.0.x/schema-unknown/client/client.gen.ts | 35 +-------- .../security-api-key/client/client.gen.ts | 35 +-------- .../2.0.x/security-basic/client/client.gen.ts | 35 +-------- .../2.0.x/security-false/client/client.gen.ts | 35 +-------- .../security-oauth2/client/client.gen.ts | 35 +-------- .../servers-base-path/client/client.gen.ts | 35 +-------- .../2.0.x/servers-host/client/client.gen.ts | 35 +-------- .../2.0.x/servers/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../@tanstack/react-query.gen.ts | 4 +- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../sdk-nested-classes/client/client.gen.ts | 35 +-------- .../@hey-api/sdk/default/client/client.gen.ts | 35 +-------- .../sdk/instance/client/client.gen.ts | 35 +-------- .../sdk/throwOnError/client/client.gen.ts | 35 +-------- .../type-format-valibot/client/client.gen.ts | 35 +-------- .../type-format-zod/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../colada/asClass/client/client.gen.ts | 35 +-------- .../@pinia/colada/fetch/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 10 +-- .../asClass/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 72 +++++++++---------- .../angular-query-experimental.gen.ts | 72 +++++++++---------- .../fetch/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/react-query.gen.ts | 10 +-- .../react-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/react-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/react-query.gen.ts | 72 +++++++++---------- .../react-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/react-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/solid-query.gen.ts | 10 +-- .../solid-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/solid-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/solid-query.gen.ts | 72 +++++++++---------- .../solid-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/solid-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/svelte-query.gen.ts | 10 +-- .../svelte-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/svelte-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/svelte-query.gen.ts | 72 +++++++++---------- .../svelte-query/fetch/client/client.gen.ts | 35 +-------- .../@tanstack/svelte-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/vue-query.gen.ts | 10 +-- .../vue-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/vue-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/vue-query.gen.ts | 72 +++++++++---------- .../vue-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/vue-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../plugins/valibot/default/valibot.gen.ts | 4 +- .../security-api-key/client/client.gen.ts | 35 +-------- .../3.0.x/security-false/client/client.gen.ts | 35 +-------- .../security-http-bearer/client/client.gen.ts | 35 +-------- .../security-oauth2/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../3.0.x/servers/client/client.gen.ts | 35 +-------- .../transformers-all-of/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../transformers-array/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../base-url-false/client/client.gen.ts | 35 +-------- .../base-url-number/client/client.gen.ts | 35 +-------- .../base-url-strict/client/client.gen.ts | 35 +-------- .../base-url-string/client/client.gen.ts | 35 +-------- .../clean-false/client/client.gen.ts | 35 +-------- .../client-fetch/default/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../sdk-client-optional/client/client.gen.ts | 35 +-------- .../sdk-client-required/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../3.1.x/headers/client/client.gen.ts | 35 +-------- .../@tanstack/react-query.gen.ts | 4 +- .../client/client.gen.ts | 35 +-------- .../@tanstack/react-query.gen.ts | 6 +- .../3.1.x/pagination-ref/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../sdk-nested-classes/client/client.gen.ts | 35 +-------- .../@hey-api/sdk/default/client/client.gen.ts | 35 +-------- .../sdk/instance/client/client.gen.ts | 35 +-------- .../sdk/throwOnError/client/client.gen.ts | 35 +-------- .../type-format-valibot/client/client.gen.ts | 35 +-------- .../type-format-zod/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../colada/asClass/client/client.gen.ts | 35 +-------- .../@pinia/colada/fetch/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 10 +-- .../asClass/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 72 +++++++++---------- .../angular-query-experimental.gen.ts | 72 +++++++++---------- .../fetch/client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/react-query.gen.ts | 10 +-- .../react-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/react-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/react-query.gen.ts | 72 +++++++++---------- .../react-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/react-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/solid-query.gen.ts | 10 +-- .../solid-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/solid-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/solid-query.gen.ts | 72 +++++++++---------- .../solid-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/solid-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/svelte-query.gen.ts | 10 +-- .../svelte-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/svelte-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/svelte-query.gen.ts | 72 +++++++++---------- .../svelte-query/fetch/client/client.gen.ts | 35 +-------- .../@tanstack/svelte-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../asClass/@tanstack/vue-query.gen.ts | 10 +-- .../vue-query/asClass/client/client.gen.ts | 35 +-------- .../axios/@tanstack/vue-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/vue-query.gen.ts | 72 +++++++++---------- .../vue-query/fetch/client/client.gen.ts | 35 +-------- .../name-builder/@tanstack/vue-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 +-------- .../plugins/valibot/default/valibot.gen.ts | 16 ++--- .../3.1.x/schema-const/valibot.gen.ts | 2 +- .../security-api-key/client/client.gen.ts | 35 +-------- .../3.1.x/security-false/client/client.gen.ts | 35 +-------- .../security-http-bearer/client/client.gen.ts | 35 +-------- .../security-oauth2/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../3.1.x/servers/client/client.gen.ts | 35 +-------- .../3.1.x/sse-fetch/client/client.gen.ts | 35 +-------- .../transformers-all-of/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../transformers-array/client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../client/client.gen.ts | 35 +-------- .../angular-query-experimental.gen.ts | 10 +-- .../meta/@tanstack/react-query.gen.ts | 10 +-- .../meta/@tanstack/solid-query.gen.ts | 10 +-- .../meta/@tanstack/svelte-query.gen.ts | 10 +-- .../@tanstack/meta/@tanstack/vue-query.gen.ts | 10 +-- .../@tanstack/meta/client/client.gen.ts | 35 +-------- .../class/client/client.gen.ts | 35 +-------- .../flat/client/client.gen.ts | 35 +-------- .../instance/client/client.gen.ts | 35 +-------- .../opencode/flat/client/client.gen.ts | 35 +-------- .../opencode/grouped/client/client.gen.ts | 35 +-------- .../2.0.x/mini/default/zod.gen.ts | 4 +- .../__snapshots__/2.0.x/v3/default/zod.gen.ts | 4 +- .../__snapshots__/2.0.x/v4/default/zod.gen.ts | 4 +- .../3.0.x/mini/circular/zod.gen.ts | 26 +++++-- .../3.0.x/mini/default/zod.gen.ts | 8 ++- .../3.0.x/mini/validators/zod.gen.ts | 8 ++- .../3.0.x/v3/circular/zod.gen.ts | 24 +++++-- .../__snapshots__/3.0.x/v3/default/zod.gen.ts | 8 ++- .../3.0.x/v3/validators/zod.gen.ts | 8 ++- .../3.0.x/v4/circular/zod.gen.ts | 26 +++++-- .../__snapshots__/3.0.x/v4/default/zod.gen.ts | 8 ++- .../3.0.x/v4/validators/zod.gen.ts | 8 ++- .../3.1.x/mini/default/zod.gen.ts | 20 +++--- .../3.1.x/mini/schema-const/zod.gen.ts | 6 +- .../mini/validators-circular-ref-2/zod.gen.ts | 4 +- .../mini/validators-circular-ref/zod.gen.ts | 8 ++- .../3.1.x/mini/validators-dates/zod.gen.ts | 12 +++- .../3.1.x/mini/validators-metadata/zod.gen.ts | 20 +++--- .../3.1.x/mini/validators-types/zod.gen.ts | 8 ++- .../3.1.x/mini/validators/zod.gen.ts | 8 ++- .../__snapshots__/3.1.x/v3/default/zod.gen.ts | 20 +++--- .../3.1.x/v3/schema-const/zod.gen.ts | 6 +- .../v3/validators-circular-ref-2/zod.gen.ts | 4 +- .../v3/validators-circular-ref/zod.gen.ts | 8 ++- .../3.1.x/v3/validators-dates/zod.gen.ts | 12 +++- .../3.1.x/v3/validators-metadata/zod.gen.ts | 18 +++-- .../3.1.x/v3/validators-types/zod.gen.ts | 8 ++- .../3.1.x/v3/validators/zod.gen.ts | 8 ++- .../__snapshots__/3.1.x/v4/default/zod.gen.ts | 20 +++--- .../3.1.x/v4/schema-const/zod.gen.ts | 6 +- .../v4/validators-circular-ref-2/zod.gen.ts | 4 +- .../v4/validators-circular-ref/zod.gen.ts | 8 ++- .../3.1.x/v4/validators-dates/zod.gen.ts | 12 +++- .../3.1.x/v4/validators-metadata/zod.gen.ts | 20 +++--- .../3.1.x/v4/validators-types/zod.gen.ts | 8 ++- .../3.1.x/v4/validators/zod.gen.ts | 8 ++- .../2.0.x/mini/default/zod.gen.ts | 4 +- .../__snapshots__/2.0.x/v3/default/zod.gen.ts | 4 +- .../__snapshots__/2.0.x/v4/default/zod.gen.ts | 4 +- .../3.0.x/mini/circular/zod.gen.ts | 26 +++++-- .../3.0.x/mini/default/zod.gen.ts | 8 ++- .../3.0.x/mini/validators/zod.gen.ts | 8 ++- .../3.0.x/v3/circular/zod.gen.ts | 24 +++++-- .../__snapshots__/3.0.x/v3/default/zod.gen.ts | 8 ++- .../3.0.x/v3/validators/zod.gen.ts | 8 ++- .../3.0.x/v4/circular/zod.gen.ts | 26 +++++-- .../__snapshots__/3.0.x/v4/default/zod.gen.ts | 8 ++- .../3.0.x/v4/validators/zod.gen.ts | 8 ++- .../3.1.x/mini/default/zod.gen.ts | 20 +++--- .../3.1.x/mini/schema-const/zod.gen.ts | 6 +- .../mini/validators-circular-ref-2/zod.gen.ts | 4 +- .../mini/validators-circular-ref/zod.gen.ts | 8 ++- .../3.1.x/mini/validators-dates/zod.gen.ts | 12 +++- .../3.1.x/mini/validators-metadata/zod.gen.ts | 20 +++--- .../3.1.x/mini/validators-types/zod.gen.ts | 8 ++- .../3.1.x/mini/validators/zod.gen.ts | 8 ++- .../__snapshots__/3.1.x/v3/default/zod.gen.ts | 20 +++--- .../3.1.x/v3/schema-const/zod.gen.ts | 6 +- .../v3/validators-circular-ref-2/zod.gen.ts | 4 +- .../v3/validators-circular-ref/zod.gen.ts | 8 ++- .../3.1.x/v3/validators-dates/zod.gen.ts | 12 +++- .../3.1.x/v3/validators-metadata/zod.gen.ts | 18 +++-- .../3.1.x/v3/validators-types/zod.gen.ts | 8 ++- .../3.1.x/v3/validators/zod.gen.ts | 8 ++- .../__snapshots__/3.1.x/v4/default/zod.gen.ts | 20 +++--- .../3.1.x/v4/schema-const/zod.gen.ts | 6 +- .../v4/validators-circular-ref-2/zod.gen.ts | 4 +- .../v4/validators-circular-ref/zod.gen.ts | 8 ++- .../3.1.x/v4/validators-dates/zod.gen.ts | 12 +++- .../3.1.x/v4/validators-metadata/zod.gen.ts | 20 +++--- .../3.1.x/v4/validators-types/zod.gen.ts | 8 ++- .../3.1.x/v4/validators/zod.gen.ts | 8 ++- 290 files changed, 1866 insertions(+), 6486 deletions(-) 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 c2a5190c22..a439d2748f 100644 --- a/examples/openapi-ts-fastify/src/client/client/client.gen.ts +++ b/examples/openapi-ts-fastify/src/client/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 100644 --- a/examples/openapi-ts-fetch/src/client/client/client.gen.ts +++ b/examples/openapi-ts-fetch/src/client/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 100644 --- a/examples/openapi-ts-openai/src/client/client/client.gen.ts +++ b/examples/openapi-ts-openai/src/client/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 00dbae3997..4a4fc4648f 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 @@ -85,35 +85,7 @@ export const createClient = (config: Config = {}): Client => { // 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 - } - } + let response = await _fetch(request) for (const fn of interceptors.response.fns) { if (fn) { diff --git a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/@tanstack/angular-query-experimental.gen.ts b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/@tanstack/angular-query-experimental.gen.ts index 649e687fe0..4952a1ddf8 100644 --- a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/@tanstack/angular-query-experimental.gen.ts +++ b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/@tanstack/angular-query-experimental.gen.ts @@ -40,19 +40,12 @@ import type { DeletePetData, DeleteUserData, FindPetsByStatusData, - FindPetsByStatusResponse, FindPetsByTagsData, - FindPetsByTagsResponse, GetInventoryData, - GetInventoryResponse, GetOrderByIdData, - GetOrderByIdResponse, GetPetByIdData, - GetPetByIdResponse, GetUserByNameData, - GetUserByNameResponse, LoginUserData, - LoginUserResponse, LogoutUserData, PlaceOrderData, PlaceOrderResponse, @@ -167,12 +160,7 @@ export const findPetsByStatusQueryKey = ( export const findPetsByStatusOptions = ( options: Options, ) => - queryOptions< - FindPetsByStatusResponse, - DefaultError, - FindPetsByStatusResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByStatus({ ...options, @@ -194,12 +182,7 @@ export const findPetsByTagsQueryKey = (options: Options) => * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTagsOptions = (options: Options) => - queryOptions< - FindPetsByTagsResponse, - DefaultError, - FindPetsByTagsResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByTags({ ...options, @@ -246,12 +229,7 @@ export const getPetByIdQueryKey = (options: Options) => * Returns a single pet. */ export const getPetByIdOptions = (options: Options) => - queryOptions< - GetPetByIdResponse, - DefaultError, - GetPetByIdResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getPetById({ ...options, @@ -331,12 +309,7 @@ export const getInventoryQueryKey = (options?: Options) => * Returns a map of status codes to quantities. */ export const getInventoryOptions = (options?: Options) => - queryOptions< - GetInventoryResponse, - DefaultError, - GetInventoryResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getInventory({ ...options, @@ -412,12 +385,7 @@ export const getOrderByIdQueryKey = (options: Options) => * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderByIdOptions = (options: Options) => - queryOptions< - GetOrderByIdResponse, - DefaultError, - GetOrderByIdResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getOrderById({ ...options, @@ -497,12 +465,7 @@ export const loginUserQueryKey = (options?: Options) => * Log into the system. */ export const loginUserOptions = (options?: Options) => - queryOptions< - LoginUserResponse, - DefaultError, - LoginUserResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await loginUser({ ...options, @@ -524,12 +487,7 @@ export const logoutUserQueryKey = (options?: Options) => * Log user out of the system. */ export const logoutUserOptions = (options?: Options) => - queryOptions< - unknown, - DefaultError, - unknown, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await logoutUser({ ...options, @@ -576,12 +534,7 @@ export const getUserByNameQueryKey = (options: Options) => * Get user detail based on username. */ export const getUserByNameOptions = (options: Options) => - queryOptions< - GetUserByNameResponse, - DefaultError, - GetUserByNameResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserByName({ ...options, diff --git a/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts b/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts index 5a87162c2c..d0b4d2452c 100644 --- a/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts +++ b/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts @@ -19,19 +19,12 @@ import type { DeletePetData, DeleteUserData, FindPetsByStatusData, - FindPetsByStatusResponse, FindPetsByTagsData, - FindPetsByTagsResponse, GetInventoryData, - GetInventoryResponse, GetOrderByIdData, - GetOrderByIdResponse, GetPetByIdData, - GetPetByIdResponse, GetUserByNameData, - GetUserByNameResponse, LoginUserData, - LoginUserResponse, LogoutUserData, PlaceOrderData, PlaceOrderResponse, @@ -150,12 +143,7 @@ export const findPetsByStatusQueryKey = ( export const findPetsByStatusOptions = ( options: Options, ) => - queryOptions< - FindPetsByStatusResponse, - DefaultError, - FindPetsByStatusResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().findPetsByStatus({ ...options, @@ -177,12 +165,7 @@ export const findPetsByTagsQueryKey = (options: Options) => * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTagsOptions = (options: Options) => - queryOptions< - FindPetsByTagsResponse, - DefaultError, - FindPetsByTagsResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().findPetsByTags({ ...options, @@ -229,12 +212,7 @@ export const getPetByIdQueryKey = (options: Options) => * Returns a single pet. */ export const getPetByIdOptions = (options: Options) => - queryOptions< - GetPetByIdResponse, - DefaultError, - GetPetByIdResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().getPetById({ ...options, @@ -314,12 +292,7 @@ export const getInventoryQueryKey = (options?: Options) => * Returns a map of status codes to quantities. */ export const getInventoryOptions = (options?: Options) => - queryOptions< - GetInventoryResponse, - DefaultError, - GetInventoryResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().getInventory({ ...options, @@ -395,12 +368,7 @@ export const getOrderByIdQueryKey = (options: Options) => * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderByIdOptions = (options: Options) => - queryOptions< - GetOrderByIdResponse, - DefaultError, - GetOrderByIdResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().getOrderById({ ...options, @@ -480,12 +448,7 @@ export const loginUserQueryKey = (options?: Options) => * Log into the system. */ export const loginUserOptions = (options?: Options) => - queryOptions< - LoginUserResponse, - DefaultError, - LoginUserResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().loginUser({ ...options, @@ -507,12 +470,7 @@ export const logoutUserQueryKey = (options?: Options) => * Log user out of the system. */ export const logoutUserOptions = (options?: Options) => - queryOptions< - unknown, - DefaultError, - unknown, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().logoutUser({ ...options, @@ -559,12 +517,7 @@ export const getUserByNameQueryKey = (options: Options) => * Get user detail based on username. */ export const getUserByNameOptions = (options: Options) => - queryOptions< - GetUserByNameResponse, - DefaultError, - GetUserByNameResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().getUserByName({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts b/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts index 212844409e..e9fe1844e5 100644 --- a/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts +++ b/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts @@ -40,19 +40,12 @@ import type { DeletePetData, DeleteUserData, FindPetsByStatusData, - FindPetsByStatusResponse, FindPetsByTagsData, - FindPetsByTagsResponse, GetInventoryData, - GetInventoryResponse, GetOrderByIdData, - GetOrderByIdResponse, GetPetByIdData, - GetPetByIdResponse, GetUserByNameData, - GetUserByNameResponse, LoginUserData, - LoginUserResponse, LogoutUserData, PlaceOrderData, PlaceOrderResponse, @@ -167,12 +160,7 @@ export const findPetsByStatusQueryKey = ( export const findPetsByStatusOptions = ( options: Options, ) => - queryOptions< - FindPetsByStatusResponse, - DefaultError, - FindPetsByStatusResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByStatus({ ...options, @@ -194,12 +182,7 @@ export const findPetsByTagsQueryKey = (options: Options) => * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTagsOptions = (options: Options) => - queryOptions< - FindPetsByTagsResponse, - DefaultError, - FindPetsByTagsResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByTags({ ...options, @@ -246,12 +229,7 @@ export const getPetByIdQueryKey = (options: Options) => * Returns a single pet. */ export const getPetByIdOptions = (options: Options) => - queryOptions< - GetPetByIdResponse, - DefaultError, - GetPetByIdResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getPetById({ ...options, @@ -331,12 +309,7 @@ export const getInventoryQueryKey = (options?: Options) => * Returns a map of status codes to quantities. */ export const getInventoryOptions = (options?: Options) => - queryOptions< - GetInventoryResponse, - DefaultError, - GetInventoryResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getInventory({ ...options, @@ -412,12 +385,7 @@ export const getOrderByIdQueryKey = (options: Options) => * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderByIdOptions = (options: Options) => - queryOptions< - GetOrderByIdResponse, - DefaultError, - GetOrderByIdResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getOrderById({ ...options, @@ -497,12 +465,7 @@ export const loginUserQueryKey = (options?: Options) => * Log into the system. */ export const loginUserOptions = (options?: Options) => - queryOptions< - LoginUserResponse, - DefaultError, - LoginUserResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await loginUser({ ...options, @@ -524,12 +487,7 @@ export const logoutUserQueryKey = (options?: Options) => * Log user out of the system. */ export const logoutUserOptions = (options?: Options) => - queryOptions< - unknown, - DefaultError, - unknown, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await logoutUser({ ...options, @@ -576,12 +534,7 @@ export const getUserByNameQueryKey = (options: Options) => * Get user detail based on username. */ export const getUserByNameOptions = (options: Options) => - queryOptions< - GetUserByNameResponse, - DefaultError, - GetUserByNameResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserByName({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts b/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts index d3fcf6469b..9050f1d24e 100644 --- a/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts +++ b/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts @@ -36,19 +36,12 @@ import type { DeletePetData, DeleteUserData, FindPetsByStatusData, - FindPetsByStatusResponse, FindPetsByTagsData, - FindPetsByTagsResponse, GetInventoryData, - GetInventoryResponse, GetOrderByIdData, - GetOrderByIdResponse, GetPetByIdData, - GetPetByIdResponse, GetUserByNameData, - GetUserByNameResponse, LoginUserData, - LoginUserResponse, LogoutUserData, PlaceOrderData, PlaceOrderResponse, @@ -155,12 +148,7 @@ export const findPetsByStatusQueryKey = (options: Options) * Multiple status values can be provided with comma separated strings. */ export const findPetsByStatusOptions = (options: Options) => - queryOptions< - FindPetsByStatusResponse, - DefaultError, - FindPetsByStatusResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByStatus({ ...options, @@ -182,12 +170,7 @@ export const findPetsByTagsQueryKey = (options: Options) => * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTagsOptions = (options: Options) => - queryOptions< - FindPetsByTagsResponse, - DefaultError, - FindPetsByTagsResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByTags({ ...options, @@ -230,12 +213,7 @@ export const getPetByIdQueryKey = (options: Options) => * Returns a single pet. */ export const getPetByIdOptions = (options: Options) => - queryOptions< - GetPetByIdResponse, - DefaultError, - GetPetByIdResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getPetById({ ...options, @@ -307,12 +285,7 @@ export const getInventoryQueryKey = (options?: Options) => * Returns a map of status codes to quantities. */ export const getInventoryOptions = (options?: Options) => - queryOptions< - GetInventoryResponse, - DefaultError, - GetInventoryResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getInventory({ ...options, @@ -380,12 +353,7 @@ export const getOrderByIdQueryKey = (options: Options) => * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderByIdOptions = (options: Options) => - queryOptions< - GetOrderByIdResponse, - DefaultError, - GetOrderByIdResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getOrderById({ ...options, @@ -461,12 +429,7 @@ export const loginUserQueryKey = (options?: Options) => * Log into the system. */ export const loginUserOptions = (options?: Options) => - queryOptions< - LoginUserResponse, - DefaultError, - LoginUserResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await loginUser({ ...options, @@ -488,7 +451,7 @@ export const logoutUserQueryKey = (options?: Options) => * Log user out of the system. */ export const logoutUserOptions = (options?: Options) => - queryOptions>({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await logoutUser({ ...options, @@ -531,12 +494,7 @@ export const getUserByNameQueryKey = (options: Options) => * Get user detail based on username. */ export const getUserByNameOptions = (options: Options) => - queryOptions< - GetUserByNameResponse, - DefaultError, - GetUserByNameResponse, - ReturnType - >({ + queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserByName({ ...options, 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 00dbae3997..4a4fc4648f 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 @@ -85,35 +85,7 @@ export const createClient = (config: Config = {}): Client => { // 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 - } - } + let response = await _fetch(request) for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts index c2a5190c22..a439d2748f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts index c2a5190c22..a439d2748f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts index 989426b607..a491c1e2b9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts index c35157d7b4..9b800726df 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts index b9dd742469..3d165eaeb4 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts index 72609d6756..2fdb9367d3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts index feeb508864..8cd7a3e782 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts index a7bbd46cc9..68d5f06972 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts index 49fec971b1..ce3cedd56b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts index a2dc5d5d6b..281ee050f2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts index 7b5bf27b84..c814b6d71f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts index 54b8e3aaa0..e0b08cf3ea 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts index b1c4100d14..83cb27ffeb 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts index f84e2391b7..3be3759576 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts index 4d282459c3..c9714c3f59 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts index 76da712c3e..f44ae821e4 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts index 2fb721a74a..539e65d77d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts index 9a52baa3d2..37ba67e52c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts index c9065f58eb..f8de70fdfd 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts index 4fb5f51271..5dd9b0efa8 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts index f75a32be96..5bd7ed1f8d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst 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'; +import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts index ffb75dcd0f..55533a5d74 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/@tanstack/react-query.gen.ts index 8d60023d0d..2a8f02e3fe 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/@tanstack/react-query.gen.ts @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const createQueryKey2 = (options?: Options) => createQueryKey("create", options); +export const createQueryKey2 = (options?: Options) => createQueryKey('create', options); -export const createOptions = (options?: Options) => queryOptions>({ +export const createOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await create({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts index c2a5190c22..a439d2748f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts index c2a5190c22..a439d2748f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts index 989426b607..a491c1e2b9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts index 5e935efafd..40a544da1b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts index 0eba11ced5..eddef04aa6 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts index 72609d6756..2fdb9367d3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts index feeb508864..8cd7a3e782 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts index efad5fa02d..79793a5bf9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts index a555bfe657..974c626917 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOption 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts index a2dc5d5d6b..281ee050f2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts index 7b5bf27b84..c814b6d71f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts index f123d6ac4a..e6d59df49b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts index 03778b370a..14c599f6e3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts index f84e2391b7..3be3759576 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts index 4d282459c3..c9714c3f59 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts index 77ceb41bc6..a583b98113 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts index 007d99d464..b5257d4cd9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts index 9a52baa3d2..37ba67e52c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts index c9065f58eb..f8de70fdfd 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts index bf4850bf3c..f14b579913 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts index 673c3b95fe..22e536b74d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOption 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts index ffb75dcd0f..55533a5d74 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts index cd348f8548..218d9f214a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts @@ -412,13 +412,13 @@ export const vModelSquare = v.object({ export const vCompositionWithOneOfDiscriminator = v.union([ v.intersect([ v.object({ - kind: v.literal("circle") + kind: v.literal('circle') }), vModelCircle ]), v.intersect([ v.object({ - kind: v.literal("square") + kind: v.literal('square') }), vModelSquare ]) 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 8715da997d..62806c6c47 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 0e4f3174bd..67961302b0 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/@tanstack/react-query.gen.ts index 8d60023d0d..2a8f02e3fe 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/@tanstack/react-query.gen.ts @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const createQueryKey2 = (options?: Options) => createQueryKey("create", options); +export const createQueryKey2 = (options?: Options) => createQueryKey('create', options); -export const createOptions = (options?: Options) => queryOptions>({ +export const createOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await create({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts index 32b258b88c..c86d61d3c6 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options: Options) => queryOptions>({ +export const getFooOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -87,7 +87,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getFooInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getFoo", options, true); +export const getFooInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getFoo', options, true); export const getFooInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | null | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts index c2a5190c22..a439d2748f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts index c2a5190c22..a439d2748f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts index 989426b607..a491c1e2b9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts index 5e935efafd..40a544da1b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts index 0eba11ced5..eddef04aa6 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts index 72609d6756..2fdb9367d3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts index feeb508864..8cd7a3e782 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts index efad5fa02d..79793a5bf9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts index a555bfe657..974c626917 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOption 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts index a2dc5d5d6b..281ee050f2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts index 7b5bf27b84..c814b6d71f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts index f123d6ac4a..e6d59df49b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts index 03778b370a..14c599f6e3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts index f84e2391b7..3be3759576 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts index 4d282459c3..c9714c3f59 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts index 77ceb41bc6..a583b98113 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts index 007d99d464..b5257d4cd9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts index 9a52baa3d2..37ba67e52c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts index c9065f58eb..f8de70fdfd 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarOptions = (options?: Options) => queryOptions>({ +export const getFooBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts index bf4850bf3c..f14b579913 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts index 673c3b95fe..22e536b74d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOption 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'; +import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey("export", options); +export const exportQueryKey = (options?: Options) => createQueryKey('export', options); -export const exportOptions = (options?: Options) => queryOptions>({ +export const exportOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey("getCallWithOptionalParam", options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey("callWithDefaultParameters", options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey('callWithDefaultParameters', options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey("duplicateName2", options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey('duplicateName2', options); -export const duplicateName2Options = (options?: Options) => queryOptions>({ +export const duplicateName2Options = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey("callWithNoContentResponse", options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithNoContentResponse', options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey("dummyA", options); +export const dummyAQueryKey = (options?: Options) => createQueryKey('dummyA', options); -export const dummyAOptions = (options?: Options) => queryOptions>({ +export const dummyAOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions) => createQueryKey("dummyB", options); +export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); -export const dummyBOptions = (options?: Options) => queryOptions>({ +export const dummyBOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions) => createQueryKey("callWithResponse", options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); -export const callWithResponseOptions = (options?: Options) => queryOptions>({ +export const callWithResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey("collectionFormat", options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey('collectionFormat', options); -export const collectionFormatOptions = (options: Options) => queryOptions>({ +export const collectionFormatOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey("types", options); +export const typesQueryKey = (options: Options) => createQueryKey('types', options); -export const typesOptions = (options: Options) => queryOptions>({ +export const typesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); +export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); -export const fileResponseOptions = (options: Options) => queryOptions>({ +export const fileResponseOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); +export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); -export const complexTypesOptions = (options: Options) => queryOptions>({ +export const complexTypesOptions = (options: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); -export const multipartResponseOptions = (options?: Options) => queryOptions>({ +export const multipartResponseOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts index ffb75dcd0f..55533a5d74 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey("getFoo", options); +export const getFooD = (options?: Options) => createQueryKey('getFoo', options); -export const getFooE = (options?: Options) => queryOptions>({ +export const getFooE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); +export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); -export const getFooBarE = (options?: Options) => queryOptions>({ +export const getFooBarE = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts index 03aef51409..f754741b42 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts @@ -415,13 +415,13 @@ export const vModelSquare = v.object({ export const vCompositionWithOneOfDiscriminator = v.union([ v.intersect([ v.object({ - kind: v.literal("circle") + kind: v.literal('circle') }), vModelCircle ]), v.intersect([ v.object({ - kind: v.literal("square") + kind: v.literal('square') }), vModelSquare ]) @@ -467,7 +467,7 @@ export const v3eNum1Период = v.picklist([ 'Dog' ]); -export const vConstValue = v.literal("ConstValue"); +export const vConstValue = v.literal('ConstValue'); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -721,10 +721,10 @@ export const vFreeFormObjectWithAdditionalPropertiesEqTrue = v.record(v.string() export const vFreeFormObjectWithAdditionalPropertiesEqEmptyObject = v.record(v.string(), v.unknown()); export const vModelWithConst = v.object({ - String: v.optional(v.literal("String")), + String: v.optional(v.literal('String')), number: v.optional(v.literal(0)), null: v.optional(v.null()), - withType: v.optional(v.literal("Some string")) + withType: v.optional(v.literal('Some string')) }); /** @@ -1660,9 +1660,9 @@ export const vTypesData = v.object({ v.null() ]), parameterEnum: v.union([ - v.literal("Success"), - v.literal("Warning"), - v.literal("Error"), + v.literal('Success'), + v.literal('Warning'), + v.literal('Error'), v.null() ]) }) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/valibot.gen.ts index 0bf447745a..9be77d3e92 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/valibot.gen.ts @@ -3,7 +3,7 @@ import * as v from 'valibot'; export const vFoo = v.object({ - foo: v.optional(v.literal("foo")), + foo: v.optional(v.literal('foo')), bar: v.optional(v.literal(3.2)), baz: v.optional(v.literal(-1)), qux: v.optional(v.literal(true)), 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts index cba06ee5b9..6a2d4fbcd1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { type DefaultError, queryOptions } from '@tanstack/angular-query-experimental'; +import { queryOptions } from '@tanstack/angular-query-experimental'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions) => createQueryKey("getBar", options); +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); -export const getBarOptions = (options?: Options) => queryOptions>({ +export const getBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts index 50907f7581..2e33891bbd 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { type DefaultError, queryOptions } from '@tanstack/react-query'; +import { queryOptions } from '@tanstack/react-query'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions) => createQueryKey("getBar", options); +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); -export const getBarOptions = (options?: Options) => queryOptions>({ +export const getBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts index 46578d9342..1381ba00d4 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { type DefaultError, queryOptions } from '@tanstack/solid-query'; +import { queryOptions } from '@tanstack/solid-query'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions) => createQueryKey("getBar", options); +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); -export const getBarOptions = (options?: Options) => queryOptions>({ +export const getBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts index 547ff7d5e2..66bc1ac937 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { type DefaultError, queryOptions } from '@tanstack/svelte-query'; +import { queryOptions } from '@tanstack/svelte-query'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions) => createQueryKey("getBar", options); +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); -export const getBarOptions = (options?: Options) => queryOptions>({ +export const getBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts index 192793d585..07549729e2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { type DefaultError, queryOptions } from '@tanstack/vue-query'; +import { queryOptions } from '@tanstack/vue-query'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); +export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); -export const getFooOptions = (options?: Options) => queryOptions>({ +export const getFooOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions) => createQueryKey("getBar", options); +export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); -export const getBarOptions = (options?: Options) => queryOptions>({ +export const getBarOptions = (options?: Options) => queryOptions({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts index c2a5190c22..a439d2748f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { 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 c2a5190c22..a439d2748f 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 @@ -95,40 +95,7 @@ export const createClient = (config: Config = {}): Client => { // 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, - }; - } + let response = await _fetch(request); for (const fn of interceptors.response.fns) { if (fn) { diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts index 31874e2bde..faa59eba03 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts @@ -294,7 +294,9 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts index 4640f7e817..cc825b3254 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts @@ -293,7 +293,9 @@ export const zModelWithDictionary = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => { + return zModelWithCircularReference; + }).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts index cc726c6563..ccfbf6f309 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts @@ -294,7 +294,9 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts index 56a3d829e1..9b3bf45710 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts @@ -4,31 +4,43 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => { + return zQuux; + })); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.lazy((): any => zBaz)); + return z.optional(z.lazy((): any => { + return zBaz; + })); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => { + return zQuux; + })); } }); export const zQux = z.union([ z.intersection(z.object({ - type: z.literal("struct") - }), z.lazy(() => z.lazy((): any => zCorge))), + type: z.literal('struct') + }), z.lazy(() => { + return z.lazy((): any => { + return zCorge; + }); + })), z.intersection(z.object({ - type: z.literal("array") + type: z.literal('array') }), zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts index c99bdd0783..2195593a03 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -400,7 +400,9 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); @@ -450,10 +452,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.intersection(z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }), zModelCircle), z.intersection(z.object({ - kind: z.literal("square") + kind: z.literal('square') }), zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts index cfa348c12d..9ef941af5b 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts @@ -8,10 +8,14 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts index da24dd9d8c..bcce4d295c 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts @@ -3,24 +3,34 @@ import { z } from 'zod'; export const zFoo: z.AnyZodObject = z.object({ - quux: z.lazy(() => zQuux).optional() + quux: z.lazy(() => { + return zQuux; + }).optional() }); export const zBar: z.AnyZodObject = z.object({ - bar: z.lazy(() => zBar).optional(), - baz: z.lazy(() => zBaz).optional() + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.lazy(() => { + return zBaz; + }).optional() }); export const zBaz: z.AnyZodObject = z.object({ - quux: z.lazy(() => zQuux).optional() + quux: z.lazy(() => { + return zQuux; + }).optional() }); export const zQux: z.ZodTypeAny = z.union([ z.object({ - type: z.literal("struct") - }).and(z.lazy(() => zCorge)), + type: z.literal('struct') + }).and(z.lazy(() => { + return zCorge; + })), z.object({ - type: z.literal("array") + type: z.literal('array') }).and(zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts index f32143a782..5d788ebe50 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -399,7 +399,9 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => { + return zModelWithCircularReference; + }).optional() }); /** @@ -448,10 +450,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal("square") + kind: z.literal('square') }).and(zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts index 9d727f32d0..13daadc5e5 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts @@ -7,8 +7,12 @@ export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts index 36cd58c4f3..073c23da87 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts @@ -4,31 +4,43 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => { + return zQuux; + })); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.lazy((): any => zBaz)); + return z.optional(z.lazy((): any => { + return zBaz; + })); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => { + return zQuux; + })); } }); export const zQux = z.union([ z.object({ - type: z.literal("struct") - }).and(z.lazy(() => z.lazy((): any => zCorge))), + type: z.literal('struct') + }).and(z.lazy(() => { + return z.lazy((): any => { + return zCorge; + }); + })), z.object({ - type: z.literal("array") + type: z.literal('array') }).and(zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts index 9c08491ec4..3d5fb668b5 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -400,7 +400,9 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); @@ -450,10 +452,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal("square") + kind: z.literal('square') }).and(zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts index 0daf7a0a68..5299554543 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts @@ -8,10 +8,14 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts index 680e0829a8..2a97dcfe22 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -403,7 +403,9 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); @@ -453,10 +455,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.intersection(z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }), zModelCircle), z.intersection(z.object({ - kind: z.literal("square") + kind: z.literal('square') }), zModelSquare) ]); @@ -506,7 +508,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal("ConstValue"); +export const zConstValue = z.literal('ConstValue'); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -751,10 +753,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.string() export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); export const zModelWithConst = z.object({ - String: z.optional(z.literal("String")), + String: z.optional(z.literal('String')), number: z.optional(z.literal(0)), null: z.optional(z.null()), - withType: z.optional(z.literal("Some string")) + withType: z.optional(z.literal('Some string')) }); /** @@ -1686,9 +1688,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal("Success"), - z.literal("Warning"), - z.literal("Error"), + z.literal('Success'), + z.literal('Warning'), + z.literal('Error'), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts index a314590d95..10480c6a67 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ - foo: z.optional(z.literal("foo")), + foo: z.optional(z.literal('foo')), bar: z.optional(z.literal(3.2)), baz: z.optional(z.literal(-1)), qux: z.optional(z.literal(true)), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal("-9223372036854775808")), - stringUint64: z.optional(z.literal("18446744073709551615")) + stringInt64: z.optional(z.literal('-9223372036854775808')), + stringUint64: z.optional(z.literal('18446744073709551615')) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts index 3a8f1806c8..967a236607 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,9 @@ import * as z from 'zod/v4-mini'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => zBar)), + z.array(z.lazy((): any => { + return zBar; + })), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts index dda5d46941..4c5643d938 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts @@ -4,7 +4,9 @@ import * as z from 'zod/v4-mini'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => zBar))); + return z.optional(z.array(z.lazy((): any => { + return zBar; + }))); } }); @@ -12,7 +14,9 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => zQux); +export const zBaz = z.lazy((): any => { + return zQux; +}); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts index 8ecedac9aa..b515009b63 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts @@ -15,10 +15,14 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), @@ -53,7 +57,9 @@ export const zPatchFooData = z.object({ baz: z.optional(z.string()) })), qux: z.optional(z.iso.date()), - quux: z.optional(z.iso.datetime({ offset: true })) + quux: z.optional(z.iso.datetime({ + offset: true + })) })) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts index d9cdb447e1..64973d66ec 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts @@ -14,18 +14,22 @@ export const zQux = z.record(z.string(), z.object({ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/)).register(z.globalRegistry, { - description: "This is foo property." + description: 'This is foo property.' })), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { - description: "This is baz property." + return z.optional(z.array(z.lazy((): any => { + return zFoo; + })).register(z.globalRegistry, { + description: 'This is baz property.' })); }, qux: z._default(z.optional(z.int().check(z.gt(0)).register(z.globalRegistry, { - description: "This is qux property." + description: 'This is qux property.' })), 0) }), z.null() @@ -37,14 +41,14 @@ export const zFoo = z._default(z.union([ export const zBar = z.object({ foo: z.optional(zFoo) }).register(z.globalRegistry, { - description: "This is Bar schema." + description: 'This is Bar schema.' }); /** * This is Foo parameter. */ export const zFoo2 = z.string().register(z.globalRegistry, { - description: "This is Foo parameter." + description: 'This is Foo parameter.' }); export const zFoo3 = z.object({ @@ -58,7 +62,7 @@ export const zPatchFooData = z.object({ path: z.optional(z.never()), query: z.optional(z.object({ foo: z.optional(z.string().register(z.globalRegistry, { - description: "This is Foo parameter." + description: 'This is Foo parameter.' })), bar: z.optional(zBar), baz: z.optional(z.object({ diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts index a8353e832e..2b1c21593f 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts @@ -19,10 +19,14 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts index 304d89bb57..d3e255eb03 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts @@ -15,10 +15,14 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts index 58947fdc5a..e56c1943f4 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -402,7 +402,9 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => { + return zModelWithCircularReference; + }).optional() }); /** @@ -451,10 +453,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal("square") + kind: z.literal('square') }).and(zModelSquare) ]); @@ -504,7 +506,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal("ConstValue"); +export const zConstValue = z.literal('ConstValue'); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -749,10 +751,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.unknown( export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.unknown()); export const zModelWithConst = z.object({ - String: z.literal("String").optional(), + String: z.literal('String').optional(), number: z.literal(0).optional(), null: z.null().optional(), - withType: z.literal("Some string").optional() + withType: z.literal('Some string').optional() }); /** @@ -1684,9 +1686,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal("Success"), - z.literal("Warning"), - z.literal("Error"), + z.literal('Success'), + z.literal('Warning'), + z.literal('Error'), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts index 79075274d6..e577fd348b 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; export const zFoo = z.object({ - foo: z.literal("foo").optional(), + foo: z.literal('foo').optional(), bar: z.literal(3.2).optional(), baz: z.literal(-1).optional(), qux: z.literal(true).optional(), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.literal(65535).optional(), integerUint32: z.literal(4294967295).optional(), integerUint64: z.number().int().optional(), - stringInt64: z.literal("-9223372036854775808").optional(), - stringUint64: z.literal("18446744073709551615").optional() + stringInt64: z.literal('-9223372036854775808').optional(), + stringUint64: z.literal('18446744073709551615').optional() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts index f2c188be3e..582c9ca066 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,9 @@ import { z } from 'zod'; export const zBar: z.AnyZodObject = z.object({ bar: z.union([ - z.array(z.lazy(() => zBar)), + z.array(z.lazy(() => { + return zBar; + })), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts index d1f4aaa4b2..57536e8660 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts @@ -3,14 +3,18 @@ import { z } from 'zod'; export const zBar: z.AnyZodObject = z.object({ - bar: z.array(z.lazy(() => zBar)).optional() + bar: z.array(z.lazy(() => { + return zBar; + })).optional() }); export const zFoo = z.object({ foo: zBar.optional() }); -export const zBaz: z.ZodTypeAny = z.lazy(() => zQux); +export const zBaz: z.ZodTypeAny = z.lazy(() => { + return zQux; +}); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts index c9317d5912..620a0a8640 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts @@ -14,8 +14,12 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() @@ -49,7 +53,9 @@ export const zPatchFooData = z.object({ baz: z.string().optional() }).optional(), qux: z.string().date().optional(), - quux: z.string().datetime({ offset: true }).optional() + quux: z.string().datetime({ + offset: true + }).optional() }).optional() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts index e89f8e00be..4a09748c76 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts @@ -13,10 +13,14 @@ export const zQux = z.record(z.object({ */ export const zFoo: z.ZodTypeAny = z.union([ z.object({ - foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe("This is foo property.").optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).describe("This is baz property.").optional(), - qux: z.number().int().gt(0).describe("This is qux property.").optional().default(0) + foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe('This is foo property.').optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).describe('This is baz property.').optional(), + qux: z.number().int().gt(0).describe('This is qux property.').optional().default(0) }), z.null() ]).default(null); @@ -26,12 +30,12 @@ export const zFoo: z.ZodTypeAny = z.union([ */ export const zBar = z.object({ foo: zFoo.optional() -}).describe("This is Bar schema."); +}).describe('This is Bar schema.'); /** * This is Foo parameter. */ -export const zFoo2 = z.string().describe("This is Foo parameter."); +export const zFoo2 = z.string().describe('This is Foo parameter.'); export const zFoo3 = z.object({ foo: zBar.optional() @@ -43,7 +47,7 @@ export const zPatchFooData = z.object({ }), path: z.never().optional(), query: z.object({ - foo: z.string().describe("This is Foo parameter.").optional(), + foo: z.string().describe('This is Foo parameter.').optional(), bar: zBar.optional(), baz: z.object({ baz: z.string().optional() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts index c26d40cf35..d79d307e9b 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts @@ -18,8 +18,12 @@ export type QuxZodType = z.infer; export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts index 8e5318a8c7..bcda6a22d8 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts @@ -14,8 +14,12 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts index 57de43d2ac..6279534dbd 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -403,7 +403,9 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); @@ -453,10 +455,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal("square") + kind: z.literal('square') }).and(zModelSquare) ]); @@ -506,7 +508,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal("ConstValue"); +export const zConstValue = z.literal('ConstValue'); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -751,10 +753,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.string() export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); export const zModelWithConst = z.object({ - String: z.optional(z.literal("String")), + String: z.optional(z.literal('String')), number: z.optional(z.literal(0)), null: z.optional(z.null()), - withType: z.optional(z.literal("Some string")) + withType: z.optional(z.literal('Some string')) }); /** @@ -1686,9 +1688,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal("Success"), - z.literal("Warning"), - z.literal("Error"), + z.literal('Success'), + z.literal('Warning'), + z.literal('Error'), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts index 152fe92964..961bdec15c 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ - foo: z.optional(z.literal("foo")), + foo: z.optional(z.literal('foo')), bar: z.optional(z.literal(3.2)), baz: z.optional(z.literal(-1)), qux: z.optional(z.literal(true)), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal("-9223372036854775808")), - stringUint64: z.optional(z.literal("18446744073709551615")) + stringInt64: z.optional(z.literal('-9223372036854775808')), + stringUint64: z.optional(z.literal('18446744073709551615')) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts index 0560094fdc..8f42902913 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,9 @@ import { z } from 'zod/v4'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => zBar)), + z.array(z.lazy((): any => { + return zBar; + })), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts index 7bd218fcbf..0fba2fc8b7 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts @@ -4,7 +4,9 @@ import { z } from 'zod/v4'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => zBar))); + return z.optional(z.array(z.lazy((): any => { + return zBar; + }))); } }); @@ -12,7 +14,9 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => zQux); +export const zBaz = z.lazy((): any => { + return zQux; +}); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts index 5781d917ff..36e6f721aa 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts @@ -15,10 +15,14 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z.optional(z.int().gt(0)).default(0) }), @@ -53,7 +57,9 @@ export const zPatchFooData = z.object({ baz: z.optional(z.string()) })), qux: z.optional(z.iso.date()), - quux: z.optional(z.iso.datetime({ offset: true })) + quux: z.optional(z.iso.datetime({ + offset: true + })) })) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts index eb25f46f5a..270bc9a0d3 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts @@ -14,18 +14,22 @@ export const zQux = z.record(z.string(), z.object({ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/).register(z.globalRegistry, { - description: "This is foo property." + description: 'This is foo property.' })), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { - description: "This is baz property." + return z.optional(z.array(z.lazy((): any => { + return zFoo; + })).register(z.globalRegistry, { + description: 'This is baz property.' })); }, qux: z.optional(z.int().gt(0).register(z.globalRegistry, { - description: "This is qux property." + description: 'This is qux property.' })).default(0) }), z.null() @@ -37,14 +41,14 @@ export const zFoo = z.union([ export const zBar = z.object({ foo: z.optional(zFoo) }).register(z.globalRegistry, { - description: "This is Bar schema." + description: 'This is Bar schema.' }); /** * This is Foo parameter. */ export const zFoo2 = z.string().register(z.globalRegistry, { - description: "This is Foo parameter." + description: 'This is Foo parameter.' }); export const zFoo3 = z.object({ @@ -58,7 +62,7 @@ export const zPatchFooData = z.object({ path: z.optional(z.never()), query: z.optional(z.object({ foo: z.optional(z.string().register(z.globalRegistry, { - description: "This is Foo parameter." + description: 'This is Foo parameter.' })), bar: z.optional(zBar), baz: z.optional(z.object({ diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts index b2d4ca7177..c36f93b323 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts @@ -19,10 +19,14 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts index 15238b2a7e..2b37813980 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts @@ -15,10 +15,14 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts index a89a89735c..86fca9b1d6 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts @@ -294,7 +294,9 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts index 46bd465e9a..6b727d44ee 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts @@ -293,7 +293,9 @@ export const zModelWithDictionary = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => { + return zModelWithCircularReference; + }).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts index 87c7a4316d..bc7dcb6542 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts @@ -294,7 +294,9 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts index a1cb7944f2..0c5d13033f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts @@ -4,31 +4,43 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => { + return zQuux; + })); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.lazy((): any => zBaz)); + return z.optional(z.lazy((): any => { + return zBaz; + })); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => { + return zQuux; + })); } }); export const zQux = z.union([ z.intersection(z.object({ - type: z.literal("struct") - }), z.lazy(() => z.lazy((): any => zCorge))), + type: z.literal('struct') + }), z.lazy(() => { + return z.lazy((): any => { + return zCorge; + }); + })), z.intersection(z.object({ - type: z.literal("array") + type: z.literal('array') }), zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts index 5a6405c953..5b29d62f75 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -400,7 +400,9 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); @@ -450,10 +452,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.intersection(z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }), zModelCircle), z.intersection(z.object({ - kind: z.literal("square") + kind: z.literal('square') }), zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts index 7a5c784862..786ac3505a 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts @@ -8,10 +8,14 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts index 6be8f68f2a..6011ab3e7c 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts @@ -3,24 +3,34 @@ import { z } from 'zod/v3'; export const zFoo: z.AnyZodObject = z.object({ - quux: z.lazy(() => zQuux).optional() + quux: z.lazy(() => { + return zQuux; + }).optional() }); export const zBar: z.AnyZodObject = z.object({ - bar: z.lazy(() => zBar).optional(), - baz: z.lazy(() => zBaz).optional() + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.lazy(() => { + return zBaz; + }).optional() }); export const zBaz: z.AnyZodObject = z.object({ - quux: z.lazy(() => zQuux).optional() + quux: z.lazy(() => { + return zQuux; + }).optional() }); export const zQux: z.ZodTypeAny = z.union([ z.object({ - type: z.literal("struct") - }).and(z.lazy(() => zCorge)), + type: z.literal('struct') + }).and(z.lazy(() => { + return zCorge; + })), z.object({ - type: z.literal("array") + type: z.literal('array') }).and(zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts index 50fddeaa4a..6b12e930da 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -399,7 +399,9 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => { + return zModelWithCircularReference; + }).optional() }); /** @@ -448,10 +450,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal("square") + kind: z.literal('square') }).and(zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts index bdddc57752..884fe8b894 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts @@ -7,8 +7,12 @@ export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts index e8811d02f5..27ac2c0cc9 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts @@ -4,31 +4,43 @@ import { z } from 'zod'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => { + return zQuux; + })); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.lazy((): any => zBaz)); + return z.optional(z.lazy((): any => { + return zBaz; + })); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => zQuux)); + return z.optional(z.lazy((): any => { + return zQuux; + })); } }); export const zQux = z.union([ z.object({ - type: z.literal("struct") - }).and(z.lazy(() => z.lazy((): any => zCorge))), + type: z.literal('struct') + }).and(z.lazy(() => { + return z.lazy((): any => { + return zCorge; + }); + })), z.object({ - type: z.literal("array") + type: z.literal('array') }).and(zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts index c44dd9b8e4..b608099100 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -400,7 +400,9 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); @@ -450,10 +452,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal("square") + kind: z.literal('square') }).and(zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts index 944f96e474..f6b581f0d9 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts @@ -8,10 +8,14 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts index 7974190a01..5ffa612787 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -403,7 +403,9 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); @@ -453,10 +455,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.intersection(z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }), zModelCircle), z.intersection(z.object({ - kind: z.literal("square") + kind: z.literal('square') }), zModelSquare) ]); @@ -506,7 +508,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal("ConstValue"); +export const zConstValue = z.literal('ConstValue'); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -751,10 +753,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.string() export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); export const zModelWithConst = z.object({ - String: z.optional(z.literal("String")), + String: z.optional(z.literal('String')), number: z.optional(z.literal(0)), null: z.optional(z.null()), - withType: z.optional(z.literal("Some string")) + withType: z.optional(z.literal('Some string')) }); /** @@ -1686,9 +1688,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal("Success"), - z.literal("Warning"), - z.literal("Error"), + z.literal('Success'), + z.literal('Warning'), + z.literal('Error'), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts index c6bbe64fa0..1b4e0e1cf1 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ - foo: z.optional(z.literal("foo")), + foo: z.optional(z.literal('foo')), bar: z.optional(z.literal(3.2)), baz: z.optional(z.literal(-1)), qux: z.optional(z.literal(true)), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal("-9223372036854775808")), - stringUint64: z.optional(z.literal("18446744073709551615")) + stringInt64: z.optional(z.literal('-9223372036854775808')), + stringUint64: z.optional(z.literal('18446744073709551615')) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts index 6014595afa..aed07582c6 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,9 @@ import * as z from 'zod/mini'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => zBar)), + z.array(z.lazy((): any => { + return zBar; + })), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts index ee8b0c76ef..33a0a739a4 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts @@ -4,7 +4,9 @@ import * as z from 'zod/mini'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => zBar))); + return z.optional(z.array(z.lazy((): any => { + return zBar; + }))); } }); @@ -12,7 +14,9 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => zQux); +export const zBaz = z.lazy((): any => { + return zQux; +}); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts index 9ac32990ce..d64c84a813 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts @@ -15,10 +15,14 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), @@ -53,7 +57,9 @@ export const zPatchFooData = z.object({ baz: z.optional(z.string()) })), qux: z.optional(z.iso.date()), - quux: z.optional(z.iso.datetime({ offset: true })) + quux: z.optional(z.iso.datetime({ + offset: true + })) })) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts index db559c7419..aaf540431c 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts @@ -14,18 +14,22 @@ export const zQux = z.record(z.string(), z.object({ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/)).register(z.globalRegistry, { - description: "This is foo property." + description: 'This is foo property.' })), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { - description: "This is baz property." + return z.optional(z.array(z.lazy((): any => { + return zFoo; + })).register(z.globalRegistry, { + description: 'This is baz property.' })); }, qux: z._default(z.optional(z.int().check(z.gt(0)).register(z.globalRegistry, { - description: "This is qux property." + description: 'This is qux property.' })), 0) }), z.null() @@ -37,14 +41,14 @@ export const zFoo = z._default(z.union([ export const zBar = z.object({ foo: z.optional(zFoo) }).register(z.globalRegistry, { - description: "This is Bar schema." + description: 'This is Bar schema.' }); /** * This is Foo parameter. */ export const zFoo2 = z.string().register(z.globalRegistry, { - description: "This is Foo parameter." + description: 'This is Foo parameter.' }); export const zFoo3 = z.object({ @@ -58,7 +62,7 @@ export const zPatchFooData = z.object({ path: z.optional(z.never()), query: z.optional(z.object({ foo: z.optional(z.string().register(z.globalRegistry, { - description: "This is Foo parameter." + description: 'This is Foo parameter.' })), bar: z.optional(zBar), baz: z.optional(z.object({ diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts index 669174c0ac..19e14da91b 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts @@ -19,10 +19,14 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts index b786abd75f..65b32c7ba9 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts @@ -15,10 +15,14 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts index bd1c50c977..49aa50ac5d 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -402,7 +402,9 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => zModelWithCircularReference).optional() + prop: z.lazy(() => { + return zModelWithCircularReference; + }).optional() }); /** @@ -451,10 +453,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal("square") + kind: z.literal('square') }).and(zModelSquare) ]); @@ -504,7 +506,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal("ConstValue"); +export const zConstValue = z.literal('ConstValue'); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -749,10 +751,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.unknown( export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.unknown()); export const zModelWithConst = z.object({ - String: z.literal("String").optional(), + String: z.literal('String').optional(), number: z.literal(0).optional(), null: z.null().optional(), - withType: z.literal("Some string").optional() + withType: z.literal('Some string').optional() }); /** @@ -1684,9 +1686,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal("Success"), - z.literal("Warning"), - z.literal("Error"), + z.literal('Success'), + z.literal('Warning'), + z.literal('Error'), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts index 4994bcc671..2f582cbad9 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import { z } from 'zod/v3'; export const zFoo = z.object({ - foo: z.literal("foo").optional(), + foo: z.literal('foo').optional(), bar: z.literal(3.2).optional(), baz: z.literal(-1).optional(), qux: z.literal(true).optional(), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.literal(65535).optional(), integerUint32: z.literal(4294967295).optional(), integerUint64: z.number().int().optional(), - stringInt64: z.literal("-9223372036854775808").optional(), - stringUint64: z.literal("18446744073709551615").optional() + stringInt64: z.literal('-9223372036854775808').optional(), + stringUint64: z.literal('18446744073709551615').optional() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts index 4d47e4d619..15bdeb3e2c 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,9 @@ import { z } from 'zod/v3'; export const zBar: z.AnyZodObject = z.object({ bar: z.union([ - z.array(z.lazy(() => zBar)), + z.array(z.lazy(() => { + return zBar; + })), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts index 02708822cd..466a9fc5b0 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts @@ -3,14 +3,18 @@ import { z } from 'zod/v3'; export const zBar: z.AnyZodObject = z.object({ - bar: z.array(z.lazy(() => zBar)).optional() + bar: z.array(z.lazy(() => { + return zBar; + })).optional() }); export const zFoo = z.object({ foo: zBar.optional() }); -export const zBaz: z.ZodTypeAny = z.lazy(() => zQux); +export const zBaz: z.ZodTypeAny = z.lazy(() => { + return zQux; +}); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts index 68a0a720f4..746c1c5742 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts @@ -14,8 +14,12 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() @@ -49,7 +53,9 @@ export const zPatchFooData = z.object({ baz: z.string().optional() }).optional(), qux: z.string().date().optional(), - quux: z.string().datetime({ offset: true }).optional() + quux: z.string().datetime({ + offset: true + }).optional() }).optional() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts index f2ed3769dd..396361b2aa 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts @@ -13,10 +13,14 @@ export const zQux = z.record(z.object({ */ export const zFoo: z.ZodTypeAny = z.union([ z.object({ - foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe("This is foo property.").optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).describe("This is baz property.").optional(), - qux: z.number().int().gt(0).describe("This is qux property.").optional().default(0) + foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe('This is foo property.').optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).describe('This is baz property.').optional(), + qux: z.number().int().gt(0).describe('This is qux property.').optional().default(0) }), z.null() ]).default(null); @@ -26,12 +30,12 @@ export const zFoo: z.ZodTypeAny = z.union([ */ export const zBar = z.object({ foo: zFoo.optional() -}).describe("This is Bar schema."); +}).describe('This is Bar schema.'); /** * This is Foo parameter. */ -export const zFoo2 = z.string().describe("This is Foo parameter."); +export const zFoo2 = z.string().describe('This is Foo parameter.'); export const zFoo3 = z.object({ foo: zBar.optional() @@ -43,7 +47,7 @@ export const zPatchFooData = z.object({ }), path: z.never().optional(), query: z.object({ - foo: z.string().describe("This is Foo parameter.").optional(), + foo: z.string().describe('This is Foo parameter.').optional(), bar: zBar.optional(), baz: z.object({ baz: z.string().optional() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts index 2b0fa9eed9..7b92df5bc5 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts @@ -18,8 +18,12 @@ export type QuxZodType = z.infer; export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts index 15850f6a29..d4c6fe5369 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts @@ -14,8 +14,12 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => zBar).optional(), - baz: z.array(z.lazy(() => zFoo)).optional(), + bar: z.lazy(() => { + return zBar; + }).optional(), + baz: z.array(z.lazy(() => { + return zFoo; + })).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts index a9cded5374..8bafc886b2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -403,7 +403,9 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => zModelWithCircularReference)); + return z.optional(z.lazy((): any => { + return zModelWithCircularReference; + })); } }); @@ -453,10 +455,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal("circle") + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal("square") + kind: z.literal('square') }).and(zModelSquare) ]); @@ -506,7 +508,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal("ConstValue"); +export const zConstValue = z.literal('ConstValue'); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -751,10 +753,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.string() export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); export const zModelWithConst = z.object({ - String: z.optional(z.literal("String")), + String: z.optional(z.literal('String')), number: z.optional(z.literal(0)), null: z.optional(z.null()), - withType: z.optional(z.literal("Some string")) + withType: z.optional(z.literal('Some string')) }); /** @@ -1686,9 +1688,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal("Success"), - z.literal("Warning"), - z.literal("Error"), + z.literal('Success'), + z.literal('Warning'), + z.literal('Error'), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts index 46ea47c1df..2b7e1c4622 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; export const zFoo = z.object({ - foo: z.optional(z.literal("foo")), + foo: z.optional(z.literal('foo')), bar: z.optional(z.literal(3.2)), baz: z.optional(z.literal(-1)), qux: z.optional(z.literal(true)), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal("-9223372036854775808")), - stringUint64: z.optional(z.literal("18446744073709551615")) + stringInt64: z.optional(z.literal('-9223372036854775808')), + stringUint64: z.optional(z.literal('18446744073709551615')) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts index 696338aab2..f638411068 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts @@ -4,7 +4,9 @@ import { z } from 'zod'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => zBar)), + z.array(z.lazy((): any => { + return zBar; + })), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts index b628129549..53ce2eb2f0 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts @@ -4,7 +4,9 @@ import { z } from 'zod'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => zBar))); + return z.optional(z.array(z.lazy((): any => { + return zBar; + }))); } }); @@ -12,7 +14,9 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => zQux); +export const zBaz = z.lazy((): any => { + return zQux; +}); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts index 515d9ad8bd..bc6bd1d71e 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts @@ -15,10 +15,14 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z.optional(z.int().gt(0)).default(0) }), @@ -53,7 +57,9 @@ export const zPatchFooData = z.object({ baz: z.optional(z.string()) })), qux: z.optional(z.iso.date()), - quux: z.optional(z.iso.datetime({ offset: true })) + quux: z.optional(z.iso.datetime({ + offset: true + })) })) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts index 9678e5eb9d..4e71c97c64 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts @@ -14,18 +14,22 @@ export const zQux = z.record(z.string(), z.object({ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/).register(z.globalRegistry, { - description: "This is foo property." + description: 'This is foo property.' })), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { - description: "This is baz property." + return z.optional(z.array(z.lazy((): any => { + return zFoo; + })).register(z.globalRegistry, { + description: 'This is baz property.' })); }, qux: z.optional(z.int().gt(0).register(z.globalRegistry, { - description: "This is qux property." + description: 'This is qux property.' })).default(0) }), z.null() @@ -37,14 +41,14 @@ export const zFoo = z.union([ export const zBar = z.object({ foo: z.optional(zFoo) }).register(z.globalRegistry, { - description: "This is Bar schema." + description: 'This is Bar schema.' }); /** * This is Foo parameter. */ export const zFoo2 = z.string().register(z.globalRegistry, { - description: "This is Foo parameter." + description: 'This is Foo parameter.' }); export const zFoo3 = z.object({ @@ -58,7 +62,7 @@ export const zPatchFooData = z.object({ path: z.optional(z.never()), query: z.optional(z.object({ foo: z.optional(z.string().register(z.globalRegistry, { - description: "This is Foo parameter." + description: 'This is Foo parameter.' })), bar: z.optional(zBar), baz: z.optional(z.object({ diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts index 033e85ced5..ba13cd685d 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts @@ -19,10 +19,14 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts index f73a35bac9..a48bf21863 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts @@ -15,10 +15,14 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => zBar)); + return z.optional(z.lazy((): any => { + return zBar; + })); }, get baz() { - return z.optional(z.array(z.lazy((): any => zFoo))); + return z.optional(z.array(z.lazy((): any => { + return zFoo; + }))); }, qux: z.optional(z.int().gt(0)).default(0) }), From 5c53c2cba97c2caf7c5443fb1d89f08695a22592 Mon Sep 17 00:00:00 2001 From: Pewww Date: Thu, 13 Nov 2025 15:27:46 +0900 Subject: [PATCH 7/9] fix: rebuild tests --- .../src/client/client/client.gen.ts | 35 ++++++++- .../src/client/client/client.gen.ts | 35 ++++++++- .../src/client/client/client.gen.ts | 35 ++++++++- .../src/client/client/client.gen.ts | 30 +++++++- .../src/client/client/client.gen.ts | 35 ++++++++- examples/openapi-ts-swr/src/client/swr.gen.ts | 22 +++--- .../angular-query-experimental.gen.ts | 63 +++++++++++++--- .../src/client/@tanstack/react-query.gen.ts | 63 +++++++++++++--- .../src/client/client/client.gen.ts | 35 ++++++++- .../src/client/@tanstack/svelte-query.gen.ts | 63 +++++++++++++--- .../src/client/client/client.gen.ts | 35 ++++++++- .../src/client/@tanstack/vue-query.gen.ts | 58 ++++++++++++--- .../src/client/client/client.gen.ts | 30 +++++++- .../client/client.gen.ts | 35 ++++++++- .../2.0.x/form-data/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../sdk-nested-classes/client/client.gen.ts | 35 ++++++++- .../@hey-api/sdk/default/client/client.gen.ts | 35 ++++++++- .../sdk/instance/client/client.gen.ts | 35 ++++++++- .../sdk/throwOnError/client/client.gen.ts | 35 ++++++++- .../type-format-valibot/client/client.gen.ts | 35 ++++++++- .../type-format-zod/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../colada/asClass/client/client.gen.ts | 35 ++++++++- .../@pinia/colada/fetch/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 10 +-- .../asClass/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 50 ++++++------- .../angular-query-experimental.gen.ts | 50 ++++++------- .../fetch/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/react-query.gen.ts | 10 +-- .../react-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/react-query.gen.ts | 50 ++++++------- .../fetch/@tanstack/react-query.gen.ts | 50 ++++++------- .../react-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/react-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/solid-query.gen.ts | 10 +-- .../solid-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/solid-query.gen.ts | 50 ++++++------- .../fetch/@tanstack/solid-query.gen.ts | 50 ++++++------- .../solid-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/solid-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/svelte-query.gen.ts | 10 +-- .../svelte-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/svelte-query.gen.ts | 50 ++++++------- .../fetch/@tanstack/svelte-query.gen.ts | 50 ++++++------- .../svelte-query/fetch/client/client.gen.ts | 35 ++++++++- .../@tanstack/svelte-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/vue-query.gen.ts | 10 +-- .../vue-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/vue-query.gen.ts | 50 ++++++------- .../fetch/@tanstack/vue-query.gen.ts | 50 ++++++------- .../vue-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/vue-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../plugins/swr/asClass/client/client.gen.ts | 35 ++++++++- .../2.0.x/plugins/swr/asClass/swr.gen.ts | 8 +-- .../2.0.x/plugins/swr/axios/swr.gen.ts | 40 +++++------ .../plugins/swr/fetch/client/client.gen.ts | 35 ++++++++- .../2.0.x/plugins/swr/fetch/swr.gen.ts | 40 +++++------ .../2.0.x/schema-unknown/client/client.gen.ts | 35 ++++++++- .../security-api-key/client/client.gen.ts | 35 ++++++++- .../2.0.x/security-basic/client/client.gen.ts | 35 ++++++++- .../2.0.x/security-false/client/client.gen.ts | 35 ++++++++- .../security-oauth2/client/client.gen.ts | 35 ++++++++- .../servers-base-path/client/client.gen.ts | 35 ++++++++- .../2.0.x/servers-host/client/client.gen.ts | 35 ++++++++- .../2.0.x/servers/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../@tanstack/react-query.gen.ts | 4 +- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../sdk-nested-classes/client/client.gen.ts | 35 ++++++++- .../@hey-api/sdk/default/client/client.gen.ts | 35 ++++++++- .../sdk/instance/client/client.gen.ts | 35 ++++++++- .../sdk/throwOnError/client/client.gen.ts | 35 ++++++++- .../type-format-valibot/client/client.gen.ts | 35 ++++++++- .../type-format-zod/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../colada/asClass/client/client.gen.ts | 35 ++++++++- .../@pinia/colada/fetch/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 10 +-- .../asClass/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 72 +++++++++---------- .../angular-query-experimental.gen.ts | 72 +++++++++---------- .../fetch/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/react-query.gen.ts | 10 +-- .../react-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/react-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/react-query.gen.ts | 72 +++++++++---------- .../react-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/react-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/solid-query.gen.ts | 10 +-- .../solid-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/solid-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/solid-query.gen.ts | 72 +++++++++---------- .../solid-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/solid-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/svelte-query.gen.ts | 10 +-- .../svelte-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/svelte-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/svelte-query.gen.ts | 72 +++++++++---------- .../svelte-query/fetch/client/client.gen.ts | 35 ++++++++- .../@tanstack/svelte-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/vue-query.gen.ts | 10 +-- .../vue-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/vue-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/vue-query.gen.ts | 72 +++++++++---------- .../vue-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/vue-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../plugins/swr/asClass/client/client.gen.ts | 35 ++++++++- .../3.0.x/plugins/swr/asClass/swr.gen.ts | 8 +-- .../3.0.x/plugins/swr/axios/swr.gen.ts | 58 +++++++-------- .../plugins/swr/fetch/client/client.gen.ts | 35 ++++++++- .../3.0.x/plugins/swr/fetch/swr.gen.ts | 58 +++++++-------- .../plugins/valibot/default/valibot.gen.ts | 4 +- .../security-api-key/client/client.gen.ts | 35 ++++++++- .../3.0.x/security-false/client/client.gen.ts | 35 ++++++++- .../security-http-bearer/client/client.gen.ts | 35 ++++++++- .../security-oauth2/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../3.0.x/servers/client/client.gen.ts | 35 ++++++++- .../transformers-all-of/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../transformers-array/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../base-url-false/client/client.gen.ts | 35 ++++++++- .../base-url-number/client/client.gen.ts | 35 ++++++++- .../base-url-strict/client/client.gen.ts | 35 ++++++++- .../base-url-string/client/client.gen.ts | 35 ++++++++- .../clean-false/client/client.gen.ts | 35 ++++++++- .../client-fetch/default/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../sdk-client-optional/client/client.gen.ts | 35 ++++++++- .../sdk-client-required/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../3.1.x/headers/client/client.gen.ts | 35 ++++++++- .../@tanstack/react-query.gen.ts | 4 +- .../client/client.gen.ts | 35 ++++++++- .../@tanstack/react-query.gen.ts | 6 +- .../3.1.x/pagination-ref/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../sdk-nested-classes/client/client.gen.ts | 35 ++++++++- .../@hey-api/sdk/default/client/client.gen.ts | 35 ++++++++- .../sdk/instance/client/client.gen.ts | 35 ++++++++- .../sdk/throwOnError/client/client.gen.ts | 35 ++++++++- .../type-format-valibot/client/client.gen.ts | 35 ++++++++- .../type-format-zod/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../colada/asClass/client/client.gen.ts | 35 ++++++++- .../@pinia/colada/fetch/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 10 +-- .../asClass/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 72 +++++++++---------- .../angular-query-experimental.gen.ts | 72 +++++++++---------- .../fetch/client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/react-query.gen.ts | 10 +-- .../react-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/react-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/react-query.gen.ts | 72 +++++++++---------- .../react-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/react-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/solid-query.gen.ts | 10 +-- .../solid-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/solid-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/solid-query.gen.ts | 72 +++++++++---------- .../solid-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/solid-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/svelte-query.gen.ts | 10 +-- .../svelte-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/svelte-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/svelte-query.gen.ts | 72 +++++++++---------- .../svelte-query/fetch/client/client.gen.ts | 35 ++++++++- .../@tanstack/svelte-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../asClass/@tanstack/vue-query.gen.ts | 10 +-- .../vue-query/asClass/client/client.gen.ts | 35 ++++++++- .../axios/@tanstack/vue-query.gen.ts | 72 +++++++++---------- .../fetch/@tanstack/vue-query.gen.ts | 72 +++++++++---------- .../vue-query/fetch/client/client.gen.ts | 35 ++++++++- .../name-builder/@tanstack/vue-query.gen.ts | 10 +-- .../name-builder/client/client.gen.ts | 35 ++++++++- .../plugins/swr/asClass/client/client.gen.ts | 35 ++++++++- .../3.1.x/plugins/swr/asClass/swr.gen.ts | 8 +-- .../3.1.x/plugins/swr/axios/swr.gen.ts | 58 +++++++-------- .../plugins/swr/fetch/client/client.gen.ts | 35 ++++++++- .../3.1.x/plugins/swr/fetch/swr.gen.ts | 58 +++++++-------- .../plugins/valibot/default/valibot.gen.ts | 16 ++--- .../3.1.x/schema-const/valibot.gen.ts | 2 +- .../security-api-key/client/client.gen.ts | 35 ++++++++- .../3.1.x/security-false/client/client.gen.ts | 35 ++++++++- .../security-http-bearer/client/client.gen.ts | 35 ++++++++- .../security-oauth2/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../3.1.x/servers/client/client.gen.ts | 35 ++++++++- .../3.1.x/sse-fetch/client/client.gen.ts | 35 ++++++++- .../transformers-all-of/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../transformers-array/client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../client/client.gen.ts | 35 ++++++++- .../angular-query-experimental.gen.ts | 10 +-- .../meta/@tanstack/react-query.gen.ts | 10 +-- .../meta/@tanstack/solid-query.gen.ts | 10 +-- .../meta/@tanstack/svelte-query.gen.ts | 10 +-- .../@tanstack/meta/@tanstack/vue-query.gen.ts | 10 +-- .../@tanstack/meta/client/client.gen.ts | 35 ++++++++- .../test/plugins/swr/basic-generation.test.ts | 6 +- .../class/client/client.gen.ts | 35 ++++++++- .../flat/client/client.gen.ts | 35 ++++++++- .../instance/client/client.gen.ts | 35 ++++++++- .../opencode/flat/client/client.gen.ts | 35 ++++++++- .../opencode/grouped/client/client.gen.ts | 35 ++++++++- .../2.0.x/mini/default/zod.gen.ts | 4 +- .../__snapshots__/2.0.x/v3/default/zod.gen.ts | 4 +- .../__snapshots__/2.0.x/v4/default/zod.gen.ts | 4 +- .../3.0.x/mini/circular/zod.gen.ts | 26 ++----- .../3.0.x/mini/default/zod.gen.ts | 8 +-- .../3.0.x/mini/validators/zod.gen.ts | 8 +-- .../3.0.x/v3/circular/zod.gen.ts | 24 ++----- .../__snapshots__/3.0.x/v3/default/zod.gen.ts | 8 +-- .../3.0.x/v3/validators/zod.gen.ts | 8 +-- .../3.0.x/v4/circular/zod.gen.ts | 26 ++----- .../__snapshots__/3.0.x/v4/default/zod.gen.ts | 8 +-- .../3.0.x/v4/validators/zod.gen.ts | 8 +-- .../3.1.x/mini/default/zod.gen.ts | 20 +++--- .../3.1.x/mini/schema-const/zod.gen.ts | 6 +- .../mini/validators-circular-ref-2/zod.gen.ts | 4 +- .../mini/validators-circular-ref/zod.gen.ts | 8 +-- .../3.1.x/mini/validators-dates/zod.gen.ts | 12 +--- .../3.1.x/mini/validators-metadata/zod.gen.ts | 20 +++--- .../3.1.x/mini/validators-types/zod.gen.ts | 8 +-- .../3.1.x/mini/validators/zod.gen.ts | 8 +-- .../__snapshots__/3.1.x/v3/default/zod.gen.ts | 20 +++--- .../3.1.x/v3/schema-const/zod.gen.ts | 6 +- .../v3/validators-circular-ref-2/zod.gen.ts | 4 +- .../v3/validators-circular-ref/zod.gen.ts | 8 +-- .../3.1.x/v3/validators-dates/zod.gen.ts | 12 +--- .../3.1.x/v3/validators-metadata/zod.gen.ts | 18 ++--- .../3.1.x/v3/validators-types/zod.gen.ts | 8 +-- .../3.1.x/v3/validators/zod.gen.ts | 8 +-- .../__snapshots__/3.1.x/v4/default/zod.gen.ts | 20 +++--- .../3.1.x/v4/schema-const/zod.gen.ts | 6 +- .../v4/validators-circular-ref-2/zod.gen.ts | 4 +- .../v4/validators-circular-ref/zod.gen.ts | 8 +-- .../3.1.x/v4/validators-dates/zod.gen.ts | 12 +--- .../3.1.x/v4/validators-metadata/zod.gen.ts | 20 +++--- .../3.1.x/v4/validators-types/zod.gen.ts | 8 +-- .../3.1.x/v4/validators/zod.gen.ts | 8 +-- .../2.0.x/mini/default/zod.gen.ts | 4 +- .../__snapshots__/2.0.x/v3/default/zod.gen.ts | 4 +- .../__snapshots__/2.0.x/v4/default/zod.gen.ts | 4 +- .../3.0.x/mini/circular/zod.gen.ts | 26 ++----- .../3.0.x/mini/default/zod.gen.ts | 8 +-- .../3.0.x/mini/validators/zod.gen.ts | 8 +-- .../3.0.x/v3/circular/zod.gen.ts | 24 ++----- .../__snapshots__/3.0.x/v3/default/zod.gen.ts | 8 +-- .../3.0.x/v3/validators/zod.gen.ts | 8 +-- .../3.0.x/v4/circular/zod.gen.ts | 26 ++----- .../__snapshots__/3.0.x/v4/default/zod.gen.ts | 8 +-- .../3.0.x/v4/validators/zod.gen.ts | 8 +-- .../3.1.x/mini/default/zod.gen.ts | 20 +++--- .../3.1.x/mini/schema-const/zod.gen.ts | 6 +- .../mini/validators-circular-ref-2/zod.gen.ts | 4 +- .../mini/validators-circular-ref/zod.gen.ts | 8 +-- .../3.1.x/mini/validators-dates/zod.gen.ts | 12 +--- .../3.1.x/mini/validators-metadata/zod.gen.ts | 20 +++--- .../3.1.x/mini/validators-types/zod.gen.ts | 8 +-- .../3.1.x/mini/validators/zod.gen.ts | 8 +-- .../__snapshots__/3.1.x/v3/default/zod.gen.ts | 20 +++--- .../3.1.x/v3/schema-const/zod.gen.ts | 6 +- .../v3/validators-circular-ref-2/zod.gen.ts | 4 +- .../v3/validators-circular-ref/zod.gen.ts | 8 +-- .../3.1.x/v3/validators-dates/zod.gen.ts | 12 +--- .../3.1.x/v3/validators-metadata/zod.gen.ts | 18 ++--- .../3.1.x/v3/validators-types/zod.gen.ts | 8 +-- .../3.1.x/v3/validators/zod.gen.ts | 8 +-- .../__snapshots__/3.1.x/v4/default/zod.gen.ts | 20 +++--- .../3.1.x/v4/schema-const/zod.gen.ts | 6 +- .../v4/validators-circular-ref-2/zod.gen.ts | 4 +- .../v4/validators-circular-ref/zod.gen.ts | 8 +-- .../3.1.x/v4/validators-dates/zod.gen.ts | 12 +--- .../3.1.x/v4/validators-metadata/zod.gen.ts | 20 +++--- .../3.1.x/v4/validators-types/zod.gen.ts | 8 +-- .../3.1.x/v4/validators/zod.gen.ts | 8 +-- .../src/plugins/swr/v2/swrMutationOptions.ts | 4 +- 309 files changed, 6907 insertions(+), 2058 deletions(-) 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 a439d2748f..c2a5190c22 100644 --- a/examples/openapi-ts-fastify/src/client/client/client.gen.ts +++ b/examples/openapi-ts-fastify/src/client/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 100644 --- a/examples/openapi-ts-fetch/src/client/client/client.gen.ts +++ b/examples/openapi-ts-fetch/src/client/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 100644 --- a/examples/openapi-ts-openai/src/client/client/client.gen.ts +++ b/examples/openapi-ts-openai/src/client/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 4a4fc4648f..00dbae3997 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 @@ -85,7 +85,35 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request) + 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) { diff --git a/examples/openapi-ts-swr/src/client/client/client.gen.ts b/examples/openapi-ts-swr/src/client/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/examples/openapi-ts-swr/src/client/client/client.gen.ts +++ b/examples/openapi-ts-swr/src/client/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/examples/openapi-ts-swr/src/client/swr.gen.ts b/examples/openapi-ts-swr/src/client/swr.gen.ts index 0be659ac24..49db086e1f 100644 --- a/examples/openapi-ts-swr/src/client/swr.gen.ts +++ b/examples/openapi-ts-swr/src/client/swr.gen.ts @@ -52,7 +52,7 @@ import type { */ export const addPetMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string], + _key: string[], { arg, }: { @@ -76,7 +76,7 @@ export const addPetMutation = (options?: Options) => ({ */ export const updatePetMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string], + _key: string[], { arg, }: { @@ -140,7 +140,7 @@ export const findPetsByTagsOptions = ( */ export const deletePetMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string] | readonly [string, Options], + _key: string[] | [string, Options], { arg, }: { @@ -184,7 +184,7 @@ export const updatePetWithFormMutation = ( options?: Options, ) => ({ fetcher: async ( - _key: readonly [string] | readonly [string, Options], + _key: string[] | [string, Options], { arg, }: { @@ -208,7 +208,7 @@ export const updatePetWithFormMutation = ( */ export const uploadFileMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string] | readonly [string, Options], + _key: string[] | [string, Options], { arg, }: { @@ -251,7 +251,7 @@ export const getInventoryOptions = (options?: Options) => ({ */ export const placeOrderMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string], + _key: string[], { arg, }: { @@ -275,7 +275,7 @@ export const placeOrderMutation = (options?: Options) => ({ */ export const deleteOrderMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string] | readonly [string, Options], + _key: string[] | [string, Options], { arg, }: { @@ -319,7 +319,7 @@ export const getOrderByIdOptions = (options: Options) => ({ */ export const createUserMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string], + _key: string[], { arg, }: { @@ -345,7 +345,7 @@ export const createUsersWithListInputMutation = ( options?: Options, ) => ({ fetcher: async ( - _key: readonly [string], + _key: string[], { arg, }: { @@ -404,7 +404,7 @@ export const logoutUserOptions = (options?: Options) => ({ */ export const deleteUserMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string] | readonly [string, Options], + _key: string[] | [string, Options], { arg, }: { @@ -446,7 +446,7 @@ export const getUserByNameOptions = (options: Options) => ({ */ export const updateUserMutation = (options?: Options) => ({ fetcher: async ( - _key: readonly [string] | readonly [string, Options], + _key: string[] | [string, Options], { arg, }: { diff --git a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/@tanstack/angular-query-experimental.gen.ts b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/@tanstack/angular-query-experimental.gen.ts index 4952a1ddf8..649e687fe0 100644 --- a/examples/openapi-ts-tanstack-angular-query-experimental/src/client/@tanstack/angular-query-experimental.gen.ts +++ b/examples/openapi-ts-tanstack-angular-query-experimental/src/client/@tanstack/angular-query-experimental.gen.ts @@ -40,12 +40,19 @@ import type { DeletePetData, DeleteUserData, FindPetsByStatusData, + FindPetsByStatusResponse, FindPetsByTagsData, + FindPetsByTagsResponse, GetInventoryData, + GetInventoryResponse, GetOrderByIdData, + GetOrderByIdResponse, GetPetByIdData, + GetPetByIdResponse, GetUserByNameData, + GetUserByNameResponse, LoginUserData, + LoginUserResponse, LogoutUserData, PlaceOrderData, PlaceOrderResponse, @@ -160,7 +167,12 @@ export const findPetsByStatusQueryKey = ( export const findPetsByStatusOptions = ( options: Options, ) => - queryOptions({ + queryOptions< + FindPetsByStatusResponse, + DefaultError, + FindPetsByStatusResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByStatus({ ...options, @@ -182,7 +194,12 @@ export const findPetsByTagsQueryKey = (options: Options) => * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTagsOptions = (options: Options) => - queryOptions({ + queryOptions< + FindPetsByTagsResponse, + DefaultError, + FindPetsByTagsResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByTags({ ...options, @@ -229,7 +246,12 @@ export const getPetByIdQueryKey = (options: Options) => * Returns a single pet. */ export const getPetByIdOptions = (options: Options) => - queryOptions({ + queryOptions< + GetPetByIdResponse, + DefaultError, + GetPetByIdResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getPetById({ ...options, @@ -309,7 +331,12 @@ export const getInventoryQueryKey = (options?: Options) => * Returns a map of status codes to quantities. */ export const getInventoryOptions = (options?: Options) => - queryOptions({ + queryOptions< + GetInventoryResponse, + DefaultError, + GetInventoryResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getInventory({ ...options, @@ -385,7 +412,12 @@ export const getOrderByIdQueryKey = (options: Options) => * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderByIdOptions = (options: Options) => - queryOptions({ + queryOptions< + GetOrderByIdResponse, + DefaultError, + GetOrderByIdResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getOrderById({ ...options, @@ -465,7 +497,12 @@ export const loginUserQueryKey = (options?: Options) => * Log into the system. */ export const loginUserOptions = (options?: Options) => - queryOptions({ + queryOptions< + LoginUserResponse, + DefaultError, + LoginUserResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await loginUser({ ...options, @@ -487,7 +524,12 @@ export const logoutUserQueryKey = (options?: Options) => * Log user out of the system. */ export const logoutUserOptions = (options?: Options) => - queryOptions({ + queryOptions< + unknown, + DefaultError, + unknown, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await logoutUser({ ...options, @@ -534,7 +576,12 @@ export const getUserByNameQueryKey = (options: Options) => * Get user detail based on username. */ export const getUserByNameOptions = (options: Options) => - queryOptions({ + queryOptions< + GetUserByNameResponse, + DefaultError, + GetUserByNameResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserByName({ ...options, diff --git a/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts b/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts index d0b4d2452c..5a87162c2c 100644 --- a/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts +++ b/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts @@ -19,12 +19,19 @@ import type { DeletePetData, DeleteUserData, FindPetsByStatusData, + FindPetsByStatusResponse, FindPetsByTagsData, + FindPetsByTagsResponse, GetInventoryData, + GetInventoryResponse, GetOrderByIdData, + GetOrderByIdResponse, GetPetByIdData, + GetPetByIdResponse, GetUserByNameData, + GetUserByNameResponse, LoginUserData, + LoginUserResponse, LogoutUserData, PlaceOrderData, PlaceOrderResponse, @@ -143,7 +150,12 @@ export const findPetsByStatusQueryKey = ( export const findPetsByStatusOptions = ( options: Options, ) => - queryOptions({ + queryOptions< + FindPetsByStatusResponse, + DefaultError, + FindPetsByStatusResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().findPetsByStatus({ ...options, @@ -165,7 +177,12 @@ export const findPetsByTagsQueryKey = (options: Options) => * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTagsOptions = (options: Options) => - queryOptions({ + queryOptions< + FindPetsByTagsResponse, + DefaultError, + FindPetsByTagsResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().findPetsByTags({ ...options, @@ -212,7 +229,12 @@ export const getPetByIdQueryKey = (options: Options) => * Returns a single pet. */ export const getPetByIdOptions = (options: Options) => - queryOptions({ + queryOptions< + GetPetByIdResponse, + DefaultError, + GetPetByIdResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().getPetById({ ...options, @@ -292,7 +314,12 @@ export const getInventoryQueryKey = (options?: Options) => * Returns a map of status codes to quantities. */ export const getInventoryOptions = (options?: Options) => - queryOptions({ + queryOptions< + GetInventoryResponse, + DefaultError, + GetInventoryResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().getInventory({ ...options, @@ -368,7 +395,12 @@ export const getOrderByIdQueryKey = (options: Options) => * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderByIdOptions = (options: Options) => - queryOptions({ + queryOptions< + GetOrderByIdResponse, + DefaultError, + GetOrderByIdResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().getOrderById({ ...options, @@ -448,7 +480,12 @@ export const loginUserQueryKey = (options?: Options) => * Log into the system. */ export const loginUserOptions = (options?: Options) => - queryOptions({ + queryOptions< + LoginUserResponse, + DefaultError, + LoginUserResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().loginUser({ ...options, @@ -470,7 +507,12 @@ export const logoutUserQueryKey = (options?: Options) => * Log user out of the system. */ export const logoutUserOptions = (options?: Options) => - queryOptions({ + queryOptions< + unknown, + DefaultError, + unknown, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().logoutUser({ ...options, @@ -517,7 +559,12 @@ export const getUserByNameQueryKey = (options: Options) => * Get user detail based on username. */ export const getUserByNameOptions = (options: Options) => - queryOptions({ + queryOptions< + GetUserByNameResponse, + DefaultError, + GetUserByNameResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await Sdk.__registry.get().getUserByName({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts b/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts index e9fe1844e5..212844409e 100644 --- a/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts +++ b/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts @@ -40,12 +40,19 @@ import type { DeletePetData, DeleteUserData, FindPetsByStatusData, + FindPetsByStatusResponse, FindPetsByTagsData, + FindPetsByTagsResponse, GetInventoryData, + GetInventoryResponse, GetOrderByIdData, + GetOrderByIdResponse, GetPetByIdData, + GetPetByIdResponse, GetUserByNameData, + GetUserByNameResponse, LoginUserData, + LoginUserResponse, LogoutUserData, PlaceOrderData, PlaceOrderResponse, @@ -160,7 +167,12 @@ export const findPetsByStatusQueryKey = ( export const findPetsByStatusOptions = ( options: Options, ) => - queryOptions({ + queryOptions< + FindPetsByStatusResponse, + DefaultError, + FindPetsByStatusResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByStatus({ ...options, @@ -182,7 +194,12 @@ export const findPetsByTagsQueryKey = (options: Options) => * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTagsOptions = (options: Options) => - queryOptions({ + queryOptions< + FindPetsByTagsResponse, + DefaultError, + FindPetsByTagsResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByTags({ ...options, @@ -229,7 +246,12 @@ export const getPetByIdQueryKey = (options: Options) => * Returns a single pet. */ export const getPetByIdOptions = (options: Options) => - queryOptions({ + queryOptions< + GetPetByIdResponse, + DefaultError, + GetPetByIdResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getPetById({ ...options, @@ -309,7 +331,12 @@ export const getInventoryQueryKey = (options?: Options) => * Returns a map of status codes to quantities. */ export const getInventoryOptions = (options?: Options) => - queryOptions({ + queryOptions< + GetInventoryResponse, + DefaultError, + GetInventoryResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getInventory({ ...options, @@ -385,7 +412,12 @@ export const getOrderByIdQueryKey = (options: Options) => * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderByIdOptions = (options: Options) => - queryOptions({ + queryOptions< + GetOrderByIdResponse, + DefaultError, + GetOrderByIdResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getOrderById({ ...options, @@ -465,7 +497,12 @@ export const loginUserQueryKey = (options?: Options) => * Log into the system. */ export const loginUserOptions = (options?: Options) => - queryOptions({ + queryOptions< + LoginUserResponse, + DefaultError, + LoginUserResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await loginUser({ ...options, @@ -487,7 +524,12 @@ export const logoutUserQueryKey = (options?: Options) => * Log user out of the system. */ export const logoutUserOptions = (options?: Options) => - queryOptions({ + queryOptions< + unknown, + DefaultError, + unknown, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await logoutUser({ ...options, @@ -534,7 +576,12 @@ export const getUserByNameQueryKey = (options: Options) => * Get user detail based on username. */ export const getUserByNameOptions = (options: Options) => - queryOptions({ + queryOptions< + GetUserByNameResponse, + DefaultError, + GetUserByNameResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserByName({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts b/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts index 9050f1d24e..d3fcf6469b 100644 --- a/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts +++ b/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts @@ -36,12 +36,19 @@ import type { DeletePetData, DeleteUserData, FindPetsByStatusData, + FindPetsByStatusResponse, FindPetsByTagsData, + FindPetsByTagsResponse, GetInventoryData, + GetInventoryResponse, GetOrderByIdData, + GetOrderByIdResponse, GetPetByIdData, + GetPetByIdResponse, GetUserByNameData, + GetUserByNameResponse, LoginUserData, + LoginUserResponse, LogoutUserData, PlaceOrderData, PlaceOrderResponse, @@ -148,7 +155,12 @@ export const findPetsByStatusQueryKey = (options: Options) * Multiple status values can be provided with comma separated strings. */ export const findPetsByStatusOptions = (options: Options) => - queryOptions({ + queryOptions< + FindPetsByStatusResponse, + DefaultError, + FindPetsByStatusResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByStatus({ ...options, @@ -170,7 +182,12 @@ export const findPetsByTagsQueryKey = (options: Options) => * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTagsOptions = (options: Options) => - queryOptions({ + queryOptions< + FindPetsByTagsResponse, + DefaultError, + FindPetsByTagsResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await findPetsByTags({ ...options, @@ -213,7 +230,12 @@ export const getPetByIdQueryKey = (options: Options) => * Returns a single pet. */ export const getPetByIdOptions = (options: Options) => - queryOptions({ + queryOptions< + GetPetByIdResponse, + DefaultError, + GetPetByIdResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getPetById({ ...options, @@ -285,7 +307,12 @@ export const getInventoryQueryKey = (options?: Options) => * Returns a map of status codes to quantities. */ export const getInventoryOptions = (options?: Options) => - queryOptions({ + queryOptions< + GetInventoryResponse, + DefaultError, + GetInventoryResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getInventory({ ...options, @@ -353,7 +380,12 @@ export const getOrderByIdQueryKey = (options: Options) => * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderByIdOptions = (options: Options) => - queryOptions({ + queryOptions< + GetOrderByIdResponse, + DefaultError, + GetOrderByIdResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getOrderById({ ...options, @@ -429,7 +461,12 @@ export const loginUserQueryKey = (options?: Options) => * Log into the system. */ export const loginUserOptions = (options?: Options) => - queryOptions({ + queryOptions< + LoginUserResponse, + DefaultError, + LoginUserResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await loginUser({ ...options, @@ -451,7 +488,7 @@ export const logoutUserQueryKey = (options?: Options) => * Log user out of the system. */ export const logoutUserOptions = (options?: Options) => - queryOptions({ + queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await logoutUser({ ...options, @@ -494,7 +531,12 @@ export const getUserByNameQueryKey = (options: Options) => * Get user detail based on username. */ export const getUserByNameOptions = (options: Options) => - queryOptions({ + queryOptions< + GetUserByNameResponse, + DefaultError, + GetUserByNameResponse, + ReturnType + >({ queryFn: async ({ queryKey, signal }) => { const { data } = await getUserByName({ ...options, 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 4a4fc4648f..00dbae3997 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 @@ -85,7 +85,35 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request) + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts index a491c1e2b9..989426b607 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts index 9b800726df..c35157d7b4 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts index 3d165eaeb4..b9dd742469 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts index 2fdb9367d3..72609d6756 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts index 8cd7a3e782..feeb508864 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts index 68d5f06972..a7bbd46cc9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts index ce3cedd56b..49fec971b1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts index 281ee050f2..a2dc5d5d6b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts index c814b6d71f..7b5bf27b84 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts index e0b08cf3ea..54b8e3aaa0 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts index 83cb27ffeb..b1c4100d14 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts index 3be3759576..f84e2391b7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts index c9714c3f59..4d282459c3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts index f44ae821e4..76da712c3e 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts index 539e65d77d..2fb721a74a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts index 37ba67e52c..9a52baa3d2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts index f8de70fdfd..c9065f58eb 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts index 5dd9b0efa8..4fb5f51271 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -99,9 +99,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -198,9 +198,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -255,9 +255,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -298,9 +298,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -313,9 +313,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -328,9 +328,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -343,9 +343,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -358,9 +358,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -401,9 +401,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -416,9 +416,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -431,9 +431,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts index 5bd7ed1f8d..f75a32be96 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst 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, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, FooWowData, GetCallWithoutParametersAndResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionBodyData, PostApiVbyApiVersionBodyError, PostApiVbyApiVersionBodyResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, ServiceWithEmptyTagData, TestErrorCodeData, TypesData } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey('serviceWithEmptyTag', options); +export const serviceWithEmptyTagQueryKey = (options?: Options) => createQueryKey("serviceWithEmptyTag", options); -export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions({ +export const serviceWithEmptyTagOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await serviceWithEmptyTag({ ...options, @@ -98,9 +98,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -197,9 +197,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -254,9 +254,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -297,9 +297,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -312,9 +312,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -327,9 +327,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -342,9 +342,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -357,9 +357,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -400,9 +400,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -415,9 +415,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -430,9 +430,9 @@ export const typesOptions = (options: Options) => queryOptions({ queryKey: typesQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts index 55533a5d74..ffb75dcd0f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts index df351d6b75..33cb83c8c5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts @@ -18,7 +18,7 @@ export const getFooOptions = (options?: Options) => ({ export const fooPostMutation = (options?: Options) => ({ key: ["/foo"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.post({ @@ -32,7 +32,7 @@ export const fooPostMutation = (options?: Options) => ({ export const fooPutMutation = (options?: Options) => ({ key: ["/foo"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.put({ @@ -56,7 +56,7 @@ export const getFooBarOptions = (options?: Options) => ({ export const fooBarPostMutation = (options?: Options) => ({ key: ["/foo/bar"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.barService.post({ @@ -70,7 +70,7 @@ export const fooBarPostMutation = (options?: Options) => ({ export const fooBarPutMutation = (options?: Options) => ({ key: ["/foo/bar"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.barService.put({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts index 122e577b6a..0f2638aa18 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts @@ -18,7 +18,7 @@ export const serviceWithEmptyTagOptions = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchApiVbyApiVersionNoTag({ @@ -32,7 +32,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await fooWow({ @@ -46,7 +46,7 @@ export const fooWowMutation = (options?: Options) => ({ export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deleteCallWithoutParametersAndResponse({ @@ -70,7 +70,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchCallWithoutParametersAndResponse({ @@ -84,7 +84,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Options< export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await postCallWithoutParametersAndResponse({ @@ -98,7 +98,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Options

) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putCallWithoutParametersAndResponse({ @@ -112,7 +112,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/descriptions/", options] : ["/api/v{api-version}/descriptions/"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDescriptions({ @@ -126,7 +126,7 @@ export const callWithDescriptionsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithParameters({ @@ -140,7 +140,7 @@ export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithWeirdParameterNames({ @@ -164,7 +164,7 @@ export const callWithDefaultParametersOptions = (options: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDefaultOptionalParameters({ @@ -178,7 +178,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callToTestOrderOfParams({ @@ -192,7 +192,7 @@ export const callToTestOrderOfParamsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName({ @@ -216,7 +216,7 @@ export const duplicateName2Options = (options?: Options) => export const duplicateName3Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName3({ @@ -230,7 +230,7 @@ export const duplicateName3Mutation = (options?: Options) => export const duplicateName4Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName4({ @@ -294,7 +294,7 @@ export const callWithResponseOptions = (options?: Options) export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithDuplicateResponses({ @@ -308,7 +308,7 @@ export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResponses({ @@ -352,7 +352,7 @@ export const complexTypesOptions = (options: Options) => ({ export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: ["/api/v{api-version}/header"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResultFromHeader({ @@ -366,7 +366,7 @@ export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await testErrorCode({ @@ -380,7 +380,7 @@ export const testErrorCodeMutation = (options?: Options) => ( export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ @@ -399,7 +399,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options< */ export const postApiVbyApiVersionBodyMutation = (options?: Options) => ({ key: ["/api/v{api-version}/body"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionBody({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts index 122e577b6a..0f2638aa18 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts @@ -18,7 +18,7 @@ export const serviceWithEmptyTagOptions = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchApiVbyApiVersionNoTag({ @@ -32,7 +32,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await fooWow({ @@ -46,7 +46,7 @@ export const fooWowMutation = (options?: Options) => ({ export const deleteCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deleteCallWithoutParametersAndResponse({ @@ -70,7 +70,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchCallWithoutParametersAndResponse({ @@ -84,7 +84,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Options< export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await postCallWithoutParametersAndResponse({ @@ -98,7 +98,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Options

) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putCallWithoutParametersAndResponse({ @@ -112,7 +112,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/descriptions/", options] : ["/api/v{api-version}/descriptions/"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDescriptions({ @@ -126,7 +126,7 @@ export const callWithDescriptionsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithParameters({ @@ -140,7 +140,7 @@ export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithWeirdParameterNames({ @@ -164,7 +164,7 @@ export const callWithDefaultParametersOptions = (options: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDefaultOptionalParameters({ @@ -178,7 +178,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callToTestOrderOfParams({ @@ -192,7 +192,7 @@ export const callToTestOrderOfParamsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName({ @@ -216,7 +216,7 @@ export const duplicateName2Options = (options?: Options) => export const duplicateName3Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName3({ @@ -230,7 +230,7 @@ export const duplicateName3Mutation = (options?: Options) => export const duplicateName4Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName4({ @@ -294,7 +294,7 @@ export const callWithResponseOptions = (options?: Options) export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithDuplicateResponses({ @@ -308,7 +308,7 @@ export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResponses({ @@ -352,7 +352,7 @@ export const complexTypesOptions = (options: Options) => ({ export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: ["/api/v{api-version}/header"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResultFromHeader({ @@ -366,7 +366,7 @@ export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await testErrorCode({ @@ -380,7 +380,7 @@ export const testErrorCodeMutation = (options?: Options) => ( export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ @@ -399,7 +399,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options< */ export const postApiVbyApiVersionBodyMutation = (options?: Options) => ({ key: ["/api/v{api-version}/body"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionBody({ 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/@tanstack/react-query.gen.ts index 2a8f02e3fe..8d60023d0d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/internal-name-conflict/@tanstack/react-query.gen.ts @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const createQueryKey2 = (options?: Options) => createQueryKey('create', options); +export const createQueryKey2 = (options?: Options) => createQueryKey("create", options); -export const createOptions = (options?: Options) => queryOptions({ +export const createOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await create({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts index a491c1e2b9..989426b607 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts index 40a544da1b..5e935efafd 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts index eddef04aa6..0eba11ced5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts index 2fdb9367d3..72609d6756 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts index 8cd7a3e782..feeb508864 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts index 79793a5bf9..efad5fa02d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts index 974c626917..a555bfe657 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOption 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts index 281ee050f2..a2dc5d5d6b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts index c814b6d71f..7b5bf27b84 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts index e6d59df49b..f123d6ac4a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts index 14c599f6e3..03778b370a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts index 3be3759576..f84e2391b7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts index c9714c3f59..4d282459c3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts index a583b98113..77ceb41bc6 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts index b5257d4cd9..007d99d464 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts index 37ba67e52c..9a52baa3d2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts index f8de70fdfd..c9065f58eb 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts index f14b579913..bf4850bf3c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts index 22e536b74d..673c3b95fe 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOption 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts index 55533a5d74..ffb75dcd0f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts index df351d6b75..33cb83c8c5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts @@ -18,7 +18,7 @@ export const getFooOptions = (options?: Options) => ({ export const fooPostMutation = (options?: Options) => ({ key: ["/foo"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.post({ @@ -32,7 +32,7 @@ export const fooPostMutation = (options?: Options) => ({ export const fooPutMutation = (options?: Options) => ({ key: ["/foo"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.put({ @@ -56,7 +56,7 @@ export const getFooBarOptions = (options?: Options) => ({ export const fooBarPostMutation = (options?: Options) => ({ key: ["/foo/bar"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.barService.post({ @@ -70,7 +70,7 @@ export const fooBarPostMutation = (options?: Options) => ({ export const fooBarPutMutation = (options?: Options) => ({ key: ["/foo/bar"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.barService.put({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts index 0596eef0ce..60cc8a124f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts @@ -18,7 +18,7 @@ export const exportOptions = (options?: Options) => ({ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchApiVbyApiVersionNoTag({ @@ -32,7 +32,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await import_({ @@ -46,7 +46,7 @@ export const importMutation = (options?: Options) => ({ export const fooWowMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await fooWow({ @@ -80,7 +80,7 @@ export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deleteCallWithoutParametersAndResponse({ @@ -104,7 +104,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchCallWithoutParametersAndResponse({ @@ -118,7 +118,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Options< export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await postCallWithoutParametersAndResponse({ @@ -132,7 +132,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Options

) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putCallWithoutParametersAndResponse({ @@ -146,7 +146,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}", options] : ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await deleteFoo({ @@ -160,7 +160,7 @@ export const deleteFooMutation = (options?: Options) => ({ export const callWithDescriptionsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/descriptions", options] : ["/api/v{api-version}/descriptions"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDescriptions({ @@ -177,7 +177,7 @@ export const callWithDescriptionsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/parameters/deprecated"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deprecatedCall({ @@ -191,7 +191,7 @@ export const deprecatedCallMutation = (options?: Options) => export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithParameters({ @@ -205,7 +205,7 @@ export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithWeirdParameterNames({ @@ -237,7 +237,7 @@ export const getCallWithOptionalParamInfinite = (options: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters", options] : ["/api/v{api-version}/parameters"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postCallWithOptionalParam({ @@ -251,7 +251,7 @@ export const postCallWithOptionalParamMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/requestBody", options] : ["/api/v{api-version}/requestBody"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionRequestBody({ @@ -265,7 +265,7 @@ export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/formData", options] : ["/api/v{api-version}/formData"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionFormData({ @@ -289,7 +289,7 @@ export const callWithDefaultParametersOptions = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDefaultOptionalParameters({ @@ -303,7 +303,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callToTestOrderOfParams({ @@ -317,7 +317,7 @@ export const callToTestOrderOfParamsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName({ @@ -341,7 +341,7 @@ export const duplicateName2Options = (options?: Options) => export const duplicateName3Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName3({ @@ -355,7 +355,7 @@ export const duplicateName3Mutation = (options?: Options) => export const duplicateName4Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName4({ @@ -419,7 +419,7 @@ export const callWithResponseOptions = (options?: Options) export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithDuplicateResponses({ @@ -433,7 +433,7 @@ export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResponses({ @@ -467,7 +467,7 @@ export const typesOptions = (options: Options) => ({ export const uploadFileMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/upload", options] : ["/api/v{api-version}/upload"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await uploadFile({ @@ -511,7 +511,7 @@ export const multipartResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/multipart"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await multipartRequest({ @@ -525,7 +525,7 @@ export const multipartRequestMutation = (options?: Options export const complexParamsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/complex/{id}", options] : ["/api/v{api-version}/complex/{id}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await complexParams({ @@ -539,7 +539,7 @@ export const complexParamsMutation = (options?: Options) => ( export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: ["/api/v{api-version}/header"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResultFromHeader({ @@ -553,7 +553,7 @@ export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await testErrorCode({ @@ -567,7 +567,7 @@ export const testErrorCodeMutation = (options?: Options) => ( export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ @@ -584,7 +584,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options< */ export const putWithFormUrlEncodedMutation = (options?: Options) => ({ key: ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putWithFormUrlEncoded({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts index 0596eef0ce..60cc8a124f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts @@ -18,7 +18,7 @@ export const exportOptions = (options?: Options) => ({ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchApiVbyApiVersionNoTag({ @@ -32,7 +32,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await import_({ @@ -46,7 +46,7 @@ export const importMutation = (options?: Options) => ({ export const fooWowMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await fooWow({ @@ -80,7 +80,7 @@ export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deleteCallWithoutParametersAndResponse({ @@ -104,7 +104,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchCallWithoutParametersAndResponse({ @@ -118,7 +118,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Options< export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await postCallWithoutParametersAndResponse({ @@ -132,7 +132,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Options

) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putCallWithoutParametersAndResponse({ @@ -146,7 +146,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}", options] : ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await deleteFoo({ @@ -160,7 +160,7 @@ export const deleteFooMutation = (options?: Options) => ({ export const callWithDescriptionsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/descriptions", options] : ["/api/v{api-version}/descriptions"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDescriptions({ @@ -177,7 +177,7 @@ export const callWithDescriptionsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/parameters/deprecated"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deprecatedCall({ @@ -191,7 +191,7 @@ export const deprecatedCallMutation = (options?: Options) => export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithParameters({ @@ -205,7 +205,7 @@ export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithWeirdParameterNames({ @@ -237,7 +237,7 @@ export const getCallWithOptionalParamInfinite = (options: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters", options] : ["/api/v{api-version}/parameters"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postCallWithOptionalParam({ @@ -251,7 +251,7 @@ export const postCallWithOptionalParamMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/requestBody", options] : ["/api/v{api-version}/requestBody"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionRequestBody({ @@ -265,7 +265,7 @@ export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/formData", options] : ["/api/v{api-version}/formData"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionFormData({ @@ -289,7 +289,7 @@ export const callWithDefaultParametersOptions = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDefaultOptionalParameters({ @@ -303,7 +303,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callToTestOrderOfParams({ @@ -317,7 +317,7 @@ export const callToTestOrderOfParamsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName({ @@ -341,7 +341,7 @@ export const duplicateName2Options = (options?: Options) => export const duplicateName3Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName3({ @@ -355,7 +355,7 @@ export const duplicateName3Mutation = (options?: Options) => export const duplicateName4Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName4({ @@ -419,7 +419,7 @@ export const callWithResponseOptions = (options?: Options) export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithDuplicateResponses({ @@ -433,7 +433,7 @@ export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResponses({ @@ -467,7 +467,7 @@ export const typesOptions = (options: Options) => ({ export const uploadFileMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/upload", options] : ["/api/v{api-version}/upload"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await uploadFile({ @@ -511,7 +511,7 @@ export const multipartResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/multipart"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await multipartRequest({ @@ -525,7 +525,7 @@ export const multipartRequestMutation = (options?: Options export const complexParamsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/complex/{id}", options] : ["/api/v{api-version}/complex/{id}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await complexParams({ @@ -539,7 +539,7 @@ export const complexParamsMutation = (options?: Options) => ( export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: ["/api/v{api-version}/header"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResultFromHeader({ @@ -553,7 +553,7 @@ export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await testErrorCode({ @@ -567,7 +567,7 @@ export const testErrorCodeMutation = (options?: Options) => ( export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ @@ -584,7 +584,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options< */ export const putWithFormUrlEncodedMutation = (options?: Options) => ({ key: ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putWithFormUrlEncoded({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts index 218d9f214a..cd348f8548 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts @@ -412,13 +412,13 @@ export const vModelSquare = v.object({ export const vCompositionWithOneOfDiscriminator = v.union([ v.intersect([ v.object({ - kind: v.literal('circle') + kind: v.literal("circle") }), vModelCircle ]), v.intersect([ v.object({ - kind: v.literal('square') + kind: v.literal("square") }), vModelSquare ]) 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 62806c6c47..8715da997d 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 67961302b0..0e4f3174bd 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/@tanstack/react-query.gen.ts index 2a8f02e3fe..8d60023d0d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/internal-name-conflict/@tanstack/react-query.gen.ts @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const createQueryKey2 = (options?: Options) => createQueryKey('create', options); +export const createQueryKey2 = (options?: Options) => createQueryKey("create", options); -export const createOptions = (options?: Options) => queryOptions({ +export const createOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await create({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts index c86d61d3c6..32b258b88c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/pagination-ref/@tanstack/react-query.gen.ts @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options: Options) => queryOptions({ +export const getFooOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -87,7 +87,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getFooInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getFoo', options, true); +export const getFooInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getFoo", options, true); export const getFooInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | null | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts index a491c1e2b9..989426b607 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/asClass/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts index 40a544da1b..5e935efafd 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/@tanstack/angular-query-experimental.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts index eddef04aa6..0eba11ced5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/fetch/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts index 2fdb9367d3..72609d6756 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/name-builder/@tanstack/angular-query-experimental.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts index 8cd7a3e782..feeb508864 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/asClass/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts index 79793a5bf9..efad5fa02d 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/@tanstack/react-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts index 974c626917..a555bfe657 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/fetch/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOption 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts index 281ee050f2..a2dc5d5d6b 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/name-builder/@tanstack/react-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts index c814b6d71f..7b5bf27b84 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/asClass/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts index e6d59df49b..f123d6ac4a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/@tanstack/solid-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts index 14c599f6e3..03778b370a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/fetch/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts index 3be3759576..f84e2391b7 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/name-builder/@tanstack/solid-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts index c9714c3f59..4d282459c3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/asClass/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts index a583b98113..77ceb41bc6 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/@tanstack/svelte-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts index b5257d4cd9..007d99d464 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/fetch/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, type Mutati 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): Mutation return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts index 37ba67e52c..9a52baa3d2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/name-builder/@tanstack/svelte-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type MutationOptions, queryOptions } from '@tanstack import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): MutationOptions return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts index f8de70fdfd..c9065f58eb 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/asClass/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { BarBazService, FooBazService, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await FooBazService.getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const getFooBarQueryKey = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarQueryKey = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarOptions = (options?: Options) => queryOptions({ +export const getFooBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await BarBazService.getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts index f14b579913..bf4850bf3c 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/@tanstack/vue-query.gen.ts @@ -5,7 +5,7 @@ import type { AxiosError } from 'axios'; 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -42,9 +42,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -99,9 +99,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions, ApiVVersionODataControllerCountResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -114,9 +114,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions, GetApiVbyApiVersionSimpleOperationResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -143,9 +143,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -273,9 +273,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -319,7 +319,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, InfiniteData, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -387,9 +387,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -444,9 +444,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -487,9 +487,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions, CallWithNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -502,9 +502,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions, CallWithResponseAndNoContentResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -517,9 +517,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions, DummyAResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -532,9 +532,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions, DummyBResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -547,9 +547,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions, CallWithResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -590,9 +590,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions, unknown, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -605,9 +605,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions, TypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -634,9 +634,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions, FileResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -649,9 +649,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions, ComplexTypesResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -664,9 +664,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions, MultipartResponseResponse, ReturnType>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts index 22e536b74d..673c3b95fe 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/fetch/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, type InfiniteData, infiniteQueryOptions, queryOption 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, CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData, CallWithDefaultParametersData, CallWithDescriptionsData, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithNoContentResponseData, CallWithParametersData, CallWithResponseAndNoContentResponseData, CallWithResponseData, CallWithResponsesData, CallWithResponsesError, CallWithResponsesResponse, CallWithResultFromHeaderData, CallWithWeirdParameterNamesData, CollectionFormatData, ComplexParamsData, ComplexParamsResponse, ComplexTypesData, DeleteCallWithoutParametersAndResponseData, DeleteFooData3, DeprecatedCallData, DummyAData, DummyBData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, DuplicateNameData, ExportData, FileResponseData, FooWowData, GetApiVbyApiVersionSimpleOperationData, GetCallWithOptionalParamData, GetCallWithoutParametersAndResponseData, ImportData, ImportResponse, MultipartRequestData, MultipartResponseData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PatchApiVbyApiVersionNoTagData, PatchCallWithoutParametersAndResponseData, PostApiVbyApiVersionFormDataData, PostApiVbyApiVersionRequestBodyData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, PutWithFormUrlEncodedData, TestErrorCodeData, TypesData, UploadFileData, UploadFileResponse } from '../types.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 & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const exportQueryKey = (options?: Options) => createQueryKey('export', options); +export const exportQueryKey = (options?: Options) => createQueryKey("export", options); -export const exportOptions = (options?: Options) => queryOptions({ +export const exportOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await export_({ ...options, @@ -98,9 +98,9 @@ export const fooWowMutation = (options?: Partial>): UseMutat return mutationOptions; }; -export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey('apiVVersionODataControllerCount', options); +export const apiVVersionODataControllerCountQueryKey = (options?: Options) => createQueryKey("apiVVersionODataControllerCount", options); -export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions({ +export const apiVVersionODataControllerCountOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await apiVVersionODataControllerCount({ ...options, @@ -113,9 +113,9 @@ export const apiVVersionODataControllerCountOptions = (options?: Options) => createQueryKey('getApiVbyApiVersionSimpleOperation', options); +export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options) => createQueryKey("getApiVbyApiVersionSimpleOperation", options); -export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions({ +export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getApiVbyApiVersionSimpleOperation({ ...options, @@ -142,9 +142,9 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Partial return mutationOptions; }; -export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('getCallWithoutParametersAndResponse', options); +export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey("getCallWithoutParametersAndResponse", options); -export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions({ +export const getCallWithoutParametersAndResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithoutParametersAndResponse({ ...options, @@ -272,9 +272,9 @@ export const callWithWeirdParameterNamesMutation = (options?: Partial) => createQueryKey('getCallWithOptionalParam', options); +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey("getCallWithOptionalParam", options); -export const getCallWithOptionalParamOptions = (options: Options) => queryOptions({ +export const getCallWithOptionalParamOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getCallWithOptionalParam({ ...options, @@ -318,7 +318,7 @@ const createInfiniteParams = [0], 'body' | 'hea return params as unknown as typeof page; }; -export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); +export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey("getCallWithOptionalParam", options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { return infiniteQueryOptions, QueryKey>, number | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( @@ -386,9 +386,9 @@ export const postApiVbyApiVersionFormDataMutation = (options?: Partial) => createQueryKey('callWithDefaultParameters', options); +export const callWithDefaultParametersQueryKey = (options?: Options) => createQueryKey("callWithDefaultParameters", options); -export const callWithDefaultParametersOptions = (options?: Options) => queryOptions({ +export const callWithDefaultParametersOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithDefaultParameters({ ...options, @@ -443,9 +443,9 @@ export const duplicateNameMutation = (options?: Partial) => createQueryKey('duplicateName2', options); +export const duplicateName2QueryKey = (options?: Options) => createQueryKey("duplicateName2", options); -export const duplicateName2Options = (options?: Options) => queryOptions({ +export const duplicateName2Options = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await duplicateName2({ ...options, @@ -486,9 +486,9 @@ export const duplicateName4Mutation = (options?: Partial) => createQueryKey('callWithNoContentResponse', options); +export const callWithNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithNoContentResponse", options); -export const callWithNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithNoContentResponse({ ...options, @@ -501,9 +501,9 @@ export const callWithNoContentResponseOptions = (options?: Options) => createQueryKey('callWithResponseAndNoContentResponse', options); +export const callWithResponseAndNoContentResponseQueryKey = (options?: Options) => createQueryKey("callWithResponseAndNoContentResponse", options); -export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseAndNoContentResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponseAndNoContentResponse({ ...options, @@ -516,9 +516,9 @@ export const callWithResponseAndNoContentResponseOptions = (options?: Options) => createQueryKey('dummyA', options); +export const dummyAQueryKey = (options?: Options) => createQueryKey("dummyA", options); -export const dummyAOptions = (options?: Options) => queryOptions({ +export const dummyAOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyA({ ...options, @@ -531,9 +531,9 @@ export const dummyAOptions = (options?: Options) => queryOptions({ queryKey: dummyAQueryKey(options) }); -export const dummyBQueryKey = (options?: Options) => createQueryKey('dummyB', options); +export const dummyBQueryKey = (options?: Options) => createQueryKey("dummyB", options); -export const dummyBOptions = (options?: Options) => queryOptions({ +export const dummyBOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await dummyB({ ...options, @@ -546,9 +546,9 @@ export const dummyBOptions = (options?: Options) => queryOptions({ queryKey: dummyBQueryKey(options) }); -export const callWithResponseQueryKey = (options?: Options) => createQueryKey('callWithResponse', options); +export const callWithResponseQueryKey = (options?: Options) => createQueryKey("callWithResponse", options); -export const callWithResponseOptions = (options?: Options) => queryOptions({ +export const callWithResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await callWithResponse({ ...options, @@ -589,9 +589,9 @@ export const callWithResponsesMutation = (options?: Partial) => createQueryKey('collectionFormat', options); +export const collectionFormatQueryKey = (options: Options) => createQueryKey("collectionFormat", options); -export const collectionFormatOptions = (options: Options) => queryOptions({ +export const collectionFormatOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await collectionFormat({ ...options, @@ -604,9 +604,9 @@ export const collectionFormatOptions = (options: Options) queryKey: collectionFormatQueryKey(options) }); -export const typesQueryKey = (options: Options) => createQueryKey('types', options); +export const typesQueryKey = (options: Options) => createQueryKey("types", options); -export const typesOptions = (options: Options) => queryOptions({ +export const typesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await types({ ...options, @@ -633,9 +633,9 @@ export const uploadFileMutation = (options?: Partial>): return mutationOptions; }; -export const fileResponseQueryKey = (options: Options) => createQueryKey('fileResponse', options); +export const fileResponseQueryKey = (options: Options) => createQueryKey("fileResponse", options); -export const fileResponseOptions = (options: Options) => queryOptions({ +export const fileResponseOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await fileResponse({ ...options, @@ -648,9 +648,9 @@ export const fileResponseOptions = (options: Options) => query queryKey: fileResponseQueryKey(options) }); -export const complexTypesQueryKey = (options: Options) => createQueryKey('complexTypes', options); +export const complexTypesQueryKey = (options: Options) => createQueryKey("complexTypes", options); -export const complexTypesOptions = (options: Options) => queryOptions({ +export const complexTypesOptions = (options: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await complexTypes({ ...options, @@ -663,9 +663,9 @@ export const complexTypesOptions = (options: Options) => query queryKey: complexTypesQueryKey(options) }); -export const multipartResponseQueryKey = (options?: Options) => createQueryKey('multipartResponse', options); +export const multipartResponseQueryKey = (options?: Options) => createQueryKey("multipartResponse", options); -export const multipartResponseOptions = (options?: Options) => queryOptions({ +export const multipartResponseOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await multipartResponse({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts index 55533a5d74..ffb75dcd0f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/name-builder/@tanstack/vue-query.gen.ts @@ -4,7 +4,7 @@ import { type DefaultError, queryOptions, type UseMutationOptions } from '@tanst import { client } from '../client.gen'; import { fooBarPost, fooBarPut, fooPost, fooPut, getFoo, getFooBar, type Options } from '../sdk.gen'; -import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooData } from '../types.gen'; +import type { FooBarPostData, FooBarPostResponse, FooBarPutData, FooBarPutResponse, FooPostData, FooPostResponse, FooPutData, FooPutResponse, GetFooBarData, GetFooBarResponse, GetFooData, GetFooResponse } from '../types.gen'; export type QueryKey = [ Pick & { @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooD = (options?: Options) => createQueryKey('getFoo', options); +export const getFooD = (options?: Options) => createQueryKey("getFoo", options); -export const getFooE = (options?: Options) => queryOptions({ +export const getFooE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -84,9 +84,9 @@ export const fooPutC = (options?: Partial>): UseMutationOpti return mutationOptions; }; -export const getFooBarD = (options?: Options) => createQueryKey('getFooBar', options); +export const getFooBarD = (options?: Options) => createQueryKey("getFooBar", options); -export const getFooBarE = (options?: Options) => queryOptions({ +export const getFooBarE = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFooBar({ ...options, 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts index df351d6b75..33cb83c8c5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts @@ -18,7 +18,7 @@ export const getFooOptions = (options?: Options) => ({ export const fooPostMutation = (options?: Options) => ({ key: ["/foo"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.post({ @@ -32,7 +32,7 @@ export const fooPostMutation = (options?: Options) => ({ export const fooPutMutation = (options?: Options) => ({ key: ["/foo"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.put({ @@ -56,7 +56,7 @@ export const getFooBarOptions = (options?: Options) => ({ export const fooBarPostMutation = (options?: Options) => ({ key: ["/foo/bar"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.barService.post({ @@ -70,7 +70,7 @@ export const fooBarPostMutation = (options?: Options) => ({ export const fooBarPutMutation = (options?: Options) => ({ key: ["/foo/bar"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await FooBazService.fooService.barService.put({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts index 0596eef0ce..60cc8a124f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts @@ -18,7 +18,7 @@ export const exportOptions = (options?: Options) => ({ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchApiVbyApiVersionNoTag({ @@ -32,7 +32,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await import_({ @@ -46,7 +46,7 @@ export const importMutation = (options?: Options) => ({ export const fooWowMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await fooWow({ @@ -80,7 +80,7 @@ export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deleteCallWithoutParametersAndResponse({ @@ -104,7 +104,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchCallWithoutParametersAndResponse({ @@ -118,7 +118,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Options< export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await postCallWithoutParametersAndResponse({ @@ -132,7 +132,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Options

) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putCallWithoutParametersAndResponse({ @@ -146,7 +146,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}", options] : ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await deleteFoo({ @@ -160,7 +160,7 @@ export const deleteFooMutation = (options?: Options) => ({ export const callWithDescriptionsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/descriptions", options] : ["/api/v{api-version}/descriptions"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDescriptions({ @@ -177,7 +177,7 @@ export const callWithDescriptionsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/parameters/deprecated"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deprecatedCall({ @@ -191,7 +191,7 @@ export const deprecatedCallMutation = (options?: Options) => export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithParameters({ @@ -205,7 +205,7 @@ export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithWeirdParameterNames({ @@ -237,7 +237,7 @@ export const getCallWithOptionalParamInfinite = (options: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters", options] : ["/api/v{api-version}/parameters"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postCallWithOptionalParam({ @@ -251,7 +251,7 @@ export const postCallWithOptionalParamMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/requestBody", options] : ["/api/v{api-version}/requestBody"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionRequestBody({ @@ -265,7 +265,7 @@ export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/formData", options] : ["/api/v{api-version}/formData"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionFormData({ @@ -289,7 +289,7 @@ export const callWithDefaultParametersOptions = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDefaultOptionalParameters({ @@ -303,7 +303,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callToTestOrderOfParams({ @@ -317,7 +317,7 @@ export const callToTestOrderOfParamsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName({ @@ -341,7 +341,7 @@ export const duplicateName2Options = (options?: Options) => export const duplicateName3Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName3({ @@ -355,7 +355,7 @@ export const duplicateName3Mutation = (options?: Options) => export const duplicateName4Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName4({ @@ -419,7 +419,7 @@ export const callWithResponseOptions = (options?: Options) export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithDuplicateResponses({ @@ -433,7 +433,7 @@ export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResponses({ @@ -467,7 +467,7 @@ export const typesOptions = (options: Options) => ({ export const uploadFileMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/upload", options] : ["/api/v{api-version}/upload"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await uploadFile({ @@ -511,7 +511,7 @@ export const multipartResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/multipart"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await multipartRequest({ @@ -525,7 +525,7 @@ export const multipartRequestMutation = (options?: Options export const complexParamsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/complex/{id}", options] : ["/api/v{api-version}/complex/{id}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await complexParams({ @@ -539,7 +539,7 @@ export const complexParamsMutation = (options?: Options) => ( export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: ["/api/v{api-version}/header"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResultFromHeader({ @@ -553,7 +553,7 @@ export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await testErrorCode({ @@ -567,7 +567,7 @@ export const testErrorCodeMutation = (options?: Options) => ( export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ @@ -584,7 +584,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options< */ export const putWithFormUrlEncodedMutation = (options?: Options) => ({ key: ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putWithFormUrlEncoded({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts index 0596eef0ce..60cc8a124f 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts @@ -18,7 +18,7 @@ export const exportOptions = (options?: Options) => ({ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchApiVbyApiVersionNoTag({ @@ -32,7 +32,7 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await import_({ @@ -46,7 +46,7 @@ export const importMutation = (options?: Options) => ({ export const fooWowMutation = (options?: Options) => ({ key: ["/api/v{api-version}/no+tag"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await fooWow({ @@ -80,7 +80,7 @@ export const getApiVbyApiVersionSimpleOperationOptions = (options: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deleteCallWithoutParametersAndResponse({ @@ -104,7 +104,7 @@ export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await patchCallWithoutParametersAndResponse({ @@ -118,7 +118,7 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Options< export const postCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await postCallWithoutParametersAndResponse({ @@ -132,7 +132,7 @@ export const postCallWithoutParametersAndResponseMutation = (options?: Options

) => ({ key: ["/api/v{api-version}/simple"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putCallWithoutParametersAndResponse({ @@ -146,7 +146,7 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}", options] : ["/api/v{api-version}/foo/{foo_param}/bar/{BarParam}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await deleteFoo({ @@ -160,7 +160,7 @@ export const deleteFooMutation = (options?: Options) => ({ export const callWithDescriptionsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/descriptions", options] : ["/api/v{api-version}/descriptions"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDescriptions({ @@ -177,7 +177,7 @@ export const callWithDescriptionsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/parameters/deprecated"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await deprecatedCall({ @@ -191,7 +191,7 @@ export const deprecatedCallMutation = (options?: Options) => export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameterPath}", options] : ["/api/v{api-version}/parameters/{parameterPath}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithParameters({ @@ -205,7 +205,7 @@ export const callWithParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}", options] : ["/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithWeirdParameterNames({ @@ -237,7 +237,7 @@ export const getCallWithOptionalParamInfinite = (options: Options) => ({ key: options?.path ? ["/api/v{api-version}/parameters", options] : ["/api/v{api-version}/parameters"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postCallWithOptionalParam({ @@ -251,7 +251,7 @@ export const postCallWithOptionalParamMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/requestBody", options] : ["/api/v{api-version}/requestBody"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionRequestBody({ @@ -265,7 +265,7 @@ export const postApiVbyApiVersionRequestBodyMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/formData", options] : ["/api/v{api-version}/formData"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await postApiVbyApiVersionFormData({ @@ -289,7 +289,7 @@ export const callWithDefaultParametersOptions = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callWithDefaultOptionalParameters({ @@ -303,7 +303,7 @@ export const callWithDefaultOptionalParametersMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/defaults", options] : ["/api/v{api-version}/defaults"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await callToTestOrderOfParams({ @@ -317,7 +317,7 @@ export const callToTestOrderOfParamsMutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName({ @@ -341,7 +341,7 @@ export const duplicateName2Options = (options?: Options) => export const duplicateName3Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName3({ @@ -355,7 +355,7 @@ export const duplicateName3Mutation = (options?: Options) => export const duplicateName4Mutation = (options?: Options) => ({ key: ["/api/v{api-version}/duplicate"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await duplicateName4({ @@ -419,7 +419,7 @@ export const callWithResponseOptions = (options?: Options) export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithDuplicateResponses({ @@ -433,7 +433,7 @@ export const callWithDuplicateResponsesMutation = (options?: Options) => ({ key: ["/api/v{api-version}/response"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResponses({ @@ -467,7 +467,7 @@ export const typesOptions = (options: Options) => ({ export const uploadFileMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/upload", options] : ["/api/v{api-version}/upload"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await uploadFile({ @@ -511,7 +511,7 @@ export const multipartResponseOptions = (options?: Options) => ({ key: ["/api/v{api-version}/multipart"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await multipartRequest({ @@ -525,7 +525,7 @@ export const multipartRequestMutation = (options?: Options export const complexParamsMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/complex/{id}", options] : ["/api/v{api-version}/complex/{id}"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await complexParams({ @@ -539,7 +539,7 @@ export const complexParamsMutation = (options?: Options) => ( export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: ["/api/v{api-version}/header"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await callWithResultFromHeader({ @@ -553,7 +553,7 @@ export const callWithResultFromHeaderMutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/error", options] : ["/api/v{api-version}/error"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await testErrorCode({ @@ -567,7 +567,7 @@ export const testErrorCodeMutation = (options?: Options) => ( export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options) => ({ key: options?.path ? ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串", options] : ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string] | readonly [string, Options], { arg }: { + fetcher: async (_key: string[] | [string, Options], { arg }: { arg: Options; }) => { const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ @@ -584,7 +584,7 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Options< */ export const putWithFormUrlEncodedMutation = (options?: Options) => ({ key: ["/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串"], - fetcher: async (_key: readonly [string], { arg }: { + fetcher: async (_key: string[], { arg }: { arg: Options; }) => { const { data } = await putWithFormUrlEncoded({ diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts index f754741b42..03aef51409 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts @@ -415,13 +415,13 @@ export const vModelSquare = v.object({ export const vCompositionWithOneOfDiscriminator = v.union([ v.intersect([ v.object({ - kind: v.literal('circle') + kind: v.literal("circle") }), vModelCircle ]), v.intersect([ v.object({ - kind: v.literal('square') + kind: v.literal("square") }), vModelSquare ]) @@ -467,7 +467,7 @@ export const v3eNum1Период = v.picklist([ 'Dog' ]); -export const vConstValue = v.literal('ConstValue'); +export const vConstValue = v.literal("ConstValue"); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -721,10 +721,10 @@ export const vFreeFormObjectWithAdditionalPropertiesEqTrue = v.record(v.string() export const vFreeFormObjectWithAdditionalPropertiesEqEmptyObject = v.record(v.string(), v.unknown()); export const vModelWithConst = v.object({ - String: v.optional(v.literal('String')), + String: v.optional(v.literal("String")), number: v.optional(v.literal(0)), null: v.optional(v.null()), - withType: v.optional(v.literal('Some string')) + withType: v.optional(v.literal("Some string")) }); /** @@ -1660,9 +1660,9 @@ export const vTypesData = v.object({ v.null() ]), parameterEnum: v.union([ - v.literal('Success'), - v.literal('Warning'), - v.literal('Error'), + v.literal("Success"), + v.literal("Warning"), + v.literal("Error"), v.null() ]) }) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/valibot.gen.ts index 9be77d3e92..0bf447745a 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/schema-const/valibot.gen.ts @@ -3,7 +3,7 @@ import * as v from 'valibot'; export const vFoo = v.object({ - foo: v.optional(v.literal('foo')), + foo: v.optional(v.literal("foo")), bar: v.optional(v.literal(3.2)), baz: v.optional(v.literal(-1)), qux: v.optional(v.literal(true)), 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts index 6a2d4fbcd1..cba06ee5b9 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/angular-query-experimental.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { queryOptions } from '@tanstack/angular-query-experimental'; +import { type DefaultError, queryOptions } from '@tanstack/angular-query-experimental'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions({ } }); -export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); +export const getBarQueryKey = (options?: Options) => createQueryKey("getBar", options); -export const getBarOptions = (options?: Options) => queryOptions({ +export const getBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts index 2e33891bbd..50907f7581 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/react-query.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { queryOptions } from '@tanstack/react-query'; +import { type DefaultError, queryOptions } from '@tanstack/react-query'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions({ } }); -export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); +export const getBarQueryKey = (options?: Options) => createQueryKey("getBar", options); -export const getBarOptions = (options?: Options) => queryOptions({ +export const getBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts index 1381ba00d4..46578d9342 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/solid-query.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { queryOptions } from '@tanstack/solid-query'; +import { type DefaultError, queryOptions } from '@tanstack/solid-query'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions({ } }); -export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); +export const getBarQueryKey = (options?: Options) => createQueryKey("getBar", options); -export const getBarOptions = (options?: Options) => queryOptions({ +export const getBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts index 66bc1ac937..547ff7d5e2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/svelte-query.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { queryOptions } from '@tanstack/svelte-query'; +import { type DefaultError, queryOptions } from '@tanstack/svelte-query'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions({ } }); -export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); +export const getBarQueryKey = (options?: Options) => createQueryKey("getBar", options); -export const getBarOptions = (options?: Options) => queryOptions({ +export const getBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts index 07549729e2..192793d585 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/@tanstack/vue-query.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -import { queryOptions } from '@tanstack/vue-query'; +import { type DefaultError, queryOptions } from '@tanstack/vue-query'; import { client } from '../client.gen'; import { getBar, getFoo, type Options } from '../sdk.gen'; @@ -41,9 +41,9 @@ const createQueryKey = (id: string, options?: TOptions ]; }; -export const getFooQueryKey = (options?: Options) => createQueryKey('getFoo', options); +export const getFooQueryKey = (options?: Options) => createQueryKey("getFoo", options); -export const getFooOptions = (options?: Options) => queryOptions({ +export const getFooOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getFoo({ ...options, @@ -61,9 +61,9 @@ export const getFooOptions = (options?: Options) => queryOptions({ } }); -export const getBarQueryKey = (options?: Options) => createQueryKey('getBar', options); +export const getBarQueryKey = (options?: Options) => createQueryKey("getBar", options); -export const getBarOptions = (options?: Options) => queryOptions({ +export const getBarOptions = (options?: Options) => queryOptions>({ queryFn: async ({ queryKey, signal }) => { const { data } = await getBar({ ...options, diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts index a439d2748f..c2a5190c22 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts b/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts index ef0ad17dc0..0c8a5bc1e4 100644 --- a/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts +++ b/packages/openapi-ts-tests/main/test/plugins/swr/basic-generation.test.ts @@ -142,13 +142,11 @@ describe('SWR Plugin Basic Generation', () => { // Verify mutation fetcher signature with _key and arg // _key is now typed as readonly [string] instead of unknown - expect(fileContent).toContain('_key: readonly [string]'); + expect(fileContent).toContain('_key: string[]'); expect(fileContent).toContain('{ arg }'); // Verify async fetcher for mutations with proper typing - expect(fileContent).toMatch( - /fetcher: async \(_key: readonly \[string\].*{ arg }/, - ); + expect(fileContent).toMatch(/fetcher: async \(_key: string\[\].*{ arg }/); // Verify key and fetcher structure expect(fileContent).toContain('key:'); 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { 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 a439d2748f..c2a5190c22 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 @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => { // 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 = await _fetch(request); + 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) { diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts index faa59eba03..31874e2bde 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts @@ -294,9 +294,7 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts index cc825b3254..4640f7e817 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts @@ -293,9 +293,7 @@ export const zModelWithDictionary = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => { - return zModelWithCircularReference; - }).optional() + prop: z.lazy(() => zModelWithCircularReference).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts index ccfbf6f309..cc726c6563 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts @@ -294,9 +294,7 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts index 9b3bf45710..56a3d829e1 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts @@ -4,43 +4,31 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => { - return zQuux; - })); + return z.optional(z.lazy((): any => zQuux)); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.lazy((): any => { - return zBaz; - })); + return z.optional(z.lazy((): any => zBaz)); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => { - return zQuux; - })); + return z.optional(z.lazy((): any => zQuux)); } }); export const zQux = z.union([ z.intersection(z.object({ - type: z.literal('struct') - }), z.lazy(() => { - return z.lazy((): any => { - return zCorge; - }); - })), + type: z.literal("struct") + }), z.lazy(() => z.lazy((): any => zCorge))), z.intersection(z.object({ - type: z.literal('array') + type: z.literal("array") }), zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts index 2195593a03..c99bdd0783 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -400,9 +400,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); @@ -452,10 +450,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.intersection(z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }), zModelCircle), z.intersection(z.object({ - kind: z.literal('square') + kind: z.literal("square") }), zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts index 9ef941af5b..cfa348c12d 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts @@ -8,14 +8,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts index bcce4d295c..da24dd9d8c 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts @@ -3,34 +3,24 @@ import { z } from 'zod'; export const zFoo: z.AnyZodObject = z.object({ - quux: z.lazy(() => { - return zQuux; - }).optional() + quux: z.lazy(() => zQuux).optional() }); export const zBar: z.AnyZodObject = z.object({ - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.lazy(() => { - return zBaz; - }).optional() + bar: z.lazy(() => zBar).optional(), + baz: z.lazy(() => zBaz).optional() }); export const zBaz: z.AnyZodObject = z.object({ - quux: z.lazy(() => { - return zQuux; - }).optional() + quux: z.lazy(() => zQuux).optional() }); export const zQux: z.ZodTypeAny = z.union([ z.object({ - type: z.literal('struct') - }).and(z.lazy(() => { - return zCorge; - })), + type: z.literal("struct") + }).and(z.lazy(() => zCorge)), z.object({ - type: z.literal('array') + type: z.literal("array") }).and(zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts index 5d788ebe50..f32143a782 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -399,9 +399,7 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => { - return zModelWithCircularReference; - }).optional() + prop: z.lazy(() => zModelWithCircularReference).optional() }); /** @@ -450,10 +448,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }).and(zModelCircle), z.object({ - kind: z.literal('square') + kind: z.literal("square") }).and(zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts index 13daadc5e5..9d727f32d0 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts @@ -7,12 +7,8 @@ export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts index 073c23da87..36cd58c4f3 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/circular/zod.gen.ts @@ -4,43 +4,31 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => { - return zQuux; - })); + return z.optional(z.lazy((): any => zQuux)); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.lazy((): any => { - return zBaz; - })); + return z.optional(z.lazy((): any => zBaz)); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => { - return zQuux; - })); + return z.optional(z.lazy((): any => zQuux)); } }); export const zQux = z.union([ z.object({ - type: z.literal('struct') - }).and(z.lazy(() => { - return z.lazy((): any => { - return zCorge; - }); - })), + type: z.literal("struct") + }).and(z.lazy(() => z.lazy((): any => zCorge))), z.object({ - type: z.literal('array') + type: z.literal("array") }).and(zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts index 3d5fb668b5..9c08491ec4 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -400,9 +400,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); @@ -452,10 +450,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }).and(zModelCircle), z.object({ - kind: z.literal('square') + kind: z.literal("square") }).and(zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts index 5299554543..0daf7a0a68 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts @@ -8,14 +8,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts index 2a97dcfe22..680e0829a8 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -403,9 +403,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); @@ -455,10 +453,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.intersection(z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }), zModelCircle), z.intersection(z.object({ - kind: z.literal('square') + kind: z.literal("square") }), zModelSquare) ]); @@ -508,7 +506,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal('ConstValue'); +export const zConstValue = z.literal("ConstValue"); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -753,10 +751,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.string() export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); export const zModelWithConst = z.object({ - String: z.optional(z.literal('String')), + String: z.optional(z.literal("String")), number: z.optional(z.literal(0)), null: z.optional(z.null()), - withType: z.optional(z.literal('Some string')) + withType: z.optional(z.literal("Some string")) }); /** @@ -1688,9 +1686,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal('Success'), - z.literal('Warning'), - z.literal('Error'), + z.literal("Success"), + z.literal("Warning"), + z.literal("Error"), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts index 10480c6a67..a314590d95 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ - foo: z.optional(z.literal('foo')), + foo: z.optional(z.literal("foo")), bar: z.optional(z.literal(3.2)), baz: z.optional(z.literal(-1)), qux: z.optional(z.literal(true)), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal('-9223372036854775808')), - stringUint64: z.optional(z.literal('18446744073709551615')) + stringInt64: z.optional(z.literal("-9223372036854775808")), + stringUint64: z.optional(z.literal("18446744073709551615")) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts index 967a236607..3a8f1806c8 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts @@ -4,9 +4,7 @@ import * as z from 'zod/v4-mini'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => { - return zBar; - })), + z.array(z.lazy((): any => zBar)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts index 4c5643d938..dda5d46941 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts @@ -4,9 +4,7 @@ import * as z from 'zod/v4-mini'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => { - return zBar; - }))); + return z.optional(z.array(z.lazy((): any => zBar))); } }); @@ -14,9 +12,7 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => { - return zQux; -}); +export const zBaz = z.lazy((): any => zQux); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts index b515009b63..8ecedac9aa 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts @@ -15,14 +15,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), @@ -57,9 +53,7 @@ export const zPatchFooData = z.object({ baz: z.optional(z.string()) })), qux: z.optional(z.iso.date()), - quux: z.optional(z.iso.datetime({ - offset: true - })) + quux: z.optional(z.iso.datetime({ offset: true })) })) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts index 64973d66ec..d9cdb447e1 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts @@ -14,22 +14,18 @@ export const zQux = z.record(z.string(), z.object({ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/)).register(z.globalRegistry, { - description: 'This is foo property.' + description: "This is foo property." })), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - })).register(z.globalRegistry, { - description: 'This is baz property.' + return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { + description: "This is baz property." })); }, qux: z._default(z.optional(z.int().check(z.gt(0)).register(z.globalRegistry, { - description: 'This is qux property.' + description: "This is qux property." })), 0) }), z.null() @@ -41,14 +37,14 @@ export const zFoo = z._default(z.union([ export const zBar = z.object({ foo: z.optional(zFoo) }).register(z.globalRegistry, { - description: 'This is Bar schema.' + description: "This is Bar schema." }); /** * This is Foo parameter. */ export const zFoo2 = z.string().register(z.globalRegistry, { - description: 'This is Foo parameter.' + description: "This is Foo parameter." }); export const zFoo3 = z.object({ @@ -62,7 +58,7 @@ export const zPatchFooData = z.object({ path: z.optional(z.never()), query: z.optional(z.object({ foo: z.optional(z.string().register(z.globalRegistry, { - description: 'This is Foo parameter.' + description: "This is Foo parameter." })), bar: z.optional(zBar), baz: z.optional(z.object({ diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts index 2b1c21593f..a8353e832e 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts @@ -19,14 +19,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts index d3e255eb03..304d89bb57 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts @@ -15,14 +15,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts index e56c1943f4..58947fdc5a 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -402,9 +402,7 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => { - return zModelWithCircularReference; - }).optional() + prop: z.lazy(() => zModelWithCircularReference).optional() }); /** @@ -453,10 +451,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }).and(zModelCircle), z.object({ - kind: z.literal('square') + kind: z.literal("square") }).and(zModelSquare) ]); @@ -506,7 +504,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal('ConstValue'); +export const zConstValue = z.literal("ConstValue"); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -751,10 +749,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.unknown( export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.unknown()); export const zModelWithConst = z.object({ - String: z.literal('String').optional(), + String: z.literal("String").optional(), number: z.literal(0).optional(), null: z.null().optional(), - withType: z.literal('Some string').optional() + withType: z.literal("Some string").optional() }); /** @@ -1686,9 +1684,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal('Success'), - z.literal('Warning'), - z.literal('Error'), + z.literal("Success"), + z.literal("Warning"), + z.literal("Error"), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts index e577fd348b..79075274d6 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; export const zFoo = z.object({ - foo: z.literal('foo').optional(), + foo: z.literal("foo").optional(), bar: z.literal(3.2).optional(), baz: z.literal(-1).optional(), qux: z.literal(true).optional(), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.literal(65535).optional(), integerUint32: z.literal(4294967295).optional(), integerUint64: z.number().int().optional(), - stringInt64: z.literal('-9223372036854775808').optional(), - stringUint64: z.literal('18446744073709551615').optional() + stringInt64: z.literal("-9223372036854775808").optional(), + stringUint64: z.literal("18446744073709551615").optional() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts index 582c9ca066..f2c188be3e 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts @@ -4,9 +4,7 @@ import { z } from 'zod'; export const zBar: z.AnyZodObject = z.object({ bar: z.union([ - z.array(z.lazy(() => { - return zBar; - })), + z.array(z.lazy(() => zBar)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts index 57536e8660..d1f4aaa4b2 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts @@ -3,18 +3,14 @@ import { z } from 'zod'; export const zBar: z.AnyZodObject = z.object({ - bar: z.array(z.lazy(() => { - return zBar; - })).optional() + bar: z.array(z.lazy(() => zBar)).optional() }); export const zFoo = z.object({ foo: zBar.optional() }); -export const zBaz: z.ZodTypeAny = z.lazy(() => { - return zQux; -}); +export const zBaz: z.ZodTypeAny = z.lazy(() => zQux); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts index 620a0a8640..c9317d5912 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts @@ -14,12 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() @@ -53,9 +49,7 @@ export const zPatchFooData = z.object({ baz: z.string().optional() }).optional(), qux: z.string().date().optional(), - quux: z.string().datetime({ - offset: true - }).optional() + quux: z.string().datetime({ offset: true }).optional() }).optional() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts index 4a09748c76..e89f8e00be 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts @@ -13,14 +13,10 @@ export const zQux = z.record(z.object({ */ export const zFoo: z.ZodTypeAny = z.union([ z.object({ - foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe('This is foo property.').optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).describe('This is baz property.').optional(), - qux: z.number().int().gt(0).describe('This is qux property.').optional().default(0) + foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe("This is foo property.").optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).describe("This is baz property.").optional(), + qux: z.number().int().gt(0).describe("This is qux property.").optional().default(0) }), z.null() ]).default(null); @@ -30,12 +26,12 @@ export const zFoo: z.ZodTypeAny = z.union([ */ export const zBar = z.object({ foo: zFoo.optional() -}).describe('This is Bar schema.'); +}).describe("This is Bar schema."); /** * This is Foo parameter. */ -export const zFoo2 = z.string().describe('This is Foo parameter.'); +export const zFoo2 = z.string().describe("This is Foo parameter."); export const zFoo3 = z.object({ foo: zBar.optional() @@ -47,7 +43,7 @@ export const zPatchFooData = z.object({ }), path: z.never().optional(), query: z.object({ - foo: z.string().describe('This is Foo parameter.').optional(), + foo: z.string().describe("This is Foo parameter.").optional(), bar: zBar.optional(), baz: z.object({ baz: z.string().optional() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts index d79d307e9b..c26d40cf35 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts @@ -18,12 +18,8 @@ export type QuxZodType = z.infer; export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts index bcda6a22d8..8e5318a8c7 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts @@ -14,12 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts index 6279534dbd..57de43d2ac 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -403,9 +403,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); @@ -455,10 +453,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }).and(zModelCircle), z.object({ - kind: z.literal('square') + kind: z.literal("square") }).and(zModelSquare) ]); @@ -508,7 +506,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal('ConstValue'); +export const zConstValue = z.literal("ConstValue"); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -753,10 +751,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.string() export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); export const zModelWithConst = z.object({ - String: z.optional(z.literal('String')), + String: z.optional(z.literal("String")), number: z.optional(z.literal(0)), null: z.optional(z.null()), - withType: z.optional(z.literal('Some string')) + withType: z.optional(z.literal("Some string")) }); /** @@ -1688,9 +1686,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal('Success'), - z.literal('Warning'), - z.literal('Error'), + z.literal("Success"), + z.literal("Warning"), + z.literal("Error"), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts index 961bdec15c..152fe92964 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ - foo: z.optional(z.literal('foo')), + foo: z.optional(z.literal("foo")), bar: z.optional(z.literal(3.2)), baz: z.optional(z.literal(-1)), qux: z.optional(z.literal(true)), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal('-9223372036854775808')), - stringUint64: z.optional(z.literal('18446744073709551615')) + stringInt64: z.optional(z.literal("-9223372036854775808")), + stringUint64: z.optional(z.literal("18446744073709551615")) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts index 8f42902913..0560094fdc 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts @@ -4,9 +4,7 @@ import { z } from 'zod/v4'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => { - return zBar; - })), + z.array(z.lazy((): any => zBar)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts index 0fba2fc8b7..7bd218fcbf 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts @@ -4,9 +4,7 @@ import { z } from 'zod/v4'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => { - return zBar; - }))); + return z.optional(z.array(z.lazy((): any => zBar))); } }); @@ -14,9 +12,7 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => { - return zQux; -}); +export const zBaz = z.lazy((): any => zQux); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts index 36e6f721aa..5781d917ff 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts @@ -15,14 +15,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z.optional(z.int().gt(0)).default(0) }), @@ -57,9 +53,7 @@ export const zPatchFooData = z.object({ baz: z.optional(z.string()) })), qux: z.optional(z.iso.date()), - quux: z.optional(z.iso.datetime({ - offset: true - })) + quux: z.optional(z.iso.datetime({ offset: true })) })) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts index 270bc9a0d3..eb25f46f5a 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts @@ -14,22 +14,18 @@ export const zQux = z.record(z.string(), z.object({ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/).register(z.globalRegistry, { - description: 'This is foo property.' + description: "This is foo property." })), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - })).register(z.globalRegistry, { - description: 'This is baz property.' + return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { + description: "This is baz property." })); }, qux: z.optional(z.int().gt(0).register(z.globalRegistry, { - description: 'This is qux property.' + description: "This is qux property." })).default(0) }), z.null() @@ -41,14 +37,14 @@ export const zFoo = z.union([ export const zBar = z.object({ foo: z.optional(zFoo) }).register(z.globalRegistry, { - description: 'This is Bar schema.' + description: "This is Bar schema." }); /** * This is Foo parameter. */ export const zFoo2 = z.string().register(z.globalRegistry, { - description: 'This is Foo parameter.' + description: "This is Foo parameter." }); export const zFoo3 = z.object({ @@ -62,7 +58,7 @@ export const zPatchFooData = z.object({ path: z.optional(z.never()), query: z.optional(z.object({ foo: z.optional(z.string().register(z.globalRegistry, { - description: 'This is Foo parameter.' + description: "This is Foo parameter." })), bar: z.optional(zBar), baz: z.optional(z.object({ diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts index c36f93b323..b2d4ca7177 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts @@ -19,14 +19,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts index 2b37813980..15238b2a7e 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts @@ -15,14 +15,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts index 86fca9b1d6..a89a89735c 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts @@ -294,9 +294,7 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts index 6b727d44ee..46bd465e9a 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts @@ -293,9 +293,7 @@ export const zModelWithDictionary = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => { - return zModelWithCircularReference; - }).optional() + prop: z.lazy(() => zModelWithCircularReference).optional() }); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts index bc7dcb6542..87c7a4316d 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts @@ -294,9 +294,7 @@ export const zModelWithDictionary = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts index 0c5d13033f..a1cb7944f2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/circular/zod.gen.ts @@ -4,43 +4,31 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => { - return zQuux; - })); + return z.optional(z.lazy((): any => zQuux)); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.lazy((): any => { - return zBaz; - })); + return z.optional(z.lazy((): any => zBaz)); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => { - return zQuux; - })); + return z.optional(z.lazy((): any => zQuux)); } }); export const zQux = z.union([ z.intersection(z.object({ - type: z.literal('struct') - }), z.lazy(() => { - return z.lazy((): any => { - return zCorge; - }); - })), + type: z.literal("struct") + }), z.lazy(() => z.lazy((): any => zCorge))), z.intersection(z.object({ - type: z.literal('array') + type: z.literal("array") }), zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts index 5b29d62f75..5a6405c953 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -400,9 +400,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); @@ -452,10 +450,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.intersection(z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }), zModelCircle), z.intersection(z.object({ - kind: z.literal('square') + kind: z.literal("square") }), zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts index 786ac3505a..7a5c784862 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts @@ -8,14 +8,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts index 6011ab3e7c..6be8f68f2a 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/circular/zod.gen.ts @@ -3,34 +3,24 @@ import { z } from 'zod/v3'; export const zFoo: z.AnyZodObject = z.object({ - quux: z.lazy(() => { - return zQuux; - }).optional() + quux: z.lazy(() => zQuux).optional() }); export const zBar: z.AnyZodObject = z.object({ - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.lazy(() => { - return zBaz; - }).optional() + bar: z.lazy(() => zBar).optional(), + baz: z.lazy(() => zBaz).optional() }); export const zBaz: z.AnyZodObject = z.object({ - quux: z.lazy(() => { - return zQuux; - }).optional() + quux: z.lazy(() => zQuux).optional() }); export const zQux: z.ZodTypeAny = z.union([ z.object({ - type: z.literal('struct') - }).and(z.lazy(() => { - return zCorge; - })), + type: z.literal("struct") + }).and(z.lazy(() => zCorge)), z.object({ - type: z.literal('array') + type: z.literal("array") }).and(zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts index 6b12e930da..50fddeaa4a 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -399,9 +399,7 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => { - return zModelWithCircularReference; - }).optional() + prop: z.lazy(() => zModelWithCircularReference).optional() }); /** @@ -450,10 +448,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }).and(zModelCircle), z.object({ - kind: z.literal('square') + kind: z.literal("square") }).and(zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts index 884fe8b894..bdddc57752 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts @@ -7,12 +7,8 @@ export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts index 27ac2c0cc9..e8811d02f5 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/circular/zod.gen.ts @@ -4,43 +4,31 @@ import { z } from 'zod'; export const zFoo = z.object({ get quux() { - return z.optional(z.lazy((): any => { - return zQuux; - })); + return z.optional(z.lazy((): any => zQuux)); } }); export const zBar = z.object({ get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.lazy((): any => { - return zBaz; - })); + return z.optional(z.lazy((): any => zBaz)); } }); export const zBaz = z.object({ get quux() { - return z.optional(z.lazy((): any => { - return zQuux; - })); + return z.optional(z.lazy((): any => zQuux)); } }); export const zQux = z.union([ z.object({ - type: z.literal('struct') - }).and(z.lazy(() => { - return z.lazy((): any => { - return zCorge; - }); - })), + type: z.literal("struct") + }).and(z.lazy(() => z.lazy((): any => zCorge))), z.object({ - type: z.literal('array') + type: z.literal("array") }).and(zFoo) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts index b608099100..c44dd9b8e4 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -400,9 +400,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); @@ -452,10 +450,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }).and(zModelCircle), z.object({ - kind: z.literal('square') + kind: z.literal("square") }).and(zModelSquare) ]); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts index f6b581f0d9..944f96e474 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts @@ -8,14 +8,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts index 5ffa612787..7974190a01 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -403,9 +403,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); @@ -455,10 +453,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.intersection(z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }), zModelCircle), z.intersection(z.object({ - kind: z.literal('square') + kind: z.literal("square") }), zModelSquare) ]); @@ -508,7 +506,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal('ConstValue'); +export const zConstValue = z.literal("ConstValue"); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -753,10 +751,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.string() export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); export const zModelWithConst = z.object({ - String: z.optional(z.literal('String')), + String: z.optional(z.literal("String")), number: z.optional(z.literal(0)), null: z.optional(z.null()), - withType: z.optional(z.literal('Some string')) + withType: z.optional(z.literal("Some string")) }); /** @@ -1688,9 +1686,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal('Success'), - z.literal('Warning'), - z.literal('Error'), + z.literal("Success"), + z.literal("Warning"), + z.literal("Error"), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts index 1b4e0e1cf1..c6bbe64fa0 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ - foo: z.optional(z.literal('foo')), + foo: z.optional(z.literal("foo")), bar: z.optional(z.literal(3.2)), baz: z.optional(z.literal(-1)), qux: z.optional(z.literal(true)), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal('-9223372036854775808')), - stringUint64: z.optional(z.literal('18446744073709551615')) + stringInt64: z.optional(z.literal("-9223372036854775808")), + stringUint64: z.optional(z.literal("18446744073709551615")) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts index aed07582c6..6014595afa 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref-2/zod.gen.ts @@ -4,9 +4,7 @@ import * as z from 'zod/mini'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => { - return zBar; - })), + z.array(z.lazy((): any => zBar)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts index 33a0a739a4..ee8b0c76ef 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-circular-ref/zod.gen.ts @@ -4,9 +4,7 @@ import * as z from 'zod/mini'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => { - return zBar; - }))); + return z.optional(z.array(z.lazy((): any => zBar))); } }); @@ -14,9 +12,7 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => { - return zQux; -}); +export const zBaz = z.lazy((): any => zQux); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts index d64c84a813..9ac32990ce 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts @@ -15,14 +15,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), @@ -57,9 +53,7 @@ export const zPatchFooData = z.object({ baz: z.optional(z.string()) })), qux: z.optional(z.iso.date()), - quux: z.optional(z.iso.datetime({ - offset: true - })) + quux: z.optional(z.iso.datetime({ offset: true })) })) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts index aaf540431c..db559c7419 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts @@ -14,22 +14,18 @@ export const zQux = z.record(z.string(), z.object({ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/)).register(z.globalRegistry, { - description: 'This is foo property.' + description: "This is foo property." })), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - })).register(z.globalRegistry, { - description: 'This is baz property.' + return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { + description: "This is baz property." })); }, qux: z._default(z.optional(z.int().check(z.gt(0)).register(z.globalRegistry, { - description: 'This is qux property.' + description: "This is qux property." })), 0) }), z.null() @@ -41,14 +37,14 @@ export const zFoo = z._default(z.union([ export const zBar = z.object({ foo: z.optional(zFoo) }).register(z.globalRegistry, { - description: 'This is Bar schema.' + description: "This is Bar schema." }); /** * This is Foo parameter. */ export const zFoo2 = z.string().register(z.globalRegistry, { - description: 'This is Foo parameter.' + description: "This is Foo parameter." }); export const zFoo3 = z.object({ @@ -62,7 +58,7 @@ export const zPatchFooData = z.object({ path: z.optional(z.never()), query: z.optional(z.object({ foo: z.optional(z.string().register(z.globalRegistry, { - description: 'This is Foo parameter.' + description: "This is Foo parameter." })), bar: z.optional(zBar), baz: z.optional(z.object({ diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts index 19e14da91b..669174c0ac 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts @@ -19,14 +19,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts index 65b32c7ba9..b786abd75f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts @@ -15,14 +15,10 @@ export const zFoo = z._default(z.union([ z.object({ foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z._default(z.optional(z.int().check(z.gt(0))), 0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts index 49aa50ac5d..bd1c50c977 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -402,9 +402,7 @@ export const zDeprecatedModel = z.object({ * This is a model with one property containing a circular reference */ export const zModelWithCircularReference: z.AnyZodObject = z.object({ - prop: z.lazy(() => { - return zModelWithCircularReference; - }).optional() + prop: z.lazy(() => zModelWithCircularReference).optional() }); /** @@ -453,10 +451,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }).and(zModelCircle), z.object({ - kind: z.literal('square') + kind: z.literal("square") }).and(zModelSquare) ]); @@ -506,7 +504,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal('ConstValue'); +export const zConstValue = z.literal("ConstValue"); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -751,10 +749,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.unknown( export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.unknown()); export const zModelWithConst = z.object({ - String: z.literal('String').optional(), + String: z.literal("String").optional(), number: z.literal(0).optional(), null: z.null().optional(), - withType: z.literal('Some string').optional() + withType: z.literal("Some string").optional() }); /** @@ -1686,9 +1684,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal('Success'), - z.literal('Warning'), - z.literal('Error'), + z.literal("Success"), + z.literal("Warning"), + z.literal("Error"), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts index 2f582cbad9..4994bcc671 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import { z } from 'zod/v3'; export const zFoo = z.object({ - foo: z.literal('foo').optional(), + foo: z.literal("foo").optional(), bar: z.literal(3.2).optional(), baz: z.literal(-1).optional(), qux: z.literal(true).optional(), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.literal(65535).optional(), integerUint32: z.literal(4294967295).optional(), integerUint64: z.number().int().optional(), - stringInt64: z.literal('-9223372036854775808').optional(), - stringUint64: z.literal('18446744073709551615').optional() + stringInt64: z.literal("-9223372036854775808").optional(), + stringUint64: z.literal("18446744073709551615").optional() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts index 15bdeb3e2c..4d47e4d619 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref-2/zod.gen.ts @@ -4,9 +4,7 @@ import { z } from 'zod/v3'; export const zBar: z.AnyZodObject = z.object({ bar: z.union([ - z.array(z.lazy(() => { - return zBar; - })), + z.array(z.lazy(() => zBar)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts index 466a9fc5b0..02708822cd 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-circular-ref/zod.gen.ts @@ -3,18 +3,14 @@ import { z } from 'zod/v3'; export const zBar: z.AnyZodObject = z.object({ - bar: z.array(z.lazy(() => { - return zBar; - })).optional() + bar: z.array(z.lazy(() => zBar)).optional() }); export const zFoo = z.object({ foo: zBar.optional() }); -export const zBaz: z.ZodTypeAny = z.lazy(() => { - return zQux; -}); +export const zBaz: z.ZodTypeAny = z.lazy(() => zQux); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts index 746c1c5742..68a0a720f4 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts @@ -14,12 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() @@ -53,9 +49,7 @@ export const zPatchFooData = z.object({ baz: z.string().optional() }).optional(), qux: z.string().date().optional(), - quux: z.string().datetime({ - offset: true - }).optional() + quux: z.string().datetime({ offset: true }).optional() }).optional() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts index 396361b2aa..f2ed3769dd 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts @@ -13,14 +13,10 @@ export const zQux = z.record(z.object({ */ export const zFoo: z.ZodTypeAny = z.union([ z.object({ - foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe('This is foo property.').optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).describe('This is baz property.').optional(), - qux: z.number().int().gt(0).describe('This is qux property.').optional().default(0) + foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).describe("This is foo property.").optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).describe("This is baz property.").optional(), + qux: z.number().int().gt(0).describe("This is qux property.").optional().default(0) }), z.null() ]).default(null); @@ -30,12 +26,12 @@ export const zFoo: z.ZodTypeAny = z.union([ */ export const zBar = z.object({ foo: zFoo.optional() -}).describe('This is Bar schema.'); +}).describe("This is Bar schema."); /** * This is Foo parameter. */ -export const zFoo2 = z.string().describe('This is Foo parameter.'); +export const zFoo2 = z.string().describe("This is Foo parameter."); export const zFoo3 = z.object({ foo: zBar.optional() @@ -47,7 +43,7 @@ export const zPatchFooData = z.object({ }), path: z.never().optional(), query: z.object({ - foo: z.string().describe('This is Foo parameter.').optional(), + foo: z.string().describe("This is Foo parameter.").optional(), bar: zBar.optional(), baz: z.object({ baz: z.string().optional() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts index 7b92df5bc5..2b0fa9eed9 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts @@ -18,12 +18,8 @@ export type QuxZodType = z.infer; export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts index d4c6fe5369..15850f6a29 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts @@ -14,12 +14,8 @@ export const zQux = z.record(z.object({ export const zFoo: z.ZodTypeAny = z.union([ z.object({ foo: z.string().regex(/^\d{3}-\d{2}-\d{4}$/).optional(), - bar: z.lazy(() => { - return zBar; - }).optional(), - baz: z.array(z.lazy(() => { - return zFoo; - })).optional(), + bar: z.lazy(() => zBar).optional(), + baz: z.array(z.lazy(() => zFoo)).optional(), qux: z.number().int().gt(0).optional().default(0) }), z.null() diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts index 8bafc886b2..a9cded5374 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -403,9 +403,7 @@ export const zDeprecatedModel = z.object({ */ export const zModelWithCircularReference = z.object({ get prop() { - return z.optional(z.lazy((): any => { - return zModelWithCircularReference; - })); + return z.optional(z.lazy((): any => zModelWithCircularReference)); } }); @@ -455,10 +453,10 @@ export const zModelSquare = z.object({ */ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle') + kind: z.literal("circle") }).and(zModelCircle), z.object({ - kind: z.literal('square') + kind: z.literal("square") }).and(zModelSquare) ]); @@ -508,7 +506,7 @@ export const z3eNum1Период = z.enum([ 'Dog' ]); -export const zConstValue = z.literal('ConstValue'); +export const zConstValue = z.literal("ConstValue"); /** * This is a model with one property with a 'any of' relationship where the options are not $ref @@ -753,10 +751,10 @@ export const zFreeFormObjectWithAdditionalPropertiesEqTrue = z.record(z.string() export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); export const zModelWithConst = z.object({ - String: z.optional(z.literal('String')), + String: z.optional(z.literal("String")), number: z.optional(z.literal(0)), null: z.optional(z.null()), - withType: z.optional(z.literal('Some string')) + withType: z.optional(z.literal("Some string")) }); /** @@ -1688,9 +1686,9 @@ export const zTypesData = z.object({ z.null() ]), parameterEnum: z.union([ - z.literal('Success'), - z.literal('Warning'), - z.literal('Error'), + z.literal("Success"), + z.literal("Warning"), + z.literal("Error"), z.null() ]) }) diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts index 2b7e1c4622..46ea47c1df 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; export const zFoo = z.object({ - foo: z.optional(z.literal('foo')), + foo: z.optional(z.literal("foo")), bar: z.optional(z.literal(3.2)), baz: z.optional(z.literal(-1)), qux: z.optional(z.literal(true)), @@ -32,6 +32,6 @@ export const zFoo = z.object({ integerUint16: z.optional(z.literal(65535)), integerUint32: z.optional(z.literal(4294967295)), integerUint64: z.optional(z.int()), - stringInt64: z.optional(z.literal('-9223372036854775808')), - stringUint64: z.optional(z.literal('18446744073709551615')) + stringInt64: z.optional(z.literal("-9223372036854775808")), + stringUint64: z.optional(z.literal("18446744073709551615")) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts index f638411068..696338aab2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref-2/zod.gen.ts @@ -4,9 +4,7 @@ import { z } from 'zod'; export const zBar = z.object({ bar: z.union([ - z.array(z.lazy((): any => { - return zBar; - })), + z.array(z.lazy((): any => zBar)), z.null() ]) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts index 53ce2eb2f0..b628129549 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-circular-ref/zod.gen.ts @@ -4,9 +4,7 @@ import { z } from 'zod'; export const zBar = z.object({ get bar() { - return z.optional(z.array(z.lazy((): any => { - return zBar; - }))); + return z.optional(z.array(z.lazy((): any => zBar))); } }); @@ -14,9 +12,7 @@ export const zFoo = z.object({ foo: z.optional(zBar) }); -export const zBaz = z.lazy((): any => { - return zQux; -}); +export const zBaz = z.lazy((): any => zQux); /** * description caused circular reference error diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts index bc6bd1d71e..515d9ad8bd 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts @@ -15,14 +15,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z.optional(z.int().gt(0)).default(0) }), @@ -57,9 +53,7 @@ export const zPatchFooData = z.object({ baz: z.optional(z.string()) })), qux: z.optional(z.iso.date()), - quux: z.optional(z.iso.datetime({ - offset: true - })) + quux: z.optional(z.iso.datetime({ offset: true })) })) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts index 4e71c97c64..9678e5eb9d 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts @@ -14,22 +14,18 @@ export const zQux = z.record(z.string(), z.object({ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/).register(z.globalRegistry, { - description: 'This is foo property.' + description: "This is foo property." })), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - })).register(z.globalRegistry, { - description: 'This is baz property.' + return z.optional(z.array(z.lazy((): any => zFoo)).register(z.globalRegistry, { + description: "This is baz property." })); }, qux: z.optional(z.int().gt(0).register(z.globalRegistry, { - description: 'This is qux property.' + description: "This is qux property." })).default(0) }), z.null() @@ -41,14 +37,14 @@ export const zFoo = z.union([ export const zBar = z.object({ foo: z.optional(zFoo) }).register(z.globalRegistry, { - description: 'This is Bar schema.' + description: "This is Bar schema." }); /** * This is Foo parameter. */ export const zFoo2 = z.string().register(z.globalRegistry, { - description: 'This is Foo parameter.' + description: "This is Foo parameter." }); export const zFoo3 = z.object({ @@ -62,7 +58,7 @@ export const zPatchFooData = z.object({ path: z.optional(z.never()), query: z.optional(z.object({ foo: z.optional(z.string().register(z.globalRegistry, { - description: 'This is Foo parameter.' + description: "This is Foo parameter." })), bar: z.optional(zBar), baz: z.optional(z.object({ diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts index ba13cd685d..033e85ced5 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts @@ -19,14 +19,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts index a48bf21863..f73a35bac9 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts @@ -15,14 +15,10 @@ export const zFoo = z.union([ z.object({ foo: z.optional(z.string().regex(/^\d{3}-\d{2}-\d{4}$/)), get bar() { - return z.optional(z.lazy((): any => { - return zBar; - })); + return z.optional(z.lazy((): any => zBar)); }, get baz() { - return z.optional(z.array(z.lazy((): any => { - return zFoo; - }))); + return z.optional(z.array(z.lazy((): any => zFoo))); }, qux: z.optional(z.int().gt(0)).default(0) }), diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts index f72a681231..50553e7001 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts @@ -100,7 +100,7 @@ export const createSwrMutationOptions = ({ ]), ), ); - keyType = `readonly [string] | readonly [string, ${typeData}]`; + keyType = `string[] | [string, ${typeData}]`; } else { // No parameters: simple array key [path] mutationKey = $( @@ -108,7 +108,7 @@ export const createSwrMutationOptions = ({ $.literal(operation.path).$render(), ]), ); - keyType = 'readonly [string]'; + keyType = 'string[]'; } // Build the options object From 46eccd455dceb851f2542c1b895ba7a264887a89 Mon Sep 17 00:00:00 2001 From: Pewww Date: Sun, 16 Nov 2025 18:18:15 +0900 Subject: [PATCH 8/9] fix: remove unusing parameters in swr plugin --- examples/openapi-ts-swr/src/client/swr.gen.ts | 13 ++--- .../2.0.x/plugins/swr/asClass/swr.gen.ts | 8 +-- .../2.0.x/plugins/swr/axios/swr.gen.ts | 32 ++++++------ .../2.0.x/plugins/swr/fetch/swr.gen.ts | 32 ++++++------ .../3.0.x/plugins/swr/asClass/swr.gen.ts | 8 +-- .../3.0.x/plugins/swr/axios/swr.gen.ts | 50 +++++++++++-------- .../3.0.x/plugins/swr/fetch/swr.gen.ts | 50 +++++++++++-------- .../3.1.x/plugins/swr/asClass/swr.gen.ts | 8 +-- .../3.1.x/plugins/swr/axios/swr.gen.ts | 50 +++++++++++-------- .../3.1.x/plugins/swr/fetch/swr.gen.ts | 50 +++++++++++-------- .../main/test/plugins/swr/infinite.test.ts | 4 ++ .../openapi-ts/src/plugins/swr/v2/plugin.ts | 24 --------- .../src/plugins/swr/v2/swrInfiniteOptions.ts | 38 ++++++++------ .../openapi-ts/src/plugins/swr/v2/swrKey.ts | 13 +++-- .../src/plugins/swr/v2/swrOptions.ts | 14 +++++- 15 files changed, 213 insertions(+), 181 deletions(-) diff --git a/examples/openapi-ts-swr/src/client/swr.gen.ts b/examples/openapi-ts-swr/src/client/swr.gen.ts index 49db086e1f..29ce197a74 100644 --- a/examples/openapi-ts-swr/src/client/swr.gen.ts +++ b/examples/openapi-ts-swr/src/client/swr.gen.ts @@ -44,7 +44,6 @@ import type { UploadFileData, } from './types.gen'; -/* eslint-disable @typescript-eslint/no-unused-vars */ /** * Add a new pet to the store. * @@ -227,9 +226,7 @@ export const uploadFileMutation = (options?: Options) => ({ : ['/pet/{petId}/uploadImage'], }); -export const getInventoryKey = (options?: Options) => [ - '/store/inventory', -]; +export const getInventoryKey = () => ['/store/inventory']; /** * Returns pet inventories by status. @@ -241,7 +238,7 @@ export const getInventoryOptions = (options?: Options) => ({ const { data } = await getInventory({ ...options, throwOnError: true }); return data; }, - key: getInventoryKey(options), + key: getInventoryKey(), }); /** @@ -380,9 +377,7 @@ export const loginUserOptions = (options?: Options) => ({ key: loginUserKey(options), }); -export const logoutUserKey = (options?: Options) => [ - '/user/logout', -]; +export const logoutUserKey = () => ['/user/logout']; /** * Logs out current logged in user session. @@ -394,7 +389,7 @@ export const logoutUserOptions = (options?: Options) => ({ const { data } = await logoutUser({ ...options, throwOnError: true }); return data; }, - key: logoutUserKey(options), + key: logoutUserKey(), }); /** diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts index 33cb83c8c5..40fd9a0bb5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/asClass/swr.gen.ts @@ -6,10 +6,10 @@ import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarD /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const getFooKey = (options?: Options) => ["/foo"]; +export const getFooKey = () => ["/foo"]; export const getFooOptions = (options?: Options) => ({ - key: getFooKey(options), + key: getFooKey(), fetcher: async () => { const { data } = await FooBazService.getFoo({ ...options, throwOnError: true }); return data; @@ -44,10 +44,10 @@ export const fooPutMutation = (options?: Options) => ({ } }); -export const getFooBarKey = (options?: Options) => ["/foo/bar"]; +export const getFooBarKey = () => ["/foo/bar"]; export const getFooBarOptions = (options?: Options) => ({ - key: getFooBarKey(options), + key: getFooBarKey(), fetcher: async () => { const { data } = await BarBazService.getFooBar({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts index 0f2638aa18..5ceb055915 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/axios/swr.gen.ts @@ -6,10 +6,10 @@ import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const serviceWithEmptyTagKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; +export const serviceWithEmptyTagKey = () => ["/api/v{api-version}/no+tag"]; export const serviceWithEmptyTagOptions = (options?: Options) => ({ - key: serviceWithEmptyTagKey(options), + key: serviceWithEmptyTagKey(), fetcher: async () => { const { data } = await serviceWithEmptyTag({ ...options, throwOnError: true }); return data; @@ -58,10 +58,10 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Options } }); -export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; +export const getCallWithoutParametersAndResponseKey = () => ["/api/v{api-version}/simple"]; export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ - key: getCallWithoutParametersAndResponseKey(options), + key: getCallWithoutParametersAndResponseKey(), fetcher: async () => { const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); return data; @@ -204,10 +204,10 @@ export const duplicateNameMutation = (options?: Options) => ( } }); -export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; +export const duplicateName2Key = () => ["/api/v{api-version}/duplicate"]; export const duplicateName2Options = (options?: Options) => ({ - key: duplicateName2Key(options), + key: duplicateName2Key(), fetcher: async () => { const { data } = await duplicateName2({ ...options, throwOnError: true }); return data; @@ -242,50 +242,50 @@ export const duplicateName4Mutation = (options?: Options) => } }); -export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; +export const callWithNoContentResponseKey = () => ["/api/v{api-version}/no-content"]; export const callWithNoContentResponseOptions = (options?: Options) => ({ - key: callWithNoContentResponseKey(options), + key: callWithNoContentResponseKey(), fetcher: async () => { const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; +export const callWithResponseAndNoContentResponseKey = () => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ - key: callWithResponseAndNoContentResponseKey(options), + key: callWithResponseAndNoContentResponseKey(), fetcher: async () => { const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; +export const dummyAKey = () => ["/api/v{api-version}/multiple-tags/a"]; export const dummyAOptions = (options?: Options) => ({ - key: dummyAKey(options), + key: dummyAKey(), fetcher: async () => { const { data } = await dummyA({ ...options, throwOnError: true }); return data; } }); -export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; +export const dummyBKey = () => ["/api/v{api-version}/multiple-tags/b"]; export const dummyBOptions = (options?: Options) => ({ - key: dummyBKey(options), + key: dummyBKey(), fetcher: async () => { const { data } = await dummyB({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; +export const callWithResponseKey = () => ["/api/v{api-version}/response"]; export const callWithResponseOptions = (options?: Options) => ({ - key: callWithResponseKey(options), + key: callWithResponseKey(), fetcher: async () => { const { data } = await callWithResponse({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts index 0f2638aa18..5ceb055915 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/swr/fetch/swr.gen.ts @@ -6,10 +6,10 @@ import type { CallToTestOrderOfParamsData, CallWithDefaultOptionalParametersData /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const serviceWithEmptyTagKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; +export const serviceWithEmptyTagKey = () => ["/api/v{api-version}/no+tag"]; export const serviceWithEmptyTagOptions = (options?: Options) => ({ - key: serviceWithEmptyTagKey(options), + key: serviceWithEmptyTagKey(), fetcher: async () => { const { data } = await serviceWithEmptyTag({ ...options, throwOnError: true }); return data; @@ -58,10 +58,10 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Options } }); -export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; +export const getCallWithoutParametersAndResponseKey = () => ["/api/v{api-version}/simple"]; export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ - key: getCallWithoutParametersAndResponseKey(options), + key: getCallWithoutParametersAndResponseKey(), fetcher: async () => { const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); return data; @@ -204,10 +204,10 @@ export const duplicateNameMutation = (options?: Options) => ( } }); -export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; +export const duplicateName2Key = () => ["/api/v{api-version}/duplicate"]; export const duplicateName2Options = (options?: Options) => ({ - key: duplicateName2Key(options), + key: duplicateName2Key(), fetcher: async () => { const { data } = await duplicateName2({ ...options, throwOnError: true }); return data; @@ -242,50 +242,50 @@ export const duplicateName4Mutation = (options?: Options) => } }); -export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; +export const callWithNoContentResponseKey = () => ["/api/v{api-version}/no-content"]; export const callWithNoContentResponseOptions = (options?: Options) => ({ - key: callWithNoContentResponseKey(options), + key: callWithNoContentResponseKey(), fetcher: async () => { const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; +export const callWithResponseAndNoContentResponseKey = () => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ - key: callWithResponseAndNoContentResponseKey(options), + key: callWithResponseAndNoContentResponseKey(), fetcher: async () => { const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; +export const dummyAKey = () => ["/api/v{api-version}/multiple-tags/a"]; export const dummyAOptions = (options?: Options) => ({ - key: dummyAKey(options), + key: dummyAKey(), fetcher: async () => { const { data } = await dummyA({ ...options, throwOnError: true }); return data; } }); -export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; +export const dummyBKey = () => ["/api/v{api-version}/multiple-tags/b"]; export const dummyBOptions = (options?: Options) => ({ - key: dummyBKey(options), + key: dummyBKey(), fetcher: async () => { const { data } = await dummyB({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; +export const callWithResponseKey = () => ["/api/v{api-version}/response"]; export const callWithResponseOptions = (options?: Options) => ({ - key: callWithResponseKey(options), + key: callWithResponseKey(), fetcher: async () => { const { data } = await callWithResponse({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts index 33cb83c8c5..40fd9a0bb5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/asClass/swr.gen.ts @@ -6,10 +6,10 @@ import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarD /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const getFooKey = (options?: Options) => ["/foo"]; +export const getFooKey = () => ["/foo"]; export const getFooOptions = (options?: Options) => ({ - key: getFooKey(options), + key: getFooKey(), fetcher: async () => { const { data } = await FooBazService.getFoo({ ...options, throwOnError: true }); return data; @@ -44,10 +44,10 @@ export const fooPutMutation = (options?: Options) => ({ } }); -export const getFooBarKey = (options?: Options) => ["/foo/bar"]; +export const getFooBarKey = () => ["/foo/bar"]; export const getFooBarOptions = (options?: Options) => ({ - key: getFooBarKey(options), + key: getFooBarKey(), fetcher: async () => { const { data } = await BarBazService.getFooBar({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts index 60cc8a124f..392d9d7db1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/axios/swr.gen.ts @@ -6,10 +6,10 @@ import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const exportKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; +export const exportKey = () => ["/api/v{api-version}/no+tag"]; export const exportOptions = (options?: Options) => ({ - key: exportKey(options), + key: exportKey(), fetcher: async () => { const { data } = await export_({ ...options, throwOnError: true }); return data; @@ -58,10 +58,10 @@ export const fooWowMutation = (options?: Options) => ({ } }); -export const apiVVersionODataControllerCountKey = (options?: Options) => ["/api/v{api-version}/simple/$count"]; +export const apiVVersionODataControllerCountKey = () => ["/api/v{api-version}/simple/$count"]; export const apiVVersionODataControllerCountOptions = (options?: Options) => ({ - key: apiVVersionODataControllerCountKey(options), + key: apiVVersionODataControllerCountKey(), fetcher: async () => { const { data } = await apiVVersionODataControllerCount({ ...options, throwOnError: true }); return data; @@ -92,10 +92,10 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Options } }); -export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; +export const getCallWithoutParametersAndResponseKey = () => ["/api/v{api-version}/simple"]; export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ - key: getCallWithoutParametersAndResponseKey(options), + key: getCallWithoutParametersAndResponseKey(), fetcher: async () => { const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); return data; @@ -228,7 +228,15 @@ export const getCallWithOptionalParamOptions = (options: Options) => ({ - getKey: (pageIndex: number, previousPageData: unknown | null) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], + getKey: /** + * To implement pagination stop conditions, wrap this function and check previousPageData. + * Example: + * const getKey = (pageIndex: number, previousPageData: ResponseType | null) => { + * if (previousPageData && !previousPageData.hasMore) return null; + * return baseGetKey(pageIndex); + * }; + */ + (pageIndex: number) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], fetcher: async (key: readonly [string, Options]) => { const { data } = await getCallWithOptionalParam({ ...key[1], throwOnError: true }); return data; @@ -329,10 +337,10 @@ export const duplicateNameMutation = (options?: Options) => ( } }); -export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; +export const duplicateName2Key = () => ["/api/v{api-version}/duplicate"]; export const duplicateName2Options = (options?: Options) => ({ - key: duplicateName2Key(options), + key: duplicateName2Key(), fetcher: async () => { const { data } = await duplicateName2({ ...options, throwOnError: true }); return data; @@ -367,50 +375,50 @@ export const duplicateName4Mutation = (options?: Options) => } }); -export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; +export const callWithNoContentResponseKey = () => ["/api/v{api-version}/no-content"]; export const callWithNoContentResponseOptions = (options?: Options) => ({ - key: callWithNoContentResponseKey(options), + key: callWithNoContentResponseKey(), fetcher: async () => { const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; +export const callWithResponseAndNoContentResponseKey = () => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ - key: callWithResponseAndNoContentResponseKey(options), + key: callWithResponseAndNoContentResponseKey(), fetcher: async () => { const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; +export const dummyAKey = () => ["/api/v{api-version}/multiple-tags/a"]; export const dummyAOptions = (options?: Options) => ({ - key: dummyAKey(options), + key: dummyAKey(), fetcher: async () => { const { data } = await dummyA({ ...options, throwOnError: true }); return data; } }); -export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; +export const dummyBKey = () => ["/api/v{api-version}/multiple-tags/b"]; export const dummyBOptions = (options?: Options) => ({ - key: dummyBKey(options), + key: dummyBKey(), fetcher: async () => { const { data } = await dummyB({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; +export const callWithResponseKey = () => ["/api/v{api-version}/response"]; export const callWithResponseOptions = (options?: Options) => ({ - key: callWithResponseKey(options), + key: callWithResponseKey(), fetcher: async () => { const { data } = await callWithResponse({ ...options, throwOnError: true }); return data; @@ -499,10 +507,10 @@ export const complexTypesOptions = (options: Options) => ({ } }); -export const multipartResponseKey = (options?: Options) => ["/api/v{api-version}/multipart"]; +export const multipartResponseKey = () => ["/api/v{api-version}/multipart"]; export const multipartResponseOptions = (options?: Options) => ({ - key: multipartResponseKey(options), + key: multipartResponseKey(), fetcher: async () => { const { data } = await multipartResponse({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts index 60cc8a124f..392d9d7db1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/swr/fetch/swr.gen.ts @@ -6,10 +6,10 @@ import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const exportKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; +export const exportKey = () => ["/api/v{api-version}/no+tag"]; export const exportOptions = (options?: Options) => ({ - key: exportKey(options), + key: exportKey(), fetcher: async () => { const { data } = await export_({ ...options, throwOnError: true }); return data; @@ -58,10 +58,10 @@ export const fooWowMutation = (options?: Options) => ({ } }); -export const apiVVersionODataControllerCountKey = (options?: Options) => ["/api/v{api-version}/simple/$count"]; +export const apiVVersionODataControllerCountKey = () => ["/api/v{api-version}/simple/$count"]; export const apiVVersionODataControllerCountOptions = (options?: Options) => ({ - key: apiVVersionODataControllerCountKey(options), + key: apiVVersionODataControllerCountKey(), fetcher: async () => { const { data } = await apiVVersionODataControllerCount({ ...options, throwOnError: true }); return data; @@ -92,10 +92,10 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Options } }); -export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; +export const getCallWithoutParametersAndResponseKey = () => ["/api/v{api-version}/simple"]; export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ - key: getCallWithoutParametersAndResponseKey(options), + key: getCallWithoutParametersAndResponseKey(), fetcher: async () => { const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); return data; @@ -228,7 +228,15 @@ export const getCallWithOptionalParamOptions = (options: Options) => ({ - getKey: (pageIndex: number, previousPageData: unknown | null) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], + getKey: /** + * To implement pagination stop conditions, wrap this function and check previousPageData. + * Example: + * const getKey = (pageIndex: number, previousPageData: ResponseType | null) => { + * if (previousPageData && !previousPageData.hasMore) return null; + * return baseGetKey(pageIndex); + * }; + */ + (pageIndex: number) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], fetcher: async (key: readonly [string, Options]) => { const { data } = await getCallWithOptionalParam({ ...key[1], throwOnError: true }); return data; @@ -329,10 +337,10 @@ export const duplicateNameMutation = (options?: Options) => ( } }); -export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; +export const duplicateName2Key = () => ["/api/v{api-version}/duplicate"]; export const duplicateName2Options = (options?: Options) => ({ - key: duplicateName2Key(options), + key: duplicateName2Key(), fetcher: async () => { const { data } = await duplicateName2({ ...options, throwOnError: true }); return data; @@ -367,50 +375,50 @@ export const duplicateName4Mutation = (options?: Options) => } }); -export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; +export const callWithNoContentResponseKey = () => ["/api/v{api-version}/no-content"]; export const callWithNoContentResponseOptions = (options?: Options) => ({ - key: callWithNoContentResponseKey(options), + key: callWithNoContentResponseKey(), fetcher: async () => { const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; +export const callWithResponseAndNoContentResponseKey = () => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ - key: callWithResponseAndNoContentResponseKey(options), + key: callWithResponseAndNoContentResponseKey(), fetcher: async () => { const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; +export const dummyAKey = () => ["/api/v{api-version}/multiple-tags/a"]; export const dummyAOptions = (options?: Options) => ({ - key: dummyAKey(options), + key: dummyAKey(), fetcher: async () => { const { data } = await dummyA({ ...options, throwOnError: true }); return data; } }); -export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; +export const dummyBKey = () => ["/api/v{api-version}/multiple-tags/b"]; export const dummyBOptions = (options?: Options) => ({ - key: dummyBKey(options), + key: dummyBKey(), fetcher: async () => { const { data } = await dummyB({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; +export const callWithResponseKey = () => ["/api/v{api-version}/response"]; export const callWithResponseOptions = (options?: Options) => ({ - key: callWithResponseKey(options), + key: callWithResponseKey(), fetcher: async () => { const { data } = await callWithResponse({ ...options, throwOnError: true }); return data; @@ -499,10 +507,10 @@ export const complexTypesOptions = (options: Options) => ({ } }); -export const multipartResponseKey = (options?: Options) => ["/api/v{api-version}/multipart"]; +export const multipartResponseKey = () => ["/api/v{api-version}/multipart"]; export const multipartResponseOptions = (options?: Options) => ({ - key: multipartResponseKey(options), + key: multipartResponseKey(), fetcher: async () => { const { data } = await multipartResponse({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts index 33cb83c8c5..40fd9a0bb5 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/asClass/swr.gen.ts @@ -6,10 +6,10 @@ import type { FooBarPostData, FooBarPutData, FooPostData, FooPutData, GetFooBarD /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const getFooKey = (options?: Options) => ["/foo"]; +export const getFooKey = () => ["/foo"]; export const getFooOptions = (options?: Options) => ({ - key: getFooKey(options), + key: getFooKey(), fetcher: async () => { const { data } = await FooBazService.getFoo({ ...options, throwOnError: true }); return data; @@ -44,10 +44,10 @@ export const fooPutMutation = (options?: Options) => ({ } }); -export const getFooBarKey = (options?: Options) => ["/foo/bar"]; +export const getFooBarKey = () => ["/foo/bar"]; export const getFooBarOptions = (options?: Options) => ({ - key: getFooBarKey(options), + key: getFooBarKey(), fetcher: async () => { const { data } = await BarBazService.getFooBar({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts index 60cc8a124f..392d9d7db1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/axios/swr.gen.ts @@ -6,10 +6,10 @@ import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const exportKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; +export const exportKey = () => ["/api/v{api-version}/no+tag"]; export const exportOptions = (options?: Options) => ({ - key: exportKey(options), + key: exportKey(), fetcher: async () => { const { data } = await export_({ ...options, throwOnError: true }); return data; @@ -58,10 +58,10 @@ export const fooWowMutation = (options?: Options) => ({ } }); -export const apiVVersionODataControllerCountKey = (options?: Options) => ["/api/v{api-version}/simple/$count"]; +export const apiVVersionODataControllerCountKey = () => ["/api/v{api-version}/simple/$count"]; export const apiVVersionODataControllerCountOptions = (options?: Options) => ({ - key: apiVVersionODataControllerCountKey(options), + key: apiVVersionODataControllerCountKey(), fetcher: async () => { const { data } = await apiVVersionODataControllerCount({ ...options, throwOnError: true }); return data; @@ -92,10 +92,10 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Options } }); -export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; +export const getCallWithoutParametersAndResponseKey = () => ["/api/v{api-version}/simple"]; export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ - key: getCallWithoutParametersAndResponseKey(options), + key: getCallWithoutParametersAndResponseKey(), fetcher: async () => { const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); return data; @@ -228,7 +228,15 @@ export const getCallWithOptionalParamOptions = (options: Options) => ({ - getKey: (pageIndex: number, previousPageData: unknown | null) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], + getKey: /** + * To implement pagination stop conditions, wrap this function and check previousPageData. + * Example: + * const getKey = (pageIndex: number, previousPageData: ResponseType | null) => { + * if (previousPageData && !previousPageData.hasMore) return null; + * return baseGetKey(pageIndex); + * }; + */ + (pageIndex: number) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], fetcher: async (key: readonly [string, Options]) => { const { data } = await getCallWithOptionalParam({ ...key[1], throwOnError: true }); return data; @@ -329,10 +337,10 @@ export const duplicateNameMutation = (options?: Options) => ( } }); -export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; +export const duplicateName2Key = () => ["/api/v{api-version}/duplicate"]; export const duplicateName2Options = (options?: Options) => ({ - key: duplicateName2Key(options), + key: duplicateName2Key(), fetcher: async () => { const { data } = await duplicateName2({ ...options, throwOnError: true }); return data; @@ -367,50 +375,50 @@ export const duplicateName4Mutation = (options?: Options) => } }); -export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; +export const callWithNoContentResponseKey = () => ["/api/v{api-version}/no-content"]; export const callWithNoContentResponseOptions = (options?: Options) => ({ - key: callWithNoContentResponseKey(options), + key: callWithNoContentResponseKey(), fetcher: async () => { const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; +export const callWithResponseAndNoContentResponseKey = () => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ - key: callWithResponseAndNoContentResponseKey(options), + key: callWithResponseAndNoContentResponseKey(), fetcher: async () => { const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; +export const dummyAKey = () => ["/api/v{api-version}/multiple-tags/a"]; export const dummyAOptions = (options?: Options) => ({ - key: dummyAKey(options), + key: dummyAKey(), fetcher: async () => { const { data } = await dummyA({ ...options, throwOnError: true }); return data; } }); -export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; +export const dummyBKey = () => ["/api/v{api-version}/multiple-tags/b"]; export const dummyBOptions = (options?: Options) => ({ - key: dummyBKey(options), + key: dummyBKey(), fetcher: async () => { const { data } = await dummyB({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; +export const callWithResponseKey = () => ["/api/v{api-version}/response"]; export const callWithResponseOptions = (options?: Options) => ({ - key: callWithResponseKey(options), + key: callWithResponseKey(), fetcher: async () => { const { data } = await callWithResponse({ ...options, throwOnError: true }); return data; @@ -499,10 +507,10 @@ export const complexTypesOptions = (options: Options) => ({ } }); -export const multipartResponseKey = (options?: Options) => ["/api/v{api-version}/multipart"]; +export const multipartResponseKey = () => ["/api/v{api-version}/multipart"]; export const multipartResponseOptions = (options?: Options) => ({ - key: multipartResponseKey(options), + key: multipartResponseKey(), fetcher: async () => { const { data } = await multipartResponse({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts index 60cc8a124f..392d9d7db1 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/swr/fetch/swr.gen.ts @@ -6,10 +6,10 @@ import type { ApiVVersionODataControllerCountData, CallToTestOrderOfParamsData, /* eslint-disable @typescript-eslint/no-unused-vars */ ; -export const exportKey = (options?: Options) => ["/api/v{api-version}/no+tag"]; +export const exportKey = () => ["/api/v{api-version}/no+tag"]; export const exportOptions = (options?: Options) => ({ - key: exportKey(options), + key: exportKey(), fetcher: async () => { const { data } = await export_({ ...options, throwOnError: true }); return data; @@ -58,10 +58,10 @@ export const fooWowMutation = (options?: Options) => ({ } }); -export const apiVVersionODataControllerCountKey = (options?: Options) => ["/api/v{api-version}/simple/$count"]; +export const apiVVersionODataControllerCountKey = () => ["/api/v{api-version}/simple/$count"]; export const apiVVersionODataControllerCountOptions = (options?: Options) => ({ - key: apiVVersionODataControllerCountKey(options), + key: apiVVersionODataControllerCountKey(), fetcher: async () => { const { data } = await apiVVersionODataControllerCount({ ...options, throwOnError: true }); return data; @@ -92,10 +92,10 @@ export const deleteCallWithoutParametersAndResponseMutation = (options?: Options } }); -export const getCallWithoutParametersAndResponseKey = (options?: Options) => ["/api/v{api-version}/simple"]; +export const getCallWithoutParametersAndResponseKey = () => ["/api/v{api-version}/simple"]; export const getCallWithoutParametersAndResponseOptions = (options?: Options) => ({ - key: getCallWithoutParametersAndResponseKey(options), + key: getCallWithoutParametersAndResponseKey(), fetcher: async () => { const { data } = await getCallWithoutParametersAndResponse({ ...options, throwOnError: true }); return data; @@ -228,7 +228,15 @@ export const getCallWithOptionalParamOptions = (options: Options) => ({ - getKey: (pageIndex: number, previousPageData: unknown | null) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], + getKey: /** + * To implement pagination stop conditions, wrap this function and check previousPageData. + * Example: + * const getKey = (pageIndex: number, previousPageData: ResponseType | null) => { + * if (previousPageData && !previousPageData.hasMore) return null; + * return baseGetKey(pageIndex); + * }; + */ + (pageIndex: number) => ["/api/v{api-version}/parameters", { ...options, query: { ...options.query, page: pageIndex } }], fetcher: async (key: readonly [string, Options]) => { const { data } = await getCallWithOptionalParam({ ...key[1], throwOnError: true }); return data; @@ -329,10 +337,10 @@ export const duplicateNameMutation = (options?: Options) => ( } }); -export const duplicateName2Key = (options?: Options) => ["/api/v{api-version}/duplicate"]; +export const duplicateName2Key = () => ["/api/v{api-version}/duplicate"]; export const duplicateName2Options = (options?: Options) => ({ - key: duplicateName2Key(options), + key: duplicateName2Key(), fetcher: async () => { const { data } = await duplicateName2({ ...options, throwOnError: true }); return data; @@ -367,50 +375,50 @@ export const duplicateName4Mutation = (options?: Options) => } }); -export const callWithNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/no-content"]; +export const callWithNoContentResponseKey = () => ["/api/v{api-version}/no-content"]; export const callWithNoContentResponseOptions = (options?: Options) => ({ - key: callWithNoContentResponseKey(options), + key: callWithNoContentResponseKey(), fetcher: async () => { const { data } = await callWithNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseAndNoContentResponseKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; +export const callWithResponseAndNoContentResponseKey = () => ["/api/v{api-version}/multiple-tags/response-and-no-content"]; export const callWithResponseAndNoContentResponseOptions = (options?: Options) => ({ - key: callWithResponseAndNoContentResponseKey(options), + key: callWithResponseAndNoContentResponseKey(), fetcher: async () => { const { data } = await callWithResponseAndNoContentResponse({ ...options, throwOnError: true }); return data; } }); -export const dummyAKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/a"]; +export const dummyAKey = () => ["/api/v{api-version}/multiple-tags/a"]; export const dummyAOptions = (options?: Options) => ({ - key: dummyAKey(options), + key: dummyAKey(), fetcher: async () => { const { data } = await dummyA({ ...options, throwOnError: true }); return data; } }); -export const dummyBKey = (options?: Options) => ["/api/v{api-version}/multiple-tags/b"]; +export const dummyBKey = () => ["/api/v{api-version}/multiple-tags/b"]; export const dummyBOptions = (options?: Options) => ({ - key: dummyBKey(options), + key: dummyBKey(), fetcher: async () => { const { data } = await dummyB({ ...options, throwOnError: true }); return data; } }); -export const callWithResponseKey = (options?: Options) => ["/api/v{api-version}/response"]; +export const callWithResponseKey = () => ["/api/v{api-version}/response"]; export const callWithResponseOptions = (options?: Options) => ({ - key: callWithResponseKey(options), + key: callWithResponseKey(), fetcher: async () => { const { data } = await callWithResponse({ ...options, throwOnError: true }); return data; @@ -499,10 +507,10 @@ export const complexTypesOptions = (options: Options) => ({ } }); -export const multipartResponseKey = (options?: Options) => ["/api/v{api-version}/multipart"]; +export const multipartResponseKey = () => ["/api/v{api-version}/multipart"]; export const multipartResponseOptions = (options?: Options) => ({ - key: multipartResponseKey(options), + key: multipartResponseKey(), fetcher: async () => { const { data } = await multipartResponse({ ...options, throwOnError: true }); return data; diff --git a/packages/openapi-ts-tests/main/test/plugins/swr/infinite.test.ts b/packages/openapi-ts-tests/main/test/plugins/swr/infinite.test.ts index c837777710..441a2c8631 100644 --- a/packages/openapi-ts-tests/main/test/plugins/swr/infinite.test.ts +++ b/packages/openapi-ts-tests/main/test/plugins/swr/infinite.test.ts @@ -58,7 +58,11 @@ describe('SWR Infinite Plugin', () => { if (fileContent.includes('Infinite =')) { expect(fileContent).toContain('getKey:'); expect(fileContent).toContain('pageIndex'); + // previousPageData should only appear in comments expect(fileContent).toContain('previousPageData'); + expect(fileContent).toContain( + 'To implement pagination stop conditions', + ); } } }); diff --git a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts index 9c9a660c42..139f956a46 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts @@ -1,5 +1,3 @@ -import ts from 'typescript'; - import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation'; import { stringCase } from '~/utils/stringCase'; @@ -15,28 +13,6 @@ import { createSwrOptions } from './swrOptions'; * It follows SWR's official recommended patterns for key design and data fetching. */ export const handlerV2: PluginHandler = ({ plugin }) => { - // Add file-level eslint-disable comment for unused vars - // This is more stable than adding inline comments which can be misplaced by formatters - const eslintDisableSymbol = plugin.registerSymbol({ - exported: false, - meta: { - category: 'utility', - resource: 'eslint-config', - }, - name: '__eslintDisable', - }); - - // Create an empty statement with the eslint-disable comment - const eslintDisableComment = ts.factory.createEmptyStatement(); - ts.addSyntheticLeadingComment( - eslintDisableComment, - ts.SyntaxKind.MultiLineCommentTrivia, - ' eslint-disable @typescript-eslint/no-unused-vars ', - true, - ); - - plugin.setSymbolValue(eslintDisableSymbol, eslintDisableComment); - // Register external symbols from axios (for error types) plugin.registerSymbol({ external: 'axios', diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts index ba716474a0..635f4e7e29 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts @@ -12,7 +12,7 @@ import type { TsDsl } from '~/ts-dsl'; import { $ } from '~/ts-dsl'; import type { PluginInstance } from '../types'; -import { useTypeData, useTypeResponse } from '../useType'; +import { useTypeData } from '../useType'; const optionsParamName = 'options'; @@ -24,8 +24,8 @@ const optionsParamName = 'options'; * - getKey: A function that generates SWR keys for each page * - fetcher: An async function that fetches a single page * - * The getKey function signature matches SWR's requirements: - * (pageIndex: number, previousPageData: ResponseType | null) => Key | null + * The getKey function signature is simplified to only accept pageIndex. + * Users should handle pagination stop conditions (using previousPageData) in their own code. * * The key structure uses object serialization (since SWR 1.1.0): * [path, { ...options, [paginationParam]: pageIndex }] @@ -41,7 +41,7 @@ const optionsParamName = 'options'; * * Without path params (optional): * export const getUsersInfinite = (options?: GetUsersData) => ({ - * getKey: (pageIndex: number, previousPageData: GetUsersResponse | null) => + * getKey: (pageIndex: number) => * ['/users', { ...options, query: { ...options?.query, page: pageIndex } }], * fetcher: async (key: readonly [string, GetUsersData]) => { * const { data } = await getUsers({ ...key[1], throwOnError: true }); @@ -51,7 +51,7 @@ const optionsParamName = 'options'; * * With path params (options required): * export const getOrgUsersInfinite = (options: GetOrgUsersData) => ({ - * getKey: (pageIndex: number, previousPageData: GetOrgUsersResponse | null) => + * getKey: (pageIndex: number) => * ['/orgs/{orgId}/users', { ...options, query: { ...options.query, page: pageIndex } }], * fetcher: async (key: readonly [string, GetOrgUsersData]) => { * const { data } = await getOrgUsers({ ...key[1], throwOnError: true }); @@ -59,9 +59,15 @@ const optionsParamName = 'options'; * } * }); * - * Note: The getKey function always returns a key array for each page. Use conditional - * logic within getKey (checking previousPageData) to stop pagination, not to disable - * the entire query. The key itself is never null - only returned when pagination ends. + * Note: To implement pagination stop conditions, you need to wrap the getKey function + * and check previousPageData. For example: + * + * const { getKey: baseGetKey, fetcher } = getUsersInfinite(); + * const getKey = (pageIndex: number, previousPageData: GetUsersResponse | null) => { + * if (previousPageData && !previousPageData.hasMore) return null; + * return baseGetKey(pageIndex); + * }; + * useSWRInfinite(getKey, fetcher); */ export const createSwrInfiniteOptions = ({ operation, @@ -93,12 +99,9 @@ export const createSwrInfiniteOptions = ({ }); const typeData = useTypeData({ operation, plugin }); - const typeResponse = useTypeResponse({ operation, plugin }); // Create the getKey function - // Following SWR's useSWRInfinite pattern with object serialization: - // getKey: (pageIndex: number, previousPageData: ResponseType | null) => Key | null - // + // Simplified signature that only accepts pageIndex // The getKey function returns: ['/path', { ...options, query: { ...query, page: pageIndex } }] // This leverages SWR 1.1.0+ automatic object serialization const getKeyStatements: Array> = []; @@ -147,8 +150,15 @@ export const createSwrInfiniteOptions = ({ const getKeyFunction = $.func() .param('pageIndex', (p) => p.type('number')) - .param('previousPageData', (p) => p.type(`${typeResponse} | null`)) - .do(...getKeyStatements); + .do(...getKeyStatements) + .describe([ + 'To implement pagination stop conditions, wrap this function and check previousPageData.', + 'Example:', + ' const getKey = (pageIndex: number, previousPageData: ResponseType | null) => {', + ' if (previousPageData && !previousPageData.hasMore) return null;', + ' return baseGetKey(pageIndex);', + ' };', + ]); const getKeyNode = getKeyFunction.$render(); diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts b/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts index 62a4ad3ee6..f3e5356dd6 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts @@ -69,13 +69,16 @@ export const swrKeyStatement = ({ ]); } + const funcBuilder = $.func(); + + // Only add options parameter if there are actual parameters + if (hasParams) { + funcBuilder.param('options', (p) => p.optional(!isRequired).type(typeData)); + } + const statement = $.const(symbol.placeholder) .export(symbol.exported) - .assign( - $.func() - .param('options', (p) => p.optional(!isRequired).type(typeData)) - .do($(keyExpression).return()), - ); + .assign(funcBuilder.do($(keyExpression).return())); return statement.$render(); }; diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts index f2bd327958..06604507d7 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts @@ -71,6 +71,13 @@ export const createSwrOptions = ({ const typeData = useTypeData({ operation, plugin }); + // Check if operation has parameters + const hasParams = + (operation.parameters?.path && + Object.keys(operation.parameters.path).length > 0) || + (operation.parameters?.query && + Object.keys(operation.parameters.query).length > 0); + // Create the SDK function call const awaitSdkFn = $(sdkFn) .call( @@ -89,10 +96,15 @@ export const createSwrOptions = ({ ); } + // Build the key call - only pass options if operation has parameters + const keyCall = hasParams + ? $(symbolSwrKey.placeholder).call(optionsParamName) + : $(symbolSwrKey.placeholder).call(); + // Build the options object const swrOptionsObj = $.object() .pretty() - .prop('key', $(symbolSwrKey.placeholder).call(optionsParamName)) + .prop('key', keyCall) .prop( 'fetcher', $.func() From 0e4b801801eec9afd8ae691110137a390abedb5b Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 17 Nov 2025 01:23:17 +0800 Subject: [PATCH 9/9] refactor: clean up config --- dev/openapi-ts.config.ts | 4 +- packages/openapi-ts/src/plugins/swr/config.ts | 28 ++++------ packages/openapi-ts/src/plugins/swr/plugin.ts | 10 +--- .../openapi-ts/src/plugins/swr/types.d.ts | 56 ++----------------- .../openapi-ts/src/plugins/swr/useType.ts | 8 +-- .../openapi-ts/src/plugins/swr/v2/plugin.ts | 4 +- .../src/plugins/swr/v2/swrInfiniteOptions.ts | 7 +-- .../openapi-ts/src/plugins/swr/v2/swrKey.ts | 6 +- .../src/plugins/swr/v2/swrMutationOptions.ts | 6 +- .../src/plugins/swr/v2/swrOptions.ts | 6 +- 10 files changed, 37 insertions(+), 98 deletions(-) diff --git a/dev/openapi-ts.config.ts b/dev/openapi-ts.config.ts index d4cc848c61..a9170ab8b9 100644 --- a/dev/openapi-ts.config.ts +++ b/dev/openapi-ts.config.ts @@ -41,9 +41,9 @@ export default defineConfig(() => { // 'dutchie.json', // 'invalid', // 'full.yaml', - // 'openai.yaml', + 'openai.yaml', // 'opencode.yaml', - 'pagination-ref.yaml', + // 'pagination-ref.yaml', // 'sdk-instance.yaml', // 'string-with-format.yaml', // 'transformers.json', diff --git a/packages/openapi-ts/src/plugins/swr/config.ts b/packages/openapi-ts/src/plugins/swr/config.ts index 33f3be339c..3b88f420d8 100644 --- a/packages/openapi-ts/src/plugins/swr/config.ts +++ b/packages/openapi-ts/src/plugins/swr/config.ts @@ -10,47 +10,41 @@ export const defaultConfig: SwrPlugin['Config'] = { exportFromIndex: false, }, dependencies: ['@hey-api/sdk', '@hey-api/typescript'], - handler: handler as SwrPlugin['Handler'], + handler, name: 'swr', resolveConfig: (plugin, context) => { - // Resolve swrKeys configuration - plugin.config.swrKeys = context.valueToObject({ + plugin.config.swrInfiniteOptions = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, - exported: true, - name: '{{name}}Key', + name: '{{name}}Infinite', }, mappers: { boolean: (enabled) => ({ enabled }), function: (name) => ({ name }), string: (name) => ({ name }), }, - value: plugin.config.swrKeys, + value: plugin.config.swrInfiniteOptions, }); - // Resolve swrOptions configuration - plugin.config.swrOptions = context.valueToObject({ + plugin.config.swrKeys = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, - exported: true, - name: '{{name}}Options', + name: '{{name}}Key', }, mappers: { boolean: (enabled) => ({ enabled }), function: (name) => ({ name }), string: (name) => ({ name }), }, - value: plugin.config.swrOptions, + value: plugin.config.swrKeys, }); - // Resolve swrMutationOptions configuration plugin.config.swrMutationOptions = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, - exported: true, name: '{{name}}Mutation', }, mappers: { @@ -61,20 +55,18 @@ export const defaultConfig: SwrPlugin['Config'] = { value: plugin.config.swrMutationOptions, }); - // Resolve swrInfiniteOptions configuration - plugin.config.swrInfiniteOptions = context.valueToObject({ + plugin.config.swrOptions = context.valueToObject({ defaultValue: { case: plugin.config.case ?? 'camelCase', enabled: true, - exported: true, - name: '{{name}}Infinite', + name: '{{name}}Options', }, mappers: { boolean: (enabled) => ({ enabled }), function: (name) => ({ name }), string: (name) => ({ name }), }, - value: plugin.config.swrInfiniteOptions, + value: plugin.config.swrOptions, }); }, }; diff --git a/packages/openapi-ts/src/plugins/swr/plugin.ts b/packages/openapi-ts/src/plugins/swr/plugin.ts index 0bdd89f7d1..d5ebb4d113 100644 --- a/packages/openapi-ts/src/plugins/swr/plugin.ts +++ b/packages/openapi-ts/src/plugins/swr/plugin.ts @@ -1,10 +1,4 @@ -import type { PluginHandler } from './types'; +import type { SwrPlugin } from './types'; import { handlerV2 } from './v2/plugin'; -/** - * Main handler for the SWR plugin. - * - * This plugin generates useSWR and useSWRMutation options for each operation. - * It follows SWR's official recommended patterns for key design and data fetching. - */ -export const handler: PluginHandler = handlerV2; +export const handler: SwrPlugin['Handler'] = (args) => handlerV2(args); diff --git a/packages/openapi-ts/src/plugins/swr/types.d.ts b/packages/openapi-ts/src/plugins/swr/types.d.ts index 559d800905..1c67a2d11b 100644 --- a/packages/openapi-ts/src/plugins/swr/types.d.ts +++ b/packages/openapi-ts/src/plugins/swr/types.d.ts @@ -12,6 +12,11 @@ export type UserConfig = Plugin.Name<'swr'> & /** * Add comments from SDK functions to the generated SWR code? * + * Duplicating comments this way is useful so you don't need to drill into + * the underlying SDK function to learn what it does or whether it's + * deprecated. You can set this option to `false` if you prefer less + * comment duplication. + * * @default true */ comments?: boolean; @@ -48,12 +53,6 @@ export type UserConfig = Plugin.Name<'swr'> & * @default true */ enabled?: boolean; - /** - * Whether to export generated symbols. - * - * @default true - */ - exported?: boolean; /** * Custom naming pattern for generated useSWRInfinite options names. The name variable is * obtained from the SDK function name. @@ -88,12 +87,6 @@ export type UserConfig = Plugin.Name<'swr'> & * @default true */ enabled?: boolean; - /** - * Whether to export generated symbols. - * - * @default true - */ - exported?: boolean; /** * Custom naming pattern for generated SWR key names. The name variable is * obtained from the SDK function name. @@ -128,12 +121,6 @@ export type UserConfig = Plugin.Name<'swr'> & * @default true */ enabled?: boolean; - /** - * Whether to export generated symbols. - * - * @default true - */ - exported?: boolean; /** * Custom naming pattern for generated useSWRMutation options names. The name variable is * obtained from the SDK function name. @@ -168,12 +155,6 @@ export type UserConfig = Plugin.Name<'swr'> & * @default true */ enabled?: boolean; - /** - * Whether to export generated symbols. - * - * @default true - */ - exported?: boolean; /** * Custom naming pattern for generated useSWR options names. The name variable is * obtained from the SDK function name. @@ -220,12 +201,6 @@ export type Config = Plugin.Name<'swr'> & * @default true */ enabled: boolean; - /** - * Whether to export generated symbols. - * - * @default true - */ - exported: boolean; /** * Custom naming pattern for generated useSWRInfinite options names. The name variable is obtained from the SDK function name. * @@ -249,12 +224,6 @@ export type Config = Plugin.Name<'swr'> & * @default true */ enabled: boolean; - /** - * Whether to export generated symbols. - * - * @default true - */ - exported: boolean; /** * Custom naming pattern for generated SWR key names. The name variable is obtained from the SDK function name. * @@ -278,12 +247,6 @@ export type Config = Plugin.Name<'swr'> & * @default true */ enabled: boolean; - /** - * Whether to export generated symbols. - * - * @default true - */ - exported: boolean; /** * Custom naming pattern for generated useSWRMutation options names. The name variable is obtained from the SDK function name. * @@ -307,12 +270,6 @@ export type Config = Plugin.Name<'swr'> & * @default true */ enabled: boolean; - /** - * Whether to export generated symbols. - * - * @default true - */ - exported: boolean; /** * Custom naming pattern for generated useSWR options names. The name variable is obtained from the SDK function name. * @@ -323,6 +280,3 @@ export type Config = Plugin.Name<'swr'> & }; export type SwrPlugin = DefinePlugin; - -export type PluginHandler = SwrPlugin['Handler']; -export type PluginInstance = Plugin.Instance; diff --git a/packages/openapi-ts/src/plugins/swr/useType.ts b/packages/openapi-ts/src/plugins/swr/useType.ts index 520a8397fc..2f759c882a 100644 --- a/packages/openapi-ts/src/plugins/swr/useType.ts +++ b/packages/openapi-ts/src/plugins/swr/useType.ts @@ -2,14 +2,14 @@ import type { IR } from '~/ir/types'; import { getClientPlugin } from '~/plugins/@hey-api/client-core/utils'; import { operationOptionsType } from '~/plugins/@hey-api/sdk/shared/operation'; -import type { PluginInstance } from './types'; +import type { SwrPlugin } from './types'; export const useTypeData = ({ operation, plugin, }: { operation: IR.OperationObject; - plugin: PluginInstance; + plugin: SwrPlugin['Instance']; }): string => { const pluginSdk = plugin.getPluginOrThrow('@hey-api/sdk'); const typeData = operationOptionsType({ operation, plugin: pluginSdk }); @@ -21,7 +21,7 @@ export const useTypeError = ({ plugin, }: { operation: IR.OperationObject; - plugin: PluginInstance; + plugin: SwrPlugin['Instance']; }): string => { const client = getClientPlugin(plugin.context.config); @@ -51,7 +51,7 @@ export const useTypeResponse = ({ plugin, }: { operation: IR.OperationObject; - plugin: PluginInstance; + plugin: SwrPlugin['Instance']; }): string => { const symbolResponseType = plugin.querySymbol({ category: 'type', diff --git a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts index 139f956a46..8e85f4481a 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/plugin.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/plugin.ts @@ -1,7 +1,7 @@ import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation'; import { stringCase } from '~/utils/stringCase'; -import type { PluginHandler } from '../types'; +import type { SwrPlugin } from '../types'; import { createSwrInfiniteOptions } from './swrInfiniteOptions'; import { createSwrMutationOptions } from './swrMutationOptions'; import { createSwrOptions } from './swrOptions'; @@ -12,7 +12,7 @@ import { createSwrOptions } from './swrOptions'; * This plugin generates useSWR and useSWRMutation options for each operation. * It follows SWR's official recommended patterns for key design and data fetching. */ -export const handlerV2: PluginHandler = ({ plugin }) => { +export const handlerV2: SwrPlugin['Handler'] = ({ plugin }) => { // Register external symbols from axios (for error types) plugin.registerSymbol({ external: 'axios', diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts index ebd89f0698..343cf68e47 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrInfiniteOptions.ts @@ -11,7 +11,7 @@ import { import type { TsDsl } from '~/ts-dsl'; import { $ } from '~/ts-dsl'; -import type { PluginInstance } from '../types'; +import type { SwrPlugin } from '../types'; import { useTypeData } from '../useType'; const optionsParamName = 'options'; @@ -75,7 +75,7 @@ export const createSwrInfiniteOptions = ({ sdkFn, }: { operation: IR.OperationObject; - plugin: PluginInstance; + plugin: SwrPlugin['Instance']; sdkFn: string; }): void => { if (hasOperationSse({ operation })) { @@ -198,9 +198,8 @@ export const createSwrInfiniteOptions = ({ .prop('getKey', $(getKeyNode)) .prop('fetcher', fetcherFunction); - // Register the infinite options symbol const symbolSwrInfiniteOptionsFn = plugin.registerSymbol({ - exported: plugin.config.swrInfiniteOptions.exported, + exported: true, meta: { category: 'hook', resource: 'operation', diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts b/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts index f3e5356dd6..af4d8ea1f2 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrKey.ts @@ -6,7 +6,7 @@ import type { IR } from '~/ir/types'; import { buildName } from '~/openApi/shared/utils/name'; import { $ } from '~/ts-dsl'; -import type { PluginInstance } from '../types'; +import type { SwrPlugin } from '../types'; import { useTypeData } from '../useType'; /** @@ -34,7 +34,7 @@ export const swrKeyStatement = ({ symbol, }: { operation: IR.OperationObject; - plugin: PluginInstance; + plugin: SwrPlugin['Instance']; symbol: Symbol; }) => { const typeData = useTypeData({ operation, plugin }); @@ -91,7 +91,7 @@ export const registerSwrKey = ({ plugin, }: { operation: IR.OperationObject; - plugin: PluginInstance; + plugin: SwrPlugin['Instance']; }): Symbol => { const symbol = plugin.registerSymbol({ exported: true, diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts index 38679b3f90..b0c06eae47 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrMutationOptions.ts @@ -6,7 +6,7 @@ import { createOperationComment } from '~/plugins/shared/utils/operation'; import type { TsDsl } from '~/ts-dsl'; import { $ } from '~/ts-dsl'; -import type { PluginInstance } from '../types'; +import type { SwrPlugin } from '../types'; import { useTypeData } from '../useType'; const optionsParamName = 'options'; @@ -42,7 +42,7 @@ export const createSwrMutationOptions = ({ sdkFn, }: { operation: IR.OperationObject; - plugin: PluginInstance; + plugin: SwrPlugin['Instance']; sdkFn: string; }): void => { const typeData = useTypeData({ operation, plugin }); @@ -130,7 +130,7 @@ export const createSwrMutationOptions = ({ // Register the mutation options symbol const symbolSwrMutationOptionsFn = plugin.registerSymbol({ - exported: plugin.config.swrMutationOptions.exported, + exported: true, meta: { category: 'hook', resource: 'operation', diff --git a/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts b/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts index 48d69acac1..146984cec7 100644 --- a/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts +++ b/packages/openapi-ts/src/plugins/swr/v2/swrOptions.ts @@ -8,7 +8,7 @@ import { import type { TsDsl } from '~/ts-dsl'; import { $ } from '~/ts-dsl'; -import type { PluginInstance } from '../types'; +import type { SwrPlugin } from '../types'; import { useTypeData } from '../useType'; import { registerSwrKey } from './swrKey'; @@ -54,7 +54,7 @@ export const createSwrOptions = ({ sdkFn, }: { operation: IR.OperationObject; - plugin: PluginInstance; + plugin: SwrPlugin['Instance']; sdkFn: string; }): void => { if (hasOperationSse({ operation })) { @@ -114,7 +114,7 @@ export const createSwrOptions = ({ // Register the options symbol const symbolSwrOptionsFn = plugin.registerSymbol({ - exported: plugin.config.swrOptions.exported, + exported: true, meta: { category: 'hook', resource: 'operation',