diff --git a/.changeset/modern-colts-hang.md b/.changeset/modern-colts-hang.md new file mode 100644 index 000000000..1c17966fe --- /dev/null +++ b/.changeset/modern-colts-hang.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +feat(plugin): add `@pinia/colada` plugin diff --git a/.changeset/olive-pots-rest.md b/.changeset/olive-pots-rest.md new file mode 100644 index 000000000..75fc6ff34 --- /dev/null +++ b/.changeset/olive-pots-rest.md @@ -0,0 +1,23 @@ +--- +'@hey-api/openapi-ts': minor +--- + +feat(parser): add Hooks API + +### Added Hooks API + +This release adds the [Hooks API](https://heyapi.dev/openapi-ts/configuration/parser#hooks), giving you granular control over which operations generate queries and mutations. As a result, we tightened the previous behavior and POST operations no longer generate queries by default. To preserve the old behavior, add a custom matcher. + +```js +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + parser: { + hooks: { + operations: { + isQuery: (op) => (op.method === 'post' ? true : undefined), + }, + }, + }, +}; +``` diff --git a/docs/.vitepress/config/en.ts b/docs/.vitepress/config/en.ts index 53b22921f..d9e5b4c4b 100644 --- a/docs/.vitepress/config/en.ts +++ b/docs/.vitepress/config/en.ts @@ -173,12 +173,12 @@ export default defineConfig({ collapsed: true, items: [ { - link: '/openapi-ts/plugins/tanstack-query', - text: 'TanStack Query', + link: '/openapi-ts/plugins/pinia-colada', + text: 'Pinia Colada', }, { - link: '/openapi-ts/plugins/pinia-colada', - text: 'Pinia Colada soon', + link: '/openapi-ts/plugins/tanstack-query', + text: 'TanStack Query', }, { link: '/openapi-ts/plugins/swr', diff --git a/docs/data/people.ts b/docs/data/people.ts index 215f7f86d..662cb18a7 100644 --- a/docs/data/people.ts +++ b/docs/data/people.ts @@ -8,7 +8,17 @@ export const jacobCohen: Person = { name: 'Jacob Cohen', }; +export const joshHemphill: Person = { + github: 'https://github.com/josh-hemphill', + name: 'Josh Hemphill', +}; + export const maxScopp: Person = { github: 'https://github.com/max-scopp', name: 'Max Scopp', }; + +export const sebastiaanWouters: Person = { + github: 'https://github.com/SebastiaanWouters', + name: 'Sebastiaan Wouters', +}; diff --git a/docs/openapi-ts/configuration/parser.md b/docs/openapi-ts/configuration/parser.md index 87e99e088..d4cf7f3d4 100644 --- a/docs/openapi-ts/configuration/parser.md +++ b/docs/openapi-ts/configuration/parser.md @@ -18,9 +18,9 @@ You can add custom patches with `patch`. export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - patch: { // [!code ++] - schemas: { // [!code ++] + parser: { + patch: { + schemas: { Foo: (schema) => { // [!code ++] // convert date-time format to timestamp // [!code ++] delete schema.properties.updatedAt.format; // [!code ++] @@ -38,9 +38,9 @@ export default { // remove property // [!code ++] delete schema.properties.internalField; // [!code ++] }, // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` @@ -55,17 +55,15 @@ If you don't control or trust your input, you might want to validate it. Any det To validate your input, set `validate_EXPERIMENTAL` to `true`. - ```js export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] + parser: { validate_EXPERIMENTAL: true, // [!code ++] - }, // [!code ++] + }, }; ``` - ## Filters @@ -77,36 +75,33 @@ Set `include` to match operations to be included or `exclude` to match operation ::: code-group - ```js [include] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - operations: { // [!code ++] + parser: { + filters: { + operations: { include: ['GET /api/v1/foo', '/^[A-Z]+ /api/v1//'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - - + ```js [exclude] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - operations: { // [!code ++] + parser: { + filters: { + operations: { exclude: ['GET /api/v1/foo', '/^[A-Z]+ /api/v1//'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - ::: @@ -116,36 +111,33 @@ Set `include` to match tags to be included or `exclude` to match tags to be excl ::: code-group - ```js [include] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - tags: { // [!code ++] + parser: { + filters: { + tags: { include: ['v2'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - - + ```js [exclude] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - tags: { // [!code ++] + parser: { + filters: { + tags: { exclude: ['v1'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - ::: @@ -153,19 +145,17 @@ export default { You can filter out deprecated resources by setting `deprecated` to `false`. - ```js export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] + parser: { + filters: { deprecated: false, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, }; ``` - ### Schemas @@ -173,36 +163,33 @@ Set `include` to match schemas to be included or `exclude` to match schemas to b ::: code-group - ```js [include] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - schemas: { // [!code ++] + parser: { + filters: { + schemas: { include: ['Foo', '/^Bar/'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - - + ```js [exclude] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - schemas: { // [!code ++] + parser: { + filters: { + schemas: { exclude: ['Foo', '/^Bar/'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - ::: @@ -212,36 +199,33 @@ Set `include` to match parameters to be included or `exclude` to match parameter ::: code-group - ```js [include] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - parameters: { // [!code ++] + parser: { + filters: { + parameters: { include: ['QueryParameter', '/^MyQueryParameter/'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - - + ```js [exclude] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - parameters: { // [!code ++] + parser: { + filters: { + parameters: { exclude: ['QueryParameter', '/^MyQueryParameter/'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - ::: @@ -251,36 +235,33 @@ Set `include` to match request bodies to be included or `exclude` to match reque ::: code-group - ```js [include] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - requestBodies: { // [!code ++] + parser: { + filters: { + requestBodies: { include: ['Payload', '/^SpecialPayload/'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - - + ```js [exclude] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - requestBodies: { // [!code ++] + parser: { + filters: { + requestBodies: { exclude: ['Payload', '/^SpecialPayload/'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - ::: @@ -290,36 +271,33 @@ Set `include` to match responses to be included or `exclude` to match responses ::: code-group - ```js [include] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - responses: { // [!code ++] + parser: { + filters: { + responses: { include: ['Foo', '/^Bar/'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - - + ```js [exclude] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] - responses: { // [!code ++] + parser: { + filters: { + responses: { exclude: ['Foo', '/^Bar/'], // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - ::: @@ -327,37 +305,33 @@ export default { If you only want to exclude orphaned resources, set `orphans` to `false`. This is the default value when combined with any other filters. If this isn't the desired behavior, you may want to set `orphans` to `true` to always preserve unused resources. - ```js export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] + parser: { + filters: { orphans: false, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, }; ``` - ### Order For performance reasons, we don't preserve the original order when filtering out resources. If maintaining the original order is important to you, set `preserveOrder` to `true`. - ```js export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - filters: { // [!code ++] + parser: { + filters: { preserveOrder: true, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, }; ``` - ## Transforms @@ -374,32 +348,29 @@ You may want all enums to be reusable. This is because only root enums are typic ::: code-group - ```js [root] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - transforms: { // [!code ++] + parser: { + transforms: { enums: 'root', // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, }; ``` - - + ```js [inline] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - transforms: { // [!code ++] + parser: { + transforms: { enums: 'inline', // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, }; ``` - ::: @@ -411,35 +382,32 @@ Your schemas might contain read-only or write-only fields. Using such schemas di ::: code-group - ```js [default] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - transforms: { // [!code ++] - readWrite: { // [!code ++] + parser: { + transforms: { + readWrite: { requests: '{{name}}Writable', // [!code ++] responses: '{{name}}', // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, + }, }; ``` - - + ```js [disabled] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - transforms: { // [!code ++] + parser: { + transforms: { readWrite: false, // [!code ++] - }, // [!code ++] - }, // [!code ++] + }, + }, }; ``` - ::: @@ -453,31 +421,105 @@ You can provide custom pagination keywords using `pagination.keywords`. ::: code-group - ```js [extend] import { defaultPaginationKeywords } from '@hey-api/openapi-ts'; export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - pagination: { // [!code ++] - keywords: [...defaultPaginationKeywords, 'extra', 'pagination', 'keywords'], // [!code ++] - }, // [!code ++] - }, // [!code ++] + parser: { + pagination: { + keywords: [ + ...defaultPaginationKeywords, // [!code ++] + 'extra', // [!code ++] + 'pagination', // [!code ++] + 'keywords', // [!code ++] + ], + }, + }, +}; +``` + +```js [override] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + parser: { + pagination: { + keywords: [ + 'custom', // [!code ++] + 'pagination', // [!code ++] + 'keywords', // [!code ++] + ], + }, + }, +}; +``` + +::: + +## Hooks + +Hooks affect runtime behavior but aren’t tied to any single plugin. They can be configured globally via `parser.hooks` or per plugin through the `~hooks` property. + +### Operations {#hooks-operations} + +Each operation has a list of classifiers that can include `query`, `mutation`, both, or none. Plugins may use these values to decide whether to generate specific output. For example, you usually don’t want to generate [TanStack Query options](/openapi-ts/plugins/tanstack-query#queries) for PATCH operations. + +#### Query operations {#hooks-query-operations} + +By default, GET operations are classified as `query` operations. + +#### Mutation operations {#hooks-mutation-operations} + +By default, DELETE, PATCH, POST, and PUT operations are classified as `mutation` operations. + +#### Example: POST search query + +Imagine your API has a POST `/search` endpoint that accepts a large payload. By default, it's classified as a `mutation`, but in practice it behaves like a `query`, and your [state management](/openapi-ts/state-management) plugin should generate query hooks. + +You can fix this by classifying the operation as `query` in a matcher. If a matcher returns no value, we fall back to less specific matchers until one does. + +::: code-group + + +```js [parser] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + parser: { + hooks: { + operations: { + isQuery: (op) => { + if (op.method === 'post' && op.path === '/search') { // [!code ++] + return true; // [!code ++] + } // [!code ++] + }, + }, + }, + }, }; ``` -```js [override] +```js [plugin] export default { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', - parser: { // [!code ++] - pagination: { // [!code ++] - keywords: ['custom', 'pagination', 'keywords'], // [!code ++] - }, // [!code ++] - }, // [!code ++] + plugins: [ + { + name: '@tanstack/react-query', + '~hooks': { + operations: { + getKind: (op) => { + if (op.method === 'post' && op.path === '/search') { // [!code ++] + return ['query']; // [!code ++] + } // [!code ++] + }, + }, + }, + }, + ], }; ``` diff --git a/docs/openapi-ts/migrating.md b/docs/openapi-ts/migrating.md index 0df7073de..986cd23f3 100644 --- a/docs/openapi-ts/migrating.md +++ b/docs/openapi-ts/migrating.md @@ -7,6 +7,26 @@ description: Migrating to @hey-api/openapi-ts. While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. If you run into a problem with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues). +## v0.82.0 + +### Added Hooks API + +This release adds the [Hooks API](/openapi-ts/configuration/parser#hooks), giving you granular control over which operations generate queries and mutations. As a result, we tightened the previous behavior and POST operations no longer generate queries by default. To preserve the old behavior, add a custom matcher. + +```js +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + parser: { + hooks: { + operations: { + isQuery: (op) => (op.method === 'post' ? true : undefined), // [!code ++] + }, + }, + }, +}; +``` + ## v0.81.0 ### Server-Sent Events (SSE) diff --git a/docs/openapi-ts/plugins.md b/docs/openapi-ts/plugins.md index 09bad4ed6..321b66c47 100644 --- a/docs/openapi-ts/plugins.md +++ b/docs/openapi-ts/plugins.md @@ -20,12 +20,13 @@ Apart from being responsible for the default output, core plugins are the founda These plugins help reduce boilerplate associated with third-party dependencies. Hey API natively supports the most popular packages. Please open an issue on [GitHub](https://github.com/hey-api/openapi-ts/issues) if you'd like us to support your favorite package. +- [`@angular/common`](/openapi-ts/plugins/angular) +- [`@pinia/colada`](/openapi-ts/plugins/pinia-colada) - [`@tanstack/angular-query-experimental`](/openapi-ts/plugins/tanstack-query) - [`@tanstack/react-query`](/openapi-ts/plugins/tanstack-query) - [`@tanstack/solid-query`](/openapi-ts/plugins/tanstack-query) - [`@tanstack/svelte-query`](/openapi-ts/plugins/tanstack-query) - [`@tanstack/vue-query`](/openapi-ts/plugins/tanstack-query) -- [`@angular/common`](/openapi-ts/plugins/angular) - [`fastify`](/openapi-ts/plugins/fastify) - [`valibot`](/openapi-ts/plugins/valibot) - [`zod`](/openapi-ts/plugins/zod) @@ -47,7 +48,6 @@ The following plugins are planned but not in development yet. You can help us pr - [MSW](/openapi-ts/plugins/msw) Soon - [Nest](/openapi-ts/plugins/nest) Soon - [Nock](/openapi-ts/plugins/nock) Soon -- [Pinia Colada](/openapi-ts/plugins/pinia-colada) Soon - [Superstruct](/openapi-ts/plugins/superstruct) Soon - [Supertest](/openapi-ts/plugins/supertest) Soon - [SWR](/openapi-ts/plugins/swr) Soon diff --git a/docs/openapi-ts/plugins/pinia-colada.md b/docs/openapi-ts/plugins/pinia-colada.md index 1b44cf72c..d6aa4b15c 100644 --- a/docs/openapi-ts/plugins/pinia-colada.md +++ b/docs/openapi-ts/plugins/pinia-colada.md @@ -1,18 +1,221 @@ --- -title: Pinia Colada -description: Pinia Colada plugin for Hey API. Compatible with all our features. +title: Pinia Colada v0 Plugin +description: Generate Pinia Colada v0 functions and query keys from OpenAPI with the Pinia Colada plugin for openapi-ts. Fully compatible with validators, transformers, and all core features. --- -# Pinia Colada soon - - + +

Pinia Colada v0

+ +
### About -[Pinia Colada](https://pinia-colada.esm.dev) is the data fetching layer for Pinia. +[Pinia Colada](https://pinia-colada.esm.dev) is the perfect companion to Pinia to handle async state management in your Vue applications. + +The Pinia Colada plugin for Hey API generates functions and query keys from your OpenAPI spec, fully compatible with SDKs, transformers, and all core features. + +### Collaborators + + + +## Features + +- Pinia Colada v0 support +- seamless integration with `@hey-api/openapi-ts` ecosystem +- create query keys following the best practices +- type-safe query options and mutation options +- minimal learning curve thanks to extending the underlying technology + +## Installation + +In your [configuration](/openapi-ts/get-started), add `@pinia/colada` to your plugins and you'll be ready to generate Pinia Colada artifacts. :tada: + +```js +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + '@pinia/colada', // [!code ++] + ], +}; +``` + +## Output + +The Pinia Colada plugin will generate the following artifacts, depending on the input specification. + +## Queries + +Queries are generated from [query operations](/openapi-ts/configuration/parser#hooks-query-operations). The generated query functions follow the naming convention of SDK functions and by default append `Query`, e.g. `getPetByIdQuery()`. + +::: code-group + +```ts [example] +const { data, error } = useQuery({ + ...getPetByIdQuery({ + path: { + petId: 1, + }, + }), +}); +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@pinia/colada', + queryOptions: true, // [!code ++] + }, + ], +}; +``` + +::: + +You can customize the naming and casing pattern for `queryOptions` functions using the `.name` and `.case` options. + +### Meta + +You can use the `meta` field to attach arbitrary information to a query. To generate metadata for `queryOptions`, provide a function to the `.meta` option. + +::: code-group + +```ts [example] +queryOptions({ + // ...other fields + meta: { + id: 'getPetById', + }, +}); +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@pinia/colada', + queryOptions: { + meta: (operation) => ({ id: operation.id }), // [!code ++] + }, + }, + ], +}; +``` + +::: + +## Query Keys + +Query keys contain normalized SDK function parameters and additional metadata. + +::: code-group + +```ts [example] +const queryKey = [ + { + _id: 'getPetById', + baseUrl: 'https://app.heyapi.dev', + path: { + petId: 1, + }, + }, +]; +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@pinia/colada', + queryKeys: true, // [!code ++] + }, + ], +}; +``` + +::: + +### Accessing Query Keys + +If you have access to the result of query options function, you can get the query key from the `queryKey` field. + +::: code-group + +```ts [example] +const { queryKey } = getPetByIdOptions({ + path: { + petId: 1, + }, +}); +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@pinia/colada', + queryOptions: true, // [!code ++] + }, + ], +}; +``` + +::: + +Alternatively, you can access the same query key by calling query key functions. The generated query key functions follow the naming convention of SDK functions and by default append `QueryKey`, e.g. `getPetByIdQueryKey()`. + +::: code-group + +```ts [example] +const queryKey = getPetByIdQueryKey({ + path: { + petId: 1, + }, +}); +``` + +```js [config] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev + output: 'src/client', + plugins: [ + // ...other plugins + { + name: '@pinia/colada', + queryKeys: true, // [!code ++] + }, + ], +}; +``` + +::: + +You can customize the naming and casing pattern for `queryKeys` functions using the `.name` and `.case` options. + +## API + +You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@pinia/colada/types.d.ts) interface. + diff --git a/docs/openapi-ts/plugins/tanstack-query.md b/docs/openapi-ts/plugins/tanstack-query.md index 3ac4edcb2..13a6f6bc1 100644 --- a/docs/openapi-ts/plugins/tanstack-query.md +++ b/docs/openapi-ts/plugins/tanstack-query.md @@ -104,7 +104,7 @@ The TanStack Query plugin will generate the following artifacts, depending on th ## Queries -Queries are generated from GET and POST endpoints. The generated query functions follow the naming convention of SDK functions and by default append `Options`, e.g. `getPetByIdOptions()`. +Queries are generated from [query operations](/openapi-ts/configuration/parser#hooks-query-operations). The generated query functions follow the naming convention of SDK functions and by default append `Options`, e.g. `getPetByIdOptions()`. ::: code-group @@ -302,7 +302,7 @@ You can customize the naming and casing pattern for `queryKeys` functions using ## Infinite Queries -Infinite queries are generated from GET and POST endpoints if we detect a [pagination](/openapi-ts/configuration/parser#pagination) parameter. The generated infinite query functions follow the naming convention of SDK functions and by default append `InfiniteOptions`, e.g. `getFooInfiniteOptions()`. +Infinite queries are generated from [query operations](/openapi-ts/configuration/parser#hooks-query-operations) if we detect a [pagination](/openapi-ts/configuration/parser#pagination) parameter. The generated infinite query functions follow the naming convention of SDK functions and by default append `InfiniteOptions`, e.g. `getFooInfiniteOptions()`. ::: code-group @@ -504,7 +504,7 @@ You can customize the naming and casing pattern for `infiniteQueryKeys` function ## Mutations -Mutations are generated from DELETE, PATCH, POST, and PUT endpoints. The generated mutation functions follow the naming convention of SDK functions and by default append `Mutation`, e.g. `addPetMutation()`. +Mutations are generated from [mutation operations](/openapi-ts/configuration/parser#hooks-mutation-operations). The generated mutation functions follow the naming convention of SDK functions and by default append `Mutation`, e.g. `addPetMutation()`. ::: code-group diff --git a/docs/openapi-ts/state-management.md b/docs/openapi-ts/state-management.md index 69bad9488..c78f3c668 100644 --- a/docs/openapi-ts/state-management.md +++ b/docs/openapi-ts/state-management.md @@ -11,8 +11,8 @@ Any reasonably large application will have to deal with state management at some Hey API natively supports the following state managers. +- [Pinia Colada](/openapi-ts/plugins/pinia-colada) - [TanStack Query](/openapi-ts/plugins/tanstack-query) -- [Pinia Colada](/openapi-ts/plugins/pinia-colada) Soon - [SWR](/openapi-ts/plugins/swr) Soon - [Zustand](/openapi-ts/plugins/zustand) Soon diff --git a/examples/openapi-ts-pinia-colada/.eslintrc.cjs b/examples/openapi-ts-pinia-colada/.eslintrc.cjs new file mode 100644 index 000000000..ff3a044fa --- /dev/null +++ b/examples/openapi-ts-pinia-colada/.eslintrc.cjs @@ -0,0 +1,15 @@ +/* eslint-env node */ +require('@rushstack/eslint-patch/modern-module-resolution') + +module.exports = { + extends: [ + 'plugin:vue/vue3-essential', + 'eslint:recommended', + '@vue/eslint-config-typescript', + '@vue/eslint-config-prettier/skip-formatting' + ], + parserOptions: { + ecmaVersion: 'latest' + }, + root: true +} diff --git a/examples/openapi-ts-pinia-colada/.gitignore b/examples/openapi-ts-pinia-colada/.gitignore new file mode 100644 index 000000000..8ee54e8d3 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/.gitignore @@ -0,0 +1,30 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +.DS_Store +dist +dist-ssr +coverage +*.local + +/cypress/videos/ +/cypress/screenshots/ + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +*.tsbuildinfo diff --git a/examples/openapi-ts-pinia-colada/.prettierrc.json b/examples/openapi-ts-pinia-colada/.prettierrc.json new file mode 100644 index 000000000..ecdf3e07a --- /dev/null +++ b/examples/openapi-ts-pinia-colada/.prettierrc.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/prettierrc", + "semi": false, + "tabWidth": 2, + "singleQuote": true, + "printWidth": 100, + "trailingComma": "none" +} diff --git a/examples/openapi-ts-pinia-colada/.vscode/extensions.json b/examples/openapi-ts-pinia-colada/.vscode/extensions.json new file mode 100644 index 000000000..0449b97dc --- /dev/null +++ b/examples/openapi-ts-pinia-colada/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["Vue.volar", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] +} diff --git a/examples/openapi-ts-pinia-colada/README.md b/examples/openapi-ts-pinia-colada/README.md new file mode 100644 index 000000000..d75bfa3dc --- /dev/null +++ b/examples/openapi-ts-pinia-colada/README.md @@ -0,0 +1,45 @@ +# @hey-api/openapi-ts with Pinia Colada Example + +This example demonstrates how to use @hey-api/openapi-ts with Pinia Colada for Vue 3 applications. + +## Recommended IDE Setup + +[VSCode](https://code.visualstudio.com) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur). + +## Type Support for `.vue` Imports in TS + +TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types. + +## Customize configuration + +See [Vite Configuration Reference](https://vitejs.dev/config). + +## Project Setup + +```sh +pnpm install +``` + +### Compile and Hot-Reload for Development + +```sh +pnpm dev +``` + +### Type-Check, Compile and Minify for Production + +```sh +pnpm build +``` + +### Run Unit Tests with [Vitest](https://vitest.dev) + +```sh +pnpm test:unit +``` + +### Lint with [ESLint](https://eslint.org) + +```sh +pnpm lint +``` diff --git a/examples/openapi-ts-pinia-colada/env.d.ts b/examples/openapi-ts-pinia-colada/env.d.ts new file mode 100644 index 000000000..11f02fe2a --- /dev/null +++ b/examples/openapi-ts-pinia-colada/env.d.ts @@ -0,0 +1 @@ +/// diff --git a/examples/openapi-ts-pinia-colada/index.html b/examples/openapi-ts-pinia-colada/index.html new file mode 100644 index 000000000..768f3f81e --- /dev/null +++ b/examples/openapi-ts-pinia-colada/index.html @@ -0,0 +1,13 @@ + + + + + + + Hey API + Pinia Colada Demo + + +
+ + + diff --git a/examples/openapi-ts-pinia-colada/openapi-ts.config.ts b/examples/openapi-ts-pinia-colada/openapi-ts.config.ts new file mode 100644 index 000000000..7a00915a4 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/openapi-ts.config.ts @@ -0,0 +1,24 @@ +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' + }, + { + exportFromIndex: true, + name: '@pinia/colada' + } + ] +}) diff --git a/examples/openapi-ts-pinia-colada/package.json b/examples/openapi-ts-pinia-colada/package.json new file mode 100644 index 000000000..9718ddd69 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/package.json @@ -0,0 +1,50 @@ +{ + "name": "@example/openapi-ts-pinia-colada", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "build-only": "vite build", + "build": "run-p typecheck \"build-only {@}\" --", + "dev": "vite", + "format": "prettier --write src/", + "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", + "openapi-ts": "openapi-ts", + "preview": "vite preview", + "test:unit": "vitest", + "typecheck": "vue-tsc --build --force" + }, + "dependencies": { + "@pinia/colada": "0.17.2", + "pinia": "2.3.0", + "vue": "3.5.13", + "vue-router": "4.5.0" + }, + "devDependencies": { + "@config/vite-base": "workspace:*", + "@hey-api/openapi-ts": "workspace:*", + "@rushstack/eslint-patch": "1.10.5", + "@tsconfig/node20": "20.1.4", + "@types/jsdom": "21.1.7", + "@types/node": "22.10.5", + "@vitejs/plugin-vue": "5.2.1", + "@vitejs/plugin-vue-jsx": "4.1.1", + "@vue/eslint-config-prettier": "10.1.0", + "@vue/eslint-config-typescript": "14.2.0", + "@vue/test-utils": "2.4.6", + "@vue/tsconfig": "0.7.0", + "autoprefixer": "10.4.20", + "eslint": "9.17.0", + "eslint-plugin-vue": "9.32.0", + "jsdom": "23.0.0", + "npm-run-all2": "6.2.0", + "postcss": "8.4.41", + "prettier": "3.4.2", + "tailwindcss": "3.4.9", + "typescript": "5.8.3", + "vite": "7.1.2", + "vite-plugin-vue-devtools": "7.7.0", + "vitest": "3.1.1", + "vue-tsc": "2.2.0" + } +} diff --git a/examples/openapi-ts-pinia-colada/postcss.config.js b/examples/openapi-ts-pinia-colada/postcss.config.js new file mode 100644 index 000000000..9ed16a0e8 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/postcss.config.js @@ -0,0 +1,6 @@ +export default { + plugins: { + autoprefixer: {}, + tailwindcss: {} + } +} diff --git a/examples/openapi-ts-pinia-colada/src/App.vue b/examples/openapi-ts-pinia-colada/src/App.vue new file mode 100644 index 000000000..71749443b --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/App.vue @@ -0,0 +1,9 @@ + + + diff --git a/examples/openapi-ts-pinia-colada/src/assets/main.css b/examples/openapi-ts-pinia-colada/src/assets/main.css new file mode 100644 index 000000000..0a2ac6aac --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/assets/main.css @@ -0,0 +1,7 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +body { + @apply bg-[#111113]; +} diff --git a/examples/openapi-ts-pinia-colada/src/client/@pinia/colada.gen.ts b/examples/openapi-ts-pinia-colada/src/client/@pinia/colada.gen.ts new file mode 100644 index 000000000..21f009747 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/@pinia/colada.gen.ts @@ -0,0 +1,294 @@ +// 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 = () => ({ + mutation: async (options: Options) => { + const { data } = await addPet(options) + return data + } +}) + +/** + * Update an existing pet. + * Update an existing pet by Id. + */ +export const updatePetMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await updatePet(options) + return data + } +}) + +/** + * Finds Pets by status. + * Multiple status values can be provided with comma separated strings. + */ +export const findPetsByStatusQuery = (options: Options) => ({ + key: ['findPetsByStatus', options?.path], + query: async (context: { signal: AbortSignal }) => { + const { data } = await findPetsByStatus({ + ...options, + signal: context.signal, + throwOnError: true + }) + return data + } +}) + +/** + * Finds Pets by tags. + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + */ +export const findPetsByTagsQuery = (options: Options) => ({ + key: ['findPetsByTags', options?.path], + query: async (context: { signal: AbortSignal }) => { + const { data } = await findPetsByTags({ + ...options, + signal: context.signal, + throwOnError: true + }) + return data + } +}) + +/** + * Deletes a pet. + * Delete a pet. + */ +export const deletePetMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await deletePet(options) + return data + } +}) + +/** + * Find pet by ID. + * Returns a single pet. + */ +export const getPetByIdQuery = (options: Options) => ({ + key: ['getPetById', options?.path], + query: async (context: { signal: AbortSignal }) => { + const { data } = await getPetById({ + ...options, + signal: context.signal, + throwOnError: true + }) + return data + } +}) + +/** + * Updates a pet in the store with form data. + * Updates a pet resource based on the form data. + */ +export const updatePetWithFormMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await updatePetWithForm(options) + return data + } +}) + +/** + * Uploads an image. + * Upload image of the pet. + */ +export const uploadFileMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await uploadFile(options) + return data + } +}) + +/** + * Returns pet inventories by status. + * Returns a map of status codes to quantities. + */ +export const getInventoryQuery = (options?: Options) => ({ + key: ['getInventory', options?.path], + query: async (context: { signal: AbortSignal }) => { + const { data } = await getInventory({ + ...options, + signal: context.signal, + throwOnError: true + }) + return data + } +}) + +/** + * Place an order for a pet. + * Place a new order in the store. + */ +export const placeOrderMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await placeOrder(options) + return data + } +}) + +/** + * 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 = () => ({ + mutation: async (options: Options) => { + const { data } = await deleteOrder(options) + return data + } +}) + +/** + * Find purchase order by ID. + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. + */ +export const getOrderByIdQuery = (options: Options) => ({ + key: ['getOrderById', options?.path], + query: async (context: { signal: AbortSignal }) => { + const { data } = await getOrderById({ + ...options, + signal: context.signal, + throwOnError: true + }) + return data + } +}) + +/** + * Create user. + * This can only be done by the logged in user. + */ +export const createUserMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await createUser(options) + return data + } +}) + +/** + * Creates list of users with given input array. + * Creates list of users with given input array. + */ +export const createUsersWithListInputMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await createUsersWithListInput(options) + return data + } +}) + +/** + * Logs user into the system. + * Log into the system. + */ +export const loginUserQuery = (options?: Options) => ({ + key: ['loginUser', options?.path], + query: async (context: { signal: AbortSignal }) => { + const { data } = await loginUser({ + ...options, + signal: context.signal, + throwOnError: true + }) + return data + } +}) + +/** + * Logs out current logged in user session. + * Log user out of the system. + */ +export const logoutUserQuery = (options?: Options) => ({ + key: ['logoutUser', options?.path], + query: async (context: { signal: AbortSignal }) => { + const { data } = await logoutUser({ + ...options, + signal: context.signal, + throwOnError: true + }) + return data + } +}) + +/** + * Delete user resource. + * This can only be done by the logged in user. + */ +export const deleteUserMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await deleteUser(options) + return data + } +}) + +/** + * Get user by user name. + * Get user detail based on username. + */ +export const getUserByNameQuery = (options: Options) => ({ + key: ['getUserByName', options?.path], + query: async (context: { signal: AbortSignal }) => { + const { data } = await getUserByName({ + ...options, + signal: context.signal, + throwOnError: true + }) + return data + } +}) + +/** + * Update user resource. + * This can only be done by the logged in user. + */ +export const updateUserMutation = () => ({ + mutation: async (options: Options) => { + const { data } = await updateUser(options) + return data + } +}) diff --git a/examples/openapi-ts-pinia-colada/src/client/client.gen.ts b/examples/openapi-ts-pinia-colada/src/client/client.gen.ts new file mode 100644 index 000000000..1984dc18c --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/client.gen.ts @@ -0,0 +1,27 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { + type ClientOptions as DefaultClientOptions, + type Config, + createClient, + createConfig +} from './client' +import type { ClientOptions } 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-pinia-colada/src/client/client/client.gen.ts b/examples/openapi-ts-pinia-colada/src/client/client/client.gen.ts new file mode 100644 index 000000000..65910541f --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/client/client.gen.ts @@ -0,0 +1,225 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { createSseClient } from '../core/serverSentEvents.gen' +import type { HttpMethod } from '../core/types.gen' +import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen' +import { + buildUrl, + createConfig, + createInterceptors, + getParseAs, + mergeConfigs, + mergeHeaders, + setAuthParams +} from './utils.gen' + +type ReqInit = Omit & { + body?: any + headers: ReturnType +} + +export const createClient = (config: Config = {}): Client => { + let _config = mergeConfigs(createConfig(), config) + + const getConfig = (): Config => ({ ..._config }) + + const setConfig = (config: Config): Config => { + _config = mergeConfigs(_config, config) + return getConfig() + } + + const interceptors = createInterceptors() + + const beforeRequest = async (options: RequestOptions) => { + const opts = { + ..._config, + ...options, + fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, + headers: mergeHeaders(_config.headers, options.headers), + serializedBody: undefined + } + + if (opts.security) { + await setAuthParams({ + ...opts, + security: opts.security + }) + } + + if (opts.requestValidator) { + await opts.requestValidator(opts) + } + + if (opts.body && opts.bodySerializer) { + opts.serializedBody = opts.bodySerializer(opts.body) + } + + // remove Content-Type header if body is empty to avoid sending invalid requests + if (opts.serializedBody === 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: opts.serializedBody + } + + 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) { + if (response.status === 204 || response.headers.get('Content-Length') === '0') { + return opts.responseStyle === 'data' + ? {} + : { + data: {}, + ...result + } + } + + const parseAs = + (opts.parseAs === 'auto' + ? getParseAs(response.headers.get('Content-Type')) + : opts.parseAs) ?? 'json' + + 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, + 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-pinia-colada/src/client/client/index.ts b/examples/openapi-ts-pinia-colada/src/client/client/index.ts new file mode 100644 index 000000000..1b9721d0a --- /dev/null +++ b/examples/openapi-ts-pinia-colada/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 { createClient } from './client.gen' +export type { + Client, + ClientOptions, + Config, + CreateClientConfig, + Options, + OptionsLegacyParser, + RequestOptions, + RequestResult, + ResolvedRequestOptions, + ResponseStyle, + TDataShape +} from './types.gen' +export { createConfig, mergeHeaders } from './utils.gen' diff --git a/examples/openapi-ts-pinia-colada/src/client/client/types.gen.ts b/examples/openapi-ts-pinia-colada/src/client/client/types.gen.ts new file mode 100644 index 000000000..273baf786 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/client/types.gen.ts @@ -0,0 +1,226 @@ +// 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?: (request: Request) => ReturnType + /** + * 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>, 'method'> +) => RequestResult + +type BuildUrlFn = < + TData extends { + body?: unknown + path?: Record + query?: Record + url: string + } +>( + options: Pick & Options +) => string + +export type Client = CoreClient & { + interceptors: Middleware +} + +/** + * The `createClientConfig()` function will be called on client initialization + * and the returned object will become the client's initial configuration. + * + * You may want to initialize your client this way instead of calling + * `setConfig()`. This is useful for example if you're using Next.js + * to ensure your client always has the correct values. + */ +export type CreateClientConfig = ( + override?: Config +) => Config & T> + +export interface TDataShape { + body?: unknown + headers?: unknown + path?: unknown + query?: unknown + url: string +} + +type OmitKeys = Pick> + +export type Options< + TData extends TDataShape = TDataShape, + ThrowOnError extends boolean = boolean, + TResponse = unknown, + TResponseStyle extends ResponseStyle = 'fields' +> = OmitKeys< + RequestOptions, + 'body' | 'path' | 'query' | 'url' +> & + Omit + +export type OptionsLegacyParser< + TData = unknown, + ThrowOnError extends boolean = boolean, + TResponseStyle extends ResponseStyle = 'fields' +> = TData extends { body?: any } + ? TData extends { headers?: any } + ? OmitKeys, 'body' | 'headers' | 'url'> & + TData + : OmitKeys, 'body' | 'url'> & + TData & + Pick, 'headers'> + : TData extends { headers?: any } + ? OmitKeys, 'headers' | 'url'> & + TData & + Pick, 'body'> + : OmitKeys, 'url'> & TData diff --git a/examples/openapi-ts-pinia-colada/src/client/client/utils.gen.ts b/examples/openapi-ts-pinia-colada/src/client/client/utils.gen.ts new file mode 100644 index 000000000..f701b3d78 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/client/utils.gen.ts @@ -0,0 +1,310 @@ +// 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 = ({ + allowReserved, + array, + object +}: 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 + } + + if (Array.isArray(value)) { + const serializedArray = serializeArrayParam({ + allowReserved, + explode: true, + name, + style: 'form', + value, + ...array + }) + if (serializedArray) search.push(serializedArray) + } else if (typeof value === 'object') { + const serializedObject = serializeObjectParam({ + allowReserved, + explode: true, + name, + style: 'deepObject', + value: value as Record, + ...object + }) + if (serializedObject) search.push(serializedObject) + } else { + const serializedPrimitive = serializePrimitiveParam({ + 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 +} + +export const mergeHeaders = ( + ...headers: Array['headers'] | undefined> +): Headers => { + const mergedHeaders = new Headers() + for (const header of headers) { + if (!header || typeof header !== 'object') { + continue + } + + const iterator = header instanceof Headers ? header.entries() : 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: (Interceptor | null)[] + + constructor() { + this._fns = [] + } + + clear() { + this._fns = [] + } + + getInterceptorIndex(id: number | Interceptor): number { + if (typeof id === 'number') { + return this._fns[id] ? id : -1 + } else { + return this._fns.indexOf(id) + } + } + exists(id: number | Interceptor) { + const index = this.getInterceptorIndex(id) + return !!this._fns[index] + } + + eject(id: number | Interceptor) { + const index = this.getInterceptorIndex(id) + if (this._fns[index]) { + this._fns[index] = null + } + } + + update(id: number | Interceptor, fn: Interceptor) { + const index = this.getInterceptorIndex(id) + if (this._fns[index]) { + this._fns[index] = fn + return id + } else { + return false + } + } + + use(fn: Interceptor) { + this._fns = [...this._fns, fn] + return this._fns.length - 1 + } +} + +// `createInterceptors()` response, meant for external use as it does not +// expose internals +export interface Middleware { + error: Pick>, 'eject' | 'use'> + request: Pick>, 'eject' | 'use'> + response: Pick>, 'eject' | 'use'> +} + +// do not add `Middleware` as return type so we can use _fns internally +export const createInterceptors = () => ({ + 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-pinia-colada/src/client/core/auth.gen.ts b/examples/openapi-ts-pinia-colada/src/client/core/auth.gen.ts new file mode 100644 index 000000000..dc8ff6197 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/core/auth.gen.ts @@ -0,0 +1,41 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export type AuthToken = string | undefined + +export interface Auth { + /** + * Which part of the request do we use to send the auth? + * + * @default 'header' + */ + in?: 'header' | 'query' | 'cookie' + /** + * Header or query parameter name. + * + * @default 'Authorization' + */ + name?: string + scheme?: 'basic' | 'bearer' + type: 'apiKey' | 'http' +} + +export const getAuthToken = async ( + auth: Auth, + callback: ((auth: Auth) => Promise | AuthToken) | AuthToken +): Promise => { + const token = typeof callback === 'function' ? await callback(auth) : callback + + if (!token) { + return + } + + if (auth.scheme === 'bearer') { + return `Bearer ${token}` + } + + if (auth.scheme === 'basic') { + return `Basic ${btoa(token)}` + } + + return token +} diff --git a/examples/openapi-ts-pinia-colada/src/client/core/bodySerializer.gen.ts b/examples/openapi-ts-pinia-colada/src/client/core/bodySerializer.gen.ts new file mode 100644 index 000000000..e39c6a559 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/core/bodySerializer.gen.ts @@ -0,0 +1,76 @@ +// 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 + +export interface QuerySerializerOptions { + allowReserved?: boolean + array?: SerializerOptions + object?: SerializerOptions +} + +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-pinia-colada/src/client/core/params.gen.ts b/examples/openapi-ts-pinia-colada/src/client/core/params.gen.ts new file mode 100644 index 000000000..34dddb5fa --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/core/params.gen.ts @@ -0,0 +1,144 @@ +// 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 + } + +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 + } +> + +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 (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 + ;(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) { + const name = field.map || key + ;(params[field.in] as Record)[name] = 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 { + 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-pinia-colada/src/client/core/pathSerializer.gen.ts b/examples/openapi-ts-pinia-colada/src/client/core/pathSerializer.gen.ts new file mode 100644 index 000000000..acc13672e --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/core/pathSerializer.gen.ts @@ -0,0 +1,171 @@ +// This file is auto-generated by @hey-api/openapi-ts + +interface SerializeOptions extends SerializePrimitiveOptions, SerializerOptions {} + +interface SerializePrimitiveOptions { + allowReserved?: boolean + name: string +} + +export interface SerializerOptions { + /** + * @default true + */ + explode: boolean + style: T +} + +export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited' +export type ArraySeparatorStyle = ArrayStyle | MatrixStyle +type MatrixStyle = 'label' | 'matrix' | 'simple' +export type ObjectStyle = 'form' | 'deepObject' +type ObjectSeparatorStyle = ObjectStyle | MatrixStyle + +interface SerializePrimitiveParam extends SerializePrimitiveOptions { + value: string +} + +export const separatorArrayExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'label': + return '.' + case 'matrix': + return ';' + case 'simple': + return ',' + default: + return '&' + } +} + +export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => { + switch (style) { + case 'form': + return ',' + case 'pipeDelimited': + return '|' + case 'spaceDelimited': + return '%20' + default: + return ',' + } +} + +export const separatorObjectExplode = (style: ObjectSeparatorStyle) => { + switch (style) { + case 'label': + return '.' + case 'matrix': + return ';' + case 'simple': + return ',' + default: + return '&' + } +} + +export const serializeArrayParam = ({ + allowReserved, + explode, + name, + style, + value +}: SerializeOptions & { + value: unknown[] +}) => { + if (!explode) { + const joinedValues = ( + allowReserved ? value : value.map((v) => encodeURIComponent(v as string)) + ).join(separatorArrayNoExplode(style)) + switch (style) { + case 'label': + return `.${joinedValues}` + case 'matrix': + return `;${name}=${joinedValues}` + case 'simple': + return joinedValues + default: + return `${name}=${joinedValues}` + } + } + + const separator = separatorArrayExplode(style) + const joinedValues = value + .map((v) => { + if (style === 'label' || style === 'simple') { + return allowReserved ? v : encodeURIComponent(v as string) + } + + return serializePrimitiveParam({ + allowReserved, + name, + value: v as string + }) + }) + .join(separator) + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues +} + +export const serializePrimitiveParam = ({ + allowReserved, + name, + value +}: SerializePrimitiveParam) => { + if (value === undefined || value === null) { + return '' + } + + if (typeof value === 'object') { + throw new Error( + 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.' + ) + } + + return `${name}=${allowReserved ? value : encodeURIComponent(value)}` +} + +export const serializeObjectParam = ({ + allowReserved, + explode, + name, + style, + value, + valueOnly +}: SerializeOptions & { + value: Record | Date + valueOnly?: boolean +}) => { + if (value instanceof Date) { + return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}` + } + + if (style !== 'deepObject' && !explode) { + let values: string[] = [] + Object.entries(value).forEach(([key, v]) => { + values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)] + }) + const joinedValues = values.join(',') + switch (style) { + case 'form': + return `${name}=${joinedValues}` + case 'label': + return `.${joinedValues}` + case 'matrix': + return `;${name}=${joinedValues}` + default: + return joinedValues + } + } + + const separator = separatorObjectExplode(style) + const joinedValues = Object.entries(value) + .map(([key, v]) => + serializePrimitiveParam({ + allowReserved, + name: style === 'deepObject' ? `${name}[${key}]` : key, + value: v as string + }) + ) + .join(separator) + return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues +} diff --git a/examples/openapi-ts-pinia-colada/src/client/core/serverSentEvents.gen.ts b/examples/openapi-ts-pinia-colada/src/client/core/serverSentEvents.gen.ts new file mode 100644 index 000000000..de07ebaf2 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/core/serverSentEvents.gen.ts @@ -0,0 +1,214 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Config } from './types.gen' + +export type ServerSentEventsOptions = Omit & + Pick & { + /** + * 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 + /** + * Default retry delay in milliseconds. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 3000 + */ + sseDefaultRetryDelay?: number + /** + * Maximum number of retry attempts before giving up. + */ + sseMaxRetryAttempts?: number + /** + * Maximum retry delay in milliseconds. + * + * Applies only when exponential backoff is used. + * + * This option applies only if the endpoint returns a stream of events. + * + * @default 30000 + */ + sseMaxRetryDelay?: number + /** + * Optional sleep function for retry backoff. + * + * Defaults to using `setTimeout`. + */ + sseSleepFn?: (ms: number) => Promise + url: string + } + +export interface StreamEvent { + data: TData + event?: string + id?: string + retry?: number +} + +export type ServerSentEventsResult = { + stream: AsyncGenerator< + TData extends Record ? TData[keyof TData] : TData, + TReturn, + TNext + > +} + +export const createSseClient = ({ + 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 response = await fetch(url, { ...options, headers, signal }) + + 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-pinia-colada/src/client/core/types.gen.ts b/examples/openapi-ts-pinia-colada/src/client/core/types.gen.ts new file mode 100644 index 000000000..647ffcc49 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/core/types.gen.ts @@ -0,0 +1,104 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Auth, AuthToken } from './auth.gen' +import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen' + +export type HttpMethod = + | 'connect' + | 'delete' + | 'get' + | 'head' + | 'options' + | 'patch' + | 'post' + | 'put' + | 'trace' + +export type Client< + RequestFn = never, + Config = unknown, + MethodFn = never, + BuildUrlFn = never, + SseFn = never +> = { + /** + * Returns the final request URL. + */ + buildUrl: BuildUrlFn + getConfig: () => Config + request: RequestFn + setConfig: (config: Config) => Config +} & { + [K in HttpMethod]: MethodFn +} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } }) + +export interface Config { + /** + * Auth token or a function returning auth token. The resolved value will be + * added to the request payload as defined by its `security` array. + */ + auth?: ((auth: Auth) => Promise | AuthToken) | AuthToken + /** + * A function for serializing request body parameter. By default, + * {@link JSON.stringify()} will be used. + */ + bodySerializer?: BodySerializer | null + /** + * An object containing any HTTP headers that you want to pre-populate your + * `Headers` object with. + * + * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} + */ + headers?: + | RequestInit['headers'] + | Record< + string, + string | number | boolean | (string | number | boolean)[] | null | undefined | unknown + > + /** + * The request method. + * + * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} + */ + method?: Uppercase + /** + * A function for serializing request query parameters. By default, arrays + * will be exploded in form style, objects will be exploded in deepObject + * style, and reserved characters are percent-encoded. + * + * This method will have no effect if the native `paramsSerializer()` Axios + * API function is used. + * + * {@link https://swagger.io/docs/specification/serialization/#query View examples} + */ + querySerializer?: QuerySerializer | QuerySerializerOptions + /** + * A function validating request data. This is useful if you want to ensure + * the request conforms to the desired shape, so it can be safely sent to + * the server. + */ + requestValidator?: (data: unknown) => Promise + /** + * A function transforming response data before it's returned. This is useful + * for post-processing data, e.g. converting ISO strings into Date objects. + */ + responseTransformer?: (data: unknown) => Promise + /** + * A function validating response data. This is useful if you want to ensure + * the response conforms to the desired shape, so it can be safely passed to + * the transformers and returned to the user. + */ + responseValidator?: (data: unknown) => Promise +} + +type IsExactlyNeverOrNeverUndefined = [T] extends [never] + ? true + : [T] extends [never | undefined] + ? [undefined] extends [T] + ? false + : true + : false + +export type OmitNever> = { + [K in keyof T as IsExactlyNeverOrNeverUndefined extends true ? never : K]: T[K] +} diff --git a/examples/openapi-ts-pinia-colada/src/client/core/utils.gen.ts b/examples/openapi-ts-pinia-colada/src/client/core/utils.gen.ts new file mode 100644 index 000000000..b99c527aa --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/core/utils.gen.ts @@ -0,0 +1,111 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { 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 +} diff --git a/examples/openapi-ts-pinia-colada/src/client/index.ts b/examples/openapi-ts-pinia-colada/src/client/index.ts new file mode 100644 index 000000000..2543e5750 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/index.ts @@ -0,0 +1,4 @@ +// This file is auto-generated by @hey-api/openapi-ts +export * from './@pinia/colada.gen' +export * from './sdk.gen' +export * from './types.gen' diff --git a/examples/openapi-ts-pinia-colada/src/client/schemas.gen.ts b/examples/openapi-ts-pinia-colada/src/client/schemas.gen.ts new file mode 100644 index 000000000..872554d20 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/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-pinia-colada/src/client/sdk.gen.ts b/examples/openapi-ts-pinia-colada/src/client/sdk.gen.ts new file mode 100644 index 000000000..f373c7cf6 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/sdk.gen.ts @@ -0,0 +1,411 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import type { Client, Options as ClientOptions, TDataShape } from './client' +import { client as _heyApiClient } 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 +> = ClientOptions & { + /** + * 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 ?? _heyApiClient).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 ?? _heyApiClient).put({ + 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 ?? _heyApiClient).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 ?? _heyApiClient).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 ?? _heyApiClient).delete({ + security: [ + { + scheme: 'bearer', + type: 'http' + } + ], + url: '/pet/{petId}', + ...options + }) + +/** + * Find pet by ID. + * Returns a single pet. + */ +export const getPetById = ( + options: Options +) => + (options.client ?? _heyApiClient).get({ + 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 ?? _heyApiClient).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 ?? _heyApiClient).post({ + 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 ?? _heyApiClient).get({ + 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 ?? _heyApiClient).post({ + 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 ?? _heyApiClient).delete({ + 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 ?? _heyApiClient).get({ + url: '/store/order/{orderId}', + ...options + }) + +/** + * Create user. + * This can only be done by the logged in user. + */ +export const createUser = ( + options?: Options +) => + (options?.client ?? _heyApiClient).post({ + 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 ?? _heyApiClient).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 ?? _heyApiClient).get({ + url: '/user/login', + ...options + }) + +/** + * Logs out current logged in user session. + * Log user out of the system. + */ +export const logoutUser = ( + options?: Options +) => + (options?.client ?? _heyApiClient).get({ + url: '/user/logout', + ...options + }) + +/** + * Delete user resource. + * This can only be done by the logged in user. + */ +export const deleteUser = ( + options: Options +) => + (options.client ?? _heyApiClient).delete({ + url: '/user/{username}', + ...options + }) + +/** + * Get user by user name. + * Get user detail based on username. + */ +export const getUserByName = ( + options: Options +) => + (options.client ?? _heyApiClient).get({ + url: '/user/{username}', + ...options + }) + +/** + * Update user resource. + * This can only be done by the logged in user. + */ +export const updateUser = ( + options: Options +) => + (options.client ?? _heyApiClient).put({ + url: '/user/{username}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers + } + }) diff --git a/examples/openapi-ts-pinia-colada/src/client/types.gen.ts b/examples/openapi-ts-pinia-colada/src/client/types.gen.ts new file mode 100644 index 000000000..f7044e662 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/client/types.gen.ts @@ -0,0 +1,693 @@ +// This file is auto-generated by @hey-api/openapi-ts + +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 +} + +export type ClientOptions = { + baseUrl: 'https://petstore3.swagger.io/api/v3' | (string & {}) +} diff --git a/examples/openapi-ts-pinia-colada/src/main.ts b/examples/openapi-ts-pinia-colada/src/main.ts new file mode 100644 index 000000000..e6089600f --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/main.ts @@ -0,0 +1,28 @@ +import './assets/main.css' + +import { PiniaColada } from '@pinia/colada' +import { createPinia } from 'pinia' +import { createApp } from 'vue' + +import App from './App.vue' +import { client } from './client/client.gen' +import router from './router' + +// 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 ' + } +}) + +const app = createApp(App) + +const pinia = createPinia() +app.use(pinia) +app.use(PiniaColada) +app.use(router) + +app.mount('#app') diff --git a/examples/openapi-ts-pinia-colada/src/router/index.ts b/examples/openapi-ts-pinia-colada/src/router/index.ts new file mode 100644 index 000000000..42ddd585a --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/router/index.ts @@ -0,0 +1,16 @@ +import { createRouter, createWebHistory } from 'vue-router' + +import PiniaColadaExample from '@/views/PiniaColadaExample.vue' + +const router = createRouter({ + history: createWebHistory(import.meta.env.BASE_URL), + routes: [ + { + component: PiniaColadaExample, + name: 'home', + path: '/' + } + ] +}) + +export default router diff --git a/examples/openapi-ts-pinia-colada/src/views/PiniaColadaExample.vue b/examples/openapi-ts-pinia-colada/src/views/PiniaColadaExample.vue new file mode 100644 index 000000000..6930fc78a --- /dev/null +++ b/examples/openapi-ts-pinia-colada/src/views/PiniaColadaExample.vue @@ -0,0 +1,221 @@ + + + diff --git a/examples/openapi-ts-pinia-colada/tailwind.config.ts b/examples/openapi-ts-pinia-colada/tailwind.config.ts new file mode 100644 index 000000000..8cb3cc6c0 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/tailwind.config.ts @@ -0,0 +1,9 @@ +import type { Config } from 'tailwindcss' + +export default { + content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'], + plugins: [], + theme: { + extend: {} + } +} satisfies Config diff --git a/examples/openapi-ts-pinia-colada/tsconfig.app.json b/examples/openapi-ts-pinia-colada/tsconfig.app.json new file mode 100644 index 000000000..81efb53e9 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/tsconfig.app.json @@ -0,0 +1,14 @@ +{ + "extends": "@vue/tsconfig/tsconfig.dom.json", + "include": ["./env.d.ts", "./src/**/*", "./src/**/*.vue"], + "exclude": ["./src/**/__tests__/*"], + "compilerOptions": { + "composite": true, + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", + + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + } + } +} diff --git a/examples/openapi-ts-pinia-colada/tsconfig.json b/examples/openapi-ts-pinia-colada/tsconfig.json new file mode 100644 index 000000000..100cf6a8f --- /dev/null +++ b/examples/openapi-ts-pinia-colada/tsconfig.json @@ -0,0 +1,14 @@ +{ + "files": [], + "references": [ + { + "path": "./tsconfig.node.json" + }, + { + "path": "./tsconfig.app.json" + }, + { + "path": "./tsconfig.vitest.json" + } + ] +} diff --git a/examples/openapi-ts-pinia-colada/tsconfig.node.json b/examples/openapi-ts-pinia-colada/tsconfig.node.json new file mode 100644 index 000000000..f09406303 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/tsconfig.node.json @@ -0,0 +1,19 @@ +{ + "extends": "@tsconfig/node20/tsconfig.json", + "include": [ + "vite.config.*", + "vitest.config.*", + "cypress.config.*", + "nightwatch.conf.*", + "playwright.config.*" + ], + "compilerOptions": { + "composite": true, + "noEmit": true, + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", + + "module": "ESNext", + "moduleResolution": "Bundler", + "types": ["node"] + } +} diff --git a/examples/openapi-ts-pinia-colada/tsconfig.vitest.json b/examples/openapi-ts-pinia-colada/tsconfig.vitest.json new file mode 100644 index 000000000..571995d11 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/tsconfig.vitest.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.app.json", + "exclude": [], + "compilerOptions": { + "composite": true, + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo", + + "lib": [], + "types": ["node", "jsdom"] + } +} diff --git a/examples/openapi-ts-pinia-colada/vite.config.ts b/examples/openapi-ts-pinia-colada/vite.config.ts new file mode 100644 index 000000000..2ad0b1736 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/vite.config.ts @@ -0,0 +1,16 @@ +import { fileURLToPath, URL } from 'node:url' + +import { createViteConfig } from '@config/vite-base' +import vue from '@vitejs/plugin-vue' +import vueJsx from '@vitejs/plugin-vue-jsx' +import vueDevTools from 'vite-plugin-vue-devtools' + +// https://vitejs.dev/config/ +export default createViteConfig({ + plugins: [vue(), vueJsx(), vueDevTools()], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + } +}) diff --git a/examples/openapi-ts-pinia-colada/vitest.config.ts b/examples/openapi-ts-pinia-colada/vitest.config.ts new file mode 100644 index 000000000..b1c1888c6 --- /dev/null +++ b/examples/openapi-ts-pinia-colada/vitest.config.ts @@ -0,0 +1,16 @@ +import { fileURLToPath } from 'node:url' + +import { createVitestConfig } from '@config/vite-base' +import { configDefaults, mergeConfig } from 'vitest/config' + +import viteConfig from './vite.config' + +export default mergeConfig( + viteConfig, + createVitestConfig(fileURLToPath(new URL('./', import.meta.url)), { + test: { + environment: 'jsdom', + exclude: [...configDefaults.exclude, 'e2e/**'] + } + }) +) diff --git a/package.json b/package.json index beb4c7320..a4e89921c 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "rollup": "4.31.0", "rollup-plugin-dts": "6.1.1", "tsup": "8.4.0", - "turbo": "2.5.5", + "turbo": "2.5.6", "typescript": "5.8.3", "typescript-eslint": "8.29.1", "vitest": "3.1.1" diff --git a/packages/openapi-ts-tests/main/package.json b/packages/openapi-ts-tests/main/package.json index 738d48de5..f2bf8fa5f 100644 --- a/packages/openapi-ts-tests/main/package.json +++ b/packages/openapi-ts-tests/main/package.json @@ -34,6 +34,7 @@ "@config/vite-base": "workspace:*", "@hey-api/custom-client": "workspace:*", "@hey-api/openapi-ts": "workspace:*", + "@pinia/colada": "0.17.2", "@tanstack/angular-query-experimental": "5.73.3", "@tanstack/react-query": "5.73.3", "@tanstack/solid-query": "5.73.3", diff --git a/packages/openapi-ts-tests/main/test/3.1.x.test.ts b/packages/openapi-ts-tests/main/test/3.1.x.test.ts index 3dfb21499..d0b59cb13 100644 --- a/packages/openapi-ts-tests/main/test/3.1.x.test.ts +++ b/packages/openapi-ts-tests/main/test/3.1.x.test.ts @@ -815,6 +815,151 @@ describe(`OpenAPI ${version}`, () => { description: 'generates validator schemas for all integer format combinations (number/integer/string types with int8, int16, int32, int64, uint8, uint16, uint32, uint64 formats)', }, + // TODO: add Pinia Colada snapshots + // { + // config: createConfig({ + // input: 'petstore.yaml', + // output: 'plugins/@pinia/colada/default', + // plugins: ['@pinia/colada'], + // }), + // description: 'generates Pinia Colada plugin code with default settings', + // }, + // { + // config: createConfig({ + // input: 'petstore.yaml', + // output: 'plugins/@pinia/colada/operationOverrides', + // plugins: [ + // { + // name: '@pinia/colada', + // operationTypes: { + // addPet: 'query', + // getPetById: 'both', + // }, + // }, + // ], + // }), + // description: + // 'generates Pinia Colada plugin code with operation type overrides', + // }, + // { + // config: createConfig({ + // input: 'petstore.yaml', + // output: 'plugins/@pinia/colada/groupByTag', + // plugins: [ + // { + // groupByTag: true, + // name: '@pinia/colada', + // }, + // ], + // }), + // description: 'generates Pinia Colada plugin code grouped by OpenAPI tags', + // }, + // { + // config: createConfig({ + // input: 'petstore.yaml', + // output: 'plugins/@pinia/colada/groupByTagWithIndex', + // plugins: [ + // { + // exportFromIndex: true, + // groupByTag: true, + // name: '@pinia/colada', + // }, + // ], + // }), + // description: + // 'generates Pinia Colada plugin code grouped by tags with index file', + // }, + // { + // config: createConfig({ + // input: 'petstore.yaml', + // output: 'plugins/@pinia/colada/customNaming', + // plugins: [ + // { + // mutationOptions: { + // name: '{{name}}MutationOptions', + // }, + // name: '@pinia/colada', + // queryOptions: { + // name: '{{name}}QueryOptions', + // }, + // }, + // ], + // }), + // description: + // 'generates Pinia Colada plugin code with custom naming patterns', + // }, + // { + // config: createConfig({ + // input: 'petstore.yaml', + // output: 'plugins/@pinia/colada/caseSettings', + // plugins: [ + // { + // case: 'PascalCase', + // mutationOptions: { + // case: 'snake_case', + // }, + // name: '@pinia/colada', + // queryOptions: { + // case: 'camelCase', + // }, + // }, + // ], + // }), + // description: + // 'generates Pinia Colada plugin code with different case settings', + // }, + // { + // config: createConfig({ + // input: 'petstore.yaml', + // output: 'plugins/@pinia/colada/disabledOptions', + // plugins: [ + // { + // mutationOptions: { + // enabled: true, + // }, + // name: '@pinia/colada', + // queryOptions: false, + // }, + // ], + // }), + // description: 'generates Pinia Colada plugin code with queries disabled', + // }, + // { + // config: createConfig({ + // input: 'petstore.yaml', + // output: 'plugins/@pinia/colada/complexConfiguration', + // plugins: [ + // { + // exportFromIndex: true, + // groupByTag: true, + // mutationOptions: { + // case: 'camelCase', + // meta: (operation) => ({ + // method: operation.method, + // operationId: operation.id, + // }), + // name: 'use{{name}}Mutation', + // }, + // name: '@pinia/colada', + // operationTypes: { + // addPet: 'query', + // getPetById: 'both', + // updatePet: 'mutation', + // }, + // queryOptions: { + // case: 'camelCase', + // meta: (operation) => ({ + // operationId: operation.id, + // tags: operation.tags, + // }), + // name: 'use{{name}}Query', + // }, + // }, + // ], + // }), + // description: + // 'generates Pinia Colada plugin code with complex configuration combining all features', + // }, { config: createConfig({ input: 'opencode.yaml', 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 46cb75100..31fb72aae 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 @@ -57,23 +57,6 @@ export const getFooOptions = (options?: Options) => { }); }; -export const fooPostQueryKey = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostQueryKey(options) - }); -}; - export const fooPostMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarOptions = (options?: Options) => { }); }; -export const fooBarPostQueryKey = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostQueryKey(options) - }); -}; - export const fooBarPostMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { 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 08e86376a..ad92f5ab0 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 @@ -131,23 +131,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -176,23 +159,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -207,23 +173,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -238,23 +187,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -286,23 +218,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -362,23 +277,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -492,23 +390,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -588,23 +469,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -619,23 +483,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -650,23 +497,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -681,27 +511,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 ae4a57a50..c81ed8cc1 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 @@ -130,23 +130,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -175,23 +158,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -206,23 +172,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -237,23 +186,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -285,23 +217,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -361,23 +276,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -491,23 +389,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -587,23 +468,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -618,23 +482,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -649,23 +496,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -680,27 +510,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 37c6694ce..59f76727c 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 @@ -57,23 +57,6 @@ export const getFooE = (options?: Options) => { }); }; -export const fooPostD = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostD(options) - }); -}; - export const fooPostC = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarE = (options?: Options) => { }); }; -export const fooBarPostD = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooBarPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostD(options) - }); -}; - export const fooBarPostC = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { 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 ee0b2eb4c..6288ca47b 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 @@ -57,23 +57,6 @@ export const getFooOptions = (options?: Options) => { }); }; -export const fooPostQueryKey = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostQueryKey(options) - }); -}; - export const fooPostMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarOptions = (options?: Options) => { }); }; -export const fooBarPostQueryKey = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostQueryKey(options) - }); -}; - export const fooBarPostMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { 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 11ae22144..6fd02980e 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 @@ -131,23 +131,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -176,23 +159,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -207,23 +173,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -238,23 +187,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -286,23 +218,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -362,23 +277,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -492,23 +390,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -588,23 +469,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -619,23 +483,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -650,23 +497,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -681,27 +511,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 ce8a80a76..33994fc38 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 @@ -130,23 +130,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -175,23 +158,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -206,23 +172,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -237,23 +186,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -285,23 +217,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -361,23 +276,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -491,23 +389,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -587,23 +468,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -618,23 +482,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -649,23 +496,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -680,27 +510,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 280b3cb34..8f39dfcc9 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 @@ -57,23 +57,6 @@ export const getFooE = (options?: Options) => { }); }; -export const fooPostD = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostD(options) - }); -}; - export const fooPostC = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarE = (options?: Options) => { }); }; -export const fooBarPostD = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooBarPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostD(options) - }); -}; - export const fooBarPostC = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { 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 cc25c7503..2a96019f9 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 @@ -57,23 +57,6 @@ export const getFooOptions = (options?: Options) => { }); }; -export const fooPostQueryKey = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostQueryKey(options) - }); -}; - export const fooPostMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarOptions = (options?: Options) => { }); }; -export const fooBarPostQueryKey = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostQueryKey(options) - }); -}; - export const fooBarPostMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { 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 c09df98a6..08649be60 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 @@ -131,23 +131,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -176,23 +159,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -207,23 +173,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -238,23 +187,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -286,23 +218,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -362,23 +277,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -492,23 +390,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -588,23 +469,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -619,23 +483,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -650,23 +497,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -681,27 +511,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 e9165e5ec..29ea55274 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 @@ -130,23 +130,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -175,23 +158,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -206,23 +172,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -237,23 +186,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -285,23 +217,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -361,23 +276,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -491,23 +389,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -587,23 +468,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -618,23 +482,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -649,23 +496,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -680,27 +510,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 6a133c259..0dd46b62d 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 @@ -57,23 +57,6 @@ export const getFooE = (options?: Options) => { }); }; -export const fooPostD = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostD(options) - }); -}; - export const fooPostC = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarE = (options?: Options) => { }); }; -export const fooBarPostD = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooBarPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostD(options) - }); -}; - export const fooBarPostC = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { 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 2bd144cb8..7bc15a9c7 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 @@ -57,23 +57,6 @@ export const getFooOptions = (options?: Options) => { }); }; -export const fooPostQueryKey = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostQueryKey(options) - }); -}; - export const fooPostMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarOptions = (options?: Options) => { }); }; -export const fooBarPostQueryKey = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostQueryKey(options) - }); -}; - export const fooBarPostMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { 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 21ac5bffb..b9c9a0b5b 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 @@ -131,23 +131,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -176,23 +159,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -207,23 +173,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -238,23 +187,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -286,23 +218,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -362,23 +277,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -492,23 +390,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -588,23 +469,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -619,23 +483,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -650,23 +497,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -681,27 +511,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 8e40dc8ab..bfbc45213 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 @@ -130,23 +130,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -175,23 +158,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -206,23 +172,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -237,23 +186,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -285,23 +217,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -361,23 +276,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -491,23 +389,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -587,23 +468,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -618,23 +482,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -649,23 +496,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -680,27 +510,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 9d6defd97..3338e867f 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 @@ -57,23 +57,6 @@ export const getFooE = (options?: Options) => { }); }; -export const fooPostD = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostD(options) - }); -}; - export const fooPostC = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarE = (options?: Options) => { }); }; -export const fooBarPostD = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooBarPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostD(options) - }); -}; - export const fooBarPostC = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { 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 10bf4c0de..7dd129efe 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 @@ -57,23 +57,6 @@ export const getFooOptions = (options?: Options) => { }); }; -export const fooPostQueryKey = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostQueryKey(options) - }); -}; - export const fooPostMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarOptions = (options?: Options) => { }); }; -export const fooBarPostQueryKey = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostQueryKey(options) - }); -}; - export const fooBarPostMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { 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 6211e643e..39be957f0 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 @@ -131,23 +131,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -176,23 +159,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -207,23 +173,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -238,23 +187,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -286,23 +218,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -362,23 +277,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -492,23 +390,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -588,23 +469,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -619,23 +483,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -650,23 +497,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): UseMutationOptions, Options> => { const mutationOptions: UseMutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -681,27 +511,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 f54dbfe7c..f70d10b7d 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 @@ -130,23 +130,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -175,23 +158,6 @@ export const putCallWithoutParametersAndResponseMutation = (options?: Partial) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -206,23 +172,6 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('callWithParameters', options); - -export const callWithParametersOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersQueryKey(options) - }); -}; - export const callWithParametersMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -237,23 +186,6 @@ export const callWithParametersMutation = (options?: Partial) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - export const callWithWeirdParameterNamesMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -285,23 +217,6 @@ export const callWithDefaultParametersOptions = (options: Options) => createQueryKey('callWithDefaultOptionalParameters', options); - -export const callWithDefaultOptionalParametersOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDefaultOptionalParameters({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDefaultOptionalParametersQueryKey(options) - }); -}; - export const callWithDefaultOptionalParametersMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -361,23 +276,6 @@ export const duplicateName2Options = (options?: Options) => }); }; -export const duplicateName3QueryKey = (options?: Options) => createQueryKey('duplicateName3', options); - -export const duplicateName3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await duplicateName3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: duplicateName3QueryKey(options) - }); -}; - export const duplicateName3Mutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -491,23 +389,6 @@ export const callWithResponseOptions = (options?: Options) }); }; -export const callWithDuplicateResponsesQueryKey = (options?: Options) => createQueryKey('callWithDuplicateResponses', options); - -export const callWithDuplicateResponsesOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDuplicateResponses({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDuplicateResponsesQueryKey(options) - }); -}; - export const callWithDuplicateResponsesMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -587,23 +468,6 @@ export const complexTypesOptions = (options: Options) => { }); }; -export const callWithResultFromHeaderQueryKey = (options?: Options) => createQueryKey('callWithResultFromHeader', options); - -export const callWithResultFromHeaderOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithResultFromHeader({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithResultFromHeaderQueryKey(options) - }); -}; - export const callWithResultFromHeaderMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -618,23 +482,6 @@ export const callWithResultFromHeaderMutation = (options?: Partial) => createQueryKey('testErrorCode', options); - -export const testErrorCodeOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await testErrorCode({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: testErrorCodeQueryKey(options) - }); -}; - export const testErrorCodeMutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -649,23 +496,6 @@ export const testErrorCodeMutation = (options?: Partial) => createQueryKey('nonAsciiæøåÆøÅöôêÊ字符串', options); - -export const nonAsciiæøåÆøÅöôêÊ字符串Options = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await nonAsciiæøåÆøÅöôêÊ字符串({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: nonAsciiæøåÆøÅöôêÊ字符串QueryKey(options) - }); -}; - export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -680,27 +510,6 @@ export const nonAsciiæøåÆøÅöôêÊ字符串Mutation = (options?: Partial< return mutationOptions; }; -export const postApiVbyApiVersionBodyQueryKey = (options: Options) => createQueryKey('postApiVbyApiVersionBody', options); - -/** - * Body should not be unknown - * Body should not be unknown - */ -export const postApiVbyApiVersionBodyOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionBodyQueryKey(options) - }); -}; - /** * Body should not be unknown * Body should not be unknown 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 845362da6..efc31dc02 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 @@ -57,23 +57,6 @@ export const getFooE = (options?: Options) => { }); }; -export const fooPostD = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostD(options) - }); -}; - export const fooPostC = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarE = (options?: Options) => { }); }; -export const fooBarPostD = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostE = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await fooBarPost({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostD(options) - }); -}; - export const fooBarPostC = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { 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 ccb6f25bb..f5cb665c9 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 @@ -71,23 +71,6 @@ export const create2Mutation = (options?: Partial>): UseMut return mutationOptions; }; -export const create3QueryKey = (options?: Options) => createQueryKey('create3', options); - -export const create3Options = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await create3({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: create3QueryKey(options) - }); -}; - export const create3Mutation = (options?: Partial>): UseMutationOptions> => { const mutationOptions: UseMutationOptions> = { mutationFn: async (localOptions) => { 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 46cb75100..31fb72aae 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 @@ -57,23 +57,6 @@ export const getFooOptions = (options?: Options) => { }); }; -export const fooPostQueryKey = (options?: Options) => createQueryKey('fooPost', options); - -export const fooPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooPostQueryKey(options) - }); -}; - export const fooPostMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { @@ -119,23 +102,6 @@ export const getFooBarOptions = (options?: Options) => { }); }; -export const fooBarPostQueryKey = (options?: Options) => createQueryKey('fooBarPost', options); - -export const fooBarPostOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await FooBazService.fooService.barService.post({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: fooBarPostQueryKey(options) - }); -}; - export const fooBarPostMutation = (options?: Partial>): MutationOptions> => { const mutationOptions: MutationOptions> = { mutationFn: async (localOptions) => { 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 d336611d7..4efd79a1b 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 @@ -72,23 +72,6 @@ export const patchApiVbyApiVersionNoTagMutation = (options?: Partial) => createQueryKey('import', options); - -export const importOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await import_({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: importQueryKey(options) - }); -}; - export const importMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -196,23 +179,6 @@ export const patchCallWithoutParametersAndResponseMutation = (options?: Partial< return mutationOptions; }; -export const postCallWithoutParametersAndResponseQueryKey = (options?: Options) => createQueryKey('postCallWithoutParametersAndResponse', options); - -export const postCallWithoutParametersAndResponseOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithoutParametersAndResponse({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithoutParametersAndResponseQueryKey(options) - }); -}; - export const postCallWithoutParametersAndResponseMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -255,23 +221,6 @@ export const deleteFooMutation = (options?: Partial>): M return mutationOptions; }; -export const callWithDescriptionsQueryKey = (options?: Options) => createQueryKey('callWithDescriptions', options); - -export const callWithDescriptionsOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithDescriptions({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithDescriptionsQueryKey(options) - }); -}; - export const callWithDescriptionsMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -286,33 +235,27 @@ export const callWithDescriptionsMutation = (options?: Partial) => createQueryKey('deprecatedCall', options); - /** * @deprecated */ -export const deprecatedCallOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { +export const deprecatedCallMutation = (options?: Partial>): MutationOptions, Options> => { + const mutationOptions: MutationOptions, Options> = { + mutationFn: async (localOptions) => { const { data } = await deprecatedCall({ ...options, - ...queryKey[0], - signal, + ...localOptions, throwOnError: true }); return data; - }, - queryKey: deprecatedCallQueryKey(options) - }); + } + }; + return mutationOptions; }; -/** - * @deprecated - */ -export const deprecatedCallMutation = (options?: Partial>): MutationOptions, Options> => { - const mutationOptions: MutationOptions, Options> = { +export const callWithParametersMutation = (options?: Partial>): MutationOptions, Options> => { + const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { - const { data } = await deprecatedCall({ + const { data } = await callWithParameters({ ...options, ...localOptions, throwOnError: true @@ -323,12 +266,26 @@ export const deprecatedCallMutation = (options?: Partial) => createQueryKey('callWithParameters', options); +export const callWithWeirdParameterNamesMutation = (options?: Partial>): MutationOptions, Options> => { + const mutationOptions: MutationOptions, Options> = { + mutationFn: async (localOptions) => { + const { data } = await callWithWeirdParameterNames({ + ...options, + ...localOptions, + throwOnError: true + }); + return data; + } + }; + return mutationOptions; +}; + +export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); -export const callWithParametersOptions = (options: Options) => { +export const getCallWithOptionalParamOptions = (options: Options) => { return queryOptions({ queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithParameters({ + const { data } = await getCallWithOptionalParam({ ...options, ...queryKey[0], signal, @@ -336,7 +293,7 @@ export const callWithParametersOptions = (options: Options[0], 'body' | 'hea return params as unknown as typeof page; }; -export const callWithParametersInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('callWithParameters', options, true); - -export const callWithParametersInfiniteOptions = (options: Options) => { - return infiniteQueryOptions, InfiniteData, QueryKey>, string | null | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( - // @ts-ignore - { - queryFn: async ({ pageParam, queryKey, signal }) => { - // @ts-ignore - const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { - query: { - cursor: pageParam - } - }; - const params = createInfiniteParams(queryKey, page); - const { data } = await callWithParameters({ - ...options, - ...params, - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithParametersInfiniteQueryKey(options) - }); -}; - -export const callWithParametersMutation = (options?: Partial>): MutationOptions, Options> => { - const mutationOptions: MutationOptions, Options> = { - mutationFn: async (localOptions) => { - const { data } = await callWithParameters({ - ...options, - ...localOptions, - throwOnError: true - }); - return data; - } - }; - return mutationOptions; -}; - -export const callWithWeirdParameterNamesQueryKey = (options: Options) => createQueryKey('callWithWeirdParameterNames', options); - -export const callWithWeirdParameterNamesOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: callWithWeirdParameterNamesQueryKey(options) - }); -}; - -export const callWithWeirdParameterNamesMutation = (options?: Partial>): MutationOptions, Options> => { - const mutationOptions: MutationOptions, Options> = { - mutationFn: async (localOptions) => { - const { data } = await callWithWeirdParameterNames({ - ...options, - ...localOptions, - throwOnError: true - }); - return data; - } - }; - return mutationOptions; -}; - -export const getCallWithOptionalParamQueryKey = (options: Options) => createQueryKey('getCallWithOptionalParam', options); - -export const getCallWithOptionalParamOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await getCallWithOptionalParam({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: getCallWithOptionalParamQueryKey(options) - }); -}; - export const getCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('getCallWithOptionalParam', options, true); export const getCallWithOptionalParamInfiniteOptions = (options: Options) => { @@ -485,49 +354,6 @@ export const getCallWithOptionalParamInfiniteOptions = (options: Options) => createQueryKey('postCallWithOptionalParam', options); - -export const postCallWithOptionalParamOptions = (options: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postCallWithOptionalParam({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithOptionalParamQueryKey(options) - }); -}; - -export const postCallWithOptionalParamInfiniteQueryKey = (options: Options): QueryKey> => createQueryKey('postCallWithOptionalParam', options, true); - -export const postCallWithOptionalParamInfiniteOptions = (options: Options) => { - return infiniteQueryOptions, InfiniteData, QueryKey>, number | null | Pick>[0], 'body' | 'headers' | 'path' | 'query'>>( - // @ts-ignore - { - queryFn: async ({ pageParam, queryKey, signal }) => { - // @ts-ignore - const page: Pick>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : { - body: { - offset: pageParam - } - }; - const params = createInfiniteParams(queryKey, page); - const { data } = await postCallWithOptionalParam({ - ...options, - ...params, - signal, - throwOnError: true - }); - return data; - }, - queryKey: postCallWithOptionalParamInfiniteQueryKey(options) - }); -}; - export const postCallWithOptionalParamMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -542,23 +368,6 @@ export const postCallWithOptionalParamMutation = (options?: Partial) => createQueryKey('postApiVbyApiVersionRequestBody', options); - -export const postApiVbyApiVersionRequestBodyOptions = (options?: Options) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await postApiVbyApiVersionRequestBody({ - ...options, - ...queryKey[0], - signal, - throwOnError: true - }); - return data; - }, - queryKey: postApiVbyApiVersionRequestBodyQueryKey(options) - }); -}; - export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial>): MutationOptions, Options> => { const mutationOptions: MutationOptions, Options> = { mutationFn: async (localOptions) => { @@ -573,23 +382,6 @@ export const postApiVbyApiVersionRequestBodyMutation = (options?: Partial