From b6e58c64d1b71897533a85d1738cd7ce7ede178d Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 4 Sep 2024 06:41:33 +0100 Subject: [PATCH] fix: set query key base url from supplied client if provided --- .changeset/olive-tables-swim.md | 8 ++++++++ docs/openapi-ts/output.md | 2 +- examples/openapi-ts-axios/src/App.tsx | 4 ++-- .../openapi-ts-axios/src/client/schemas.gen.ts | 16 ++++++++-------- examples/openapi-ts-fetch/src/App.tsx | 4 ++-- .../openapi-ts-fetch/src/client/schemas.gen.ts | 16 ++++++++-------- .../openapi-ts-tanstack-react-query/src/App.tsx | 4 ++-- .../src/client/@tanstack/react-query.gen.ts | 2 +- .../src/client/schemas.gen.ts | 16 ++++++++-------- .../src/client/@tanstack/svelte-query.gen.ts | 2 +- .../src/client/schemas.gen.ts | 16 ++++++++-------- .../src/client/@tanstack/vue-query.gen.ts | 2 +- .../src/client/schemas.gen.ts | 16 ++++++++-------- .../src/views/TanstackExample.vue | 4 ++-- .../src/plugins/@tanstack/query-core/plugin.ts | 2 +- .../@tanstack/react-query.gen.ts.snap | 2 +- .../@tanstack/react-query.gen.ts.snap | 2 +- .../@tanstack/solid-query.gen.ts.snap | 2 +- .../@tanstack/solid-query.gen.ts.snap | 2 +- .../@tanstack/svelte-query.gen.ts.snap | 2 +- .../@tanstack/svelte-query.gen.ts.snap | 2 +- .../@tanstack/vue-query.gen.ts.snap | 2 +- .../@tanstack/vue-query.gen.ts.snap | 2 +- .../@tanstack/react-query.gen.ts.snap | 2 +- .../@tanstack/react-query.gen.ts.snap | 2 +- .../@tanstack/solid-query.gen.ts.snap | 2 +- .../@tanstack/solid-query.gen.ts.snap | 2 +- .../@tanstack/svelte-query.gen.ts.snap | 2 +- .../@tanstack/svelte-query.gen.ts.snap | 2 +- .../@tanstack/vue-query.gen.ts.snap | 2 +- .../@tanstack/vue-query.gen.ts.snap | 2 +- 31 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 .changeset/olive-tables-swim.md diff --git a/.changeset/olive-tables-swim.md b/.changeset/olive-tables-swim.md new file mode 100644 index 000000000..2f9ce0421 --- /dev/null +++ b/.changeset/olive-tables-swim.md @@ -0,0 +1,8 @@ +--- +'@example/openapi-ts-tanstack-svelte-query': patch +'@example/openapi-ts-tanstack-react-query': patch +'@example/openapi-ts-tanstack-vue-query': patch +'@hey-api/openapi-ts': patch +--- + +fix: set query key base url from supplied client if provided diff --git a/docs/openapi-ts/output.md b/docs/openapi-ts/output.md index 021f3f0aa..82757205a 100644 --- a/docs/openapi-ts/output.md +++ b/docs/openapi-ts/output.md @@ -209,7 +209,7 @@ client.post({ Schemas are located in the `schemas.gen.ts` file. This file contains runtime schemas generated from your OpenAPI specification definitions located in `#/components/schemas`. Starting with OpenAPI 3.1, these schemas are JSON Schema compliant. ```ts -export const $Pet = { +export const PetSchema = { required: ['name'], properties: { id: { diff --git a/examples/openapi-ts-axios/src/App.tsx b/examples/openapi-ts-axios/src/App.tsx index 9db6d9b6c..c1cbfb7b4 100644 --- a/examples/openapi-ts-axios/src/App.tsx +++ b/examples/openapi-ts-axios/src/App.tsx @@ -17,7 +17,7 @@ import { } from '@radix-ui/themes'; import { useState } from 'react'; -import { $Pet } from './client/schemas.gen'; +import { PetSchema } from './client/schemas.gen'; import { addPet, getPetById, updatePet } from './client/services.gen'; import type { Pet } from './client/types.gen'; @@ -54,7 +54,7 @@ function App() { const onAddPet = async (formData: FormData) => { // simple form field validation to demonstrate using schemas - if ($Pet.required.includes('name') && !formData.get('name')) { + if (PetSchema.required.includes('name') && !formData.get('name')) { setIsRequiredNameError(true); return; } diff --git a/examples/openapi-ts-axios/src/client/schemas.gen.ts b/examples/openapi-ts-axios/src/client/schemas.gen.ts index 8f6b9dc92..8cd80ffc5 100644 --- a/examples/openapi-ts-axios/src/client/schemas.gen.ts +++ b/examples/openapi-ts-axios/src/client/schemas.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -export const $Order = { +export const OrderSchema = { properties: { complete: { type: 'boolean', @@ -38,7 +38,7 @@ export const $Order = { }, } as const; -export const $Customer = { +export const CustomerSchema = { properties: { address: { items: { @@ -66,7 +66,7 @@ export const $Customer = { }, } as const; -export const $Address = { +export const AddressSchema = { properties: { city: { example: 'Palo Alto', @@ -91,7 +91,7 @@ export const $Address = { }, } as const; -export const $Category = { +export const CategorySchema = { properties: { id: { example: 1, @@ -110,7 +110,7 @@ export const $Category = { }, } as const; -export const $User = { +export const UserSchema = { properties: { email: { example: 'john@email.com', @@ -155,7 +155,7 @@ export const $User = { }, } as const; -export const $Tag = { +export const TagSchema = { properties: { id: { format: 'int64', @@ -172,7 +172,7 @@ export const $Tag = { }, } as const; -export const $Pet = { +export const PetSchema = { properties: { category: { $ref: '#/components/schemas/Category', @@ -224,7 +224,7 @@ export const $Pet = { }, } as const; -export const $ApiResponse = { +export const ApiResponseSchema = { properties: { code: { format: 'int32', diff --git a/examples/openapi-ts-fetch/src/App.tsx b/examples/openapi-ts-fetch/src/App.tsx index a214b6fa0..03c848868 100644 --- a/examples/openapi-ts-fetch/src/App.tsx +++ b/examples/openapi-ts-fetch/src/App.tsx @@ -17,7 +17,7 @@ import { } from '@radix-ui/themes'; import { useState } from 'react'; -import { $Pet } from './client/schemas.gen'; +import { PetSchema } from './client/schemas.gen'; import { addPet, getPetById, updatePet } from './client/services.gen'; import type { Pet } from './client/types.gen'; @@ -54,7 +54,7 @@ function App() { const onAddPet = async (formData: FormData) => { // simple form field validation to demonstrate using schemas - if ($Pet.required.includes('name') && !formData.get('name')) { + if (PetSchema.required.includes('name') && !formData.get('name')) { setIsRequiredNameError(true); return; } diff --git a/examples/openapi-ts-fetch/src/client/schemas.gen.ts b/examples/openapi-ts-fetch/src/client/schemas.gen.ts index 8f6b9dc92..8cd80ffc5 100644 --- a/examples/openapi-ts-fetch/src/client/schemas.gen.ts +++ b/examples/openapi-ts-fetch/src/client/schemas.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -export const $Order = { +export const OrderSchema = { properties: { complete: { type: 'boolean', @@ -38,7 +38,7 @@ export const $Order = { }, } as const; -export const $Customer = { +export const CustomerSchema = { properties: { address: { items: { @@ -66,7 +66,7 @@ export const $Customer = { }, } as const; -export const $Address = { +export const AddressSchema = { properties: { city: { example: 'Palo Alto', @@ -91,7 +91,7 @@ export const $Address = { }, } as const; -export const $Category = { +export const CategorySchema = { properties: { id: { example: 1, @@ -110,7 +110,7 @@ export const $Category = { }, } as const; -export const $User = { +export const UserSchema = { properties: { email: { example: 'john@email.com', @@ -155,7 +155,7 @@ export const $User = { }, } as const; -export const $Tag = { +export const TagSchema = { properties: { id: { format: 'int64', @@ -172,7 +172,7 @@ export const $Tag = { }, } as const; -export const $Pet = { +export const PetSchema = { properties: { category: { $ref: '#/components/schemas/Category', @@ -224,7 +224,7 @@ export const $Pet = { }, } as const; -export const $ApiResponse = { +export const ApiResponseSchema = { properties: { code: { format: 'int32', diff --git a/examples/openapi-ts-tanstack-react-query/src/App.tsx b/examples/openapi-ts-tanstack-react-query/src/App.tsx index b683be5f0..916d688e0 100644 --- a/examples/openapi-ts-tanstack-react-query/src/App.tsx +++ b/examples/openapi-ts-tanstack-react-query/src/App.tsx @@ -23,7 +23,7 @@ import { getPetByIdOptions, updatePetMutation, } from './client/@tanstack/react-query.gen'; -import { $Pet } from './client/schemas.gen'; +import { PetSchema } from './client/schemas.gen'; import type { Pet } from './client/types.gen'; const localClient = createClient({ @@ -92,7 +92,7 @@ function App() { const onAddPet = async (formData: FormData) => { // simple form field validation to demonstrate using schemas - if ($Pet.required.includes('name') && !formData.get('name')) { + if (PetSchema.required.includes('name') && !formData.get('name')) { setIsRequiredNameError(true); return; } diff --git a/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts b/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts index 6b95e64ed..9c1561078 100644 --- a/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts +++ b/examples/openapi-ts-tanstack-react-query/src/client/@tanstack/react-query.gen.ts @@ -77,7 +77,7 @@ const createQueryKey = ( ): QueryKey[0] => { const params: QueryKey[0] = { _id: id, - baseUrl: client.getConfig().baseUrl, + baseUrl: (options?.client ?? client).getConfig().baseUrl, } as QueryKey[0]; if (infinite) { params._infinite = infinite; diff --git a/examples/openapi-ts-tanstack-react-query/src/client/schemas.gen.ts b/examples/openapi-ts-tanstack-react-query/src/client/schemas.gen.ts index 8f6b9dc92..8cd80ffc5 100644 --- a/examples/openapi-ts-tanstack-react-query/src/client/schemas.gen.ts +++ b/examples/openapi-ts-tanstack-react-query/src/client/schemas.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -export const $Order = { +export const OrderSchema = { properties: { complete: { type: 'boolean', @@ -38,7 +38,7 @@ export const $Order = { }, } as const; -export const $Customer = { +export const CustomerSchema = { properties: { address: { items: { @@ -66,7 +66,7 @@ export const $Customer = { }, } as const; -export const $Address = { +export const AddressSchema = { properties: { city: { example: 'Palo Alto', @@ -91,7 +91,7 @@ export const $Address = { }, } as const; -export const $Category = { +export const CategorySchema = { properties: { id: { example: 1, @@ -110,7 +110,7 @@ export const $Category = { }, } as const; -export const $User = { +export const UserSchema = { properties: { email: { example: 'john@email.com', @@ -155,7 +155,7 @@ export const $User = { }, } as const; -export const $Tag = { +export const TagSchema = { properties: { id: { format: 'int64', @@ -172,7 +172,7 @@ export const $Tag = { }, } as const; -export const $Pet = { +export const PetSchema = { properties: { category: { $ref: '#/components/schemas/Category', @@ -224,7 +224,7 @@ export const $Pet = { }, } as const; -export const $ApiResponse = { +export const ApiResponseSchema = { properties: { code: { format: 'int32', diff --git a/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts b/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts index aa20a23bd..cd42b736d 100644 --- a/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts +++ b/examples/openapi-ts-tanstack-svelte-query/src/client/@tanstack/svelte-query.gen.ts @@ -77,7 +77,7 @@ const createQueryKey = ( ): QueryKey[0] => { const params: QueryKey[0] = { _id: id, - baseUrl: client.getConfig().baseUrl, + baseUrl: (options?.client ?? client).getConfig().baseUrl, } as QueryKey[0]; if (infinite) { params._infinite = infinite; diff --git a/examples/openapi-ts-tanstack-svelte-query/src/client/schemas.gen.ts b/examples/openapi-ts-tanstack-svelte-query/src/client/schemas.gen.ts index 8f6b9dc92..8cd80ffc5 100644 --- a/examples/openapi-ts-tanstack-svelte-query/src/client/schemas.gen.ts +++ b/examples/openapi-ts-tanstack-svelte-query/src/client/schemas.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -export const $Order = { +export const OrderSchema = { properties: { complete: { type: 'boolean', @@ -38,7 +38,7 @@ export const $Order = { }, } as const; -export const $Customer = { +export const CustomerSchema = { properties: { address: { items: { @@ -66,7 +66,7 @@ export const $Customer = { }, } as const; -export const $Address = { +export const AddressSchema = { properties: { city: { example: 'Palo Alto', @@ -91,7 +91,7 @@ export const $Address = { }, } as const; -export const $Category = { +export const CategorySchema = { properties: { id: { example: 1, @@ -110,7 +110,7 @@ export const $Category = { }, } as const; -export const $User = { +export const UserSchema = { properties: { email: { example: 'john@email.com', @@ -155,7 +155,7 @@ export const $User = { }, } as const; -export const $Tag = { +export const TagSchema = { properties: { id: { format: 'int64', @@ -172,7 +172,7 @@ export const $Tag = { }, } as const; -export const $Pet = { +export const PetSchema = { properties: { category: { $ref: '#/components/schemas/Category', @@ -224,7 +224,7 @@ export const $Pet = { }, } as const; -export const $ApiResponse = { +export const ApiResponseSchema = { properties: { code: { format: 'int32', diff --git a/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts b/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts index 959346695..be4816482 100644 --- a/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts +++ b/examples/openapi-ts-tanstack-vue-query/src/client/@tanstack/vue-query.gen.ts @@ -73,7 +73,7 @@ const createQueryKey = ( ): QueryKey[0] => { const params: QueryKey[0] = { _id: id, - baseUrl: client.getConfig().baseUrl + baseUrl: (options?.client ?? client).getConfig().baseUrl } as QueryKey[0] if (infinite) { params._infinite = infinite diff --git a/examples/openapi-ts-tanstack-vue-query/src/client/schemas.gen.ts b/examples/openapi-ts-tanstack-vue-query/src/client/schemas.gen.ts index f08589235..45ea91daf 100644 --- a/examples/openapi-ts-tanstack-vue-query/src/client/schemas.gen.ts +++ b/examples/openapi-ts-tanstack-vue-query/src/client/schemas.gen.ts @@ -1,6 +1,6 @@ // This file is auto-generated by @hey-api/openapi-ts -export const $Order = { +export const OrderSchema = { properties: { complete: { type: 'boolean' @@ -38,7 +38,7 @@ export const $Order = { } } as const -export const $Customer = { +export const CustomerSchema = { properties: { address: { items: { @@ -66,7 +66,7 @@ export const $Customer = { } } as const -export const $Address = { +export const AddressSchema = { properties: { city: { example: 'Palo Alto', @@ -91,7 +91,7 @@ export const $Address = { } } as const -export const $Category = { +export const CategorySchema = { properties: { id: { example: 1, @@ -110,7 +110,7 @@ export const $Category = { } } as const -export const $User = { +export const UserSchema = { properties: { email: { example: 'john@email.com', @@ -155,7 +155,7 @@ export const $User = { } } as const -export const $Tag = { +export const TagSchema = { properties: { id: { format: 'int64', @@ -172,7 +172,7 @@ export const $Tag = { } } as const -export const $Pet = { +export const PetSchema = { properties: { category: { $ref: '#/components/schemas/Category' @@ -224,7 +224,7 @@ export const $Pet = { } } as const -export const $ApiResponse = { +export const ApiResponseSchema = { properties: { code: { format: 'int32', diff --git a/examples/openapi-ts-tanstack-vue-query/src/views/TanstackExample.vue b/examples/openapi-ts-tanstack-vue-query/src/views/TanstackExample.vue index 2f9482d21..cc3876af9 100644 --- a/examples/openapi-ts-tanstack-vue-query/src/views/TanstackExample.vue +++ b/examples/openapi-ts-tanstack-vue-query/src/views/TanstackExample.vue @@ -1,5 +1,5 @@