Skip to content

Commit

Permalink
Merge pull request #1010 from hey-api/fix/tanstack-query-key-client
Browse files Browse the repository at this point in the history
fix: set query key base url from supplied client if provided
  • Loading branch information
mrlubos authored Sep 4, 2024
2 parents a254df1 + b6e58c6 commit 12df29b
Show file tree
Hide file tree
Showing 31 changed files with 77 additions and 69 deletions.
8 changes: 8 additions & 0 deletions .changeset/olive-tables-swim.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion docs/openapi-ts/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-axios/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions examples/openapi-ts-axios/src/client/schemas.gen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is auto-generated by @hey-api/openapi-ts

export const $Order = {
export const OrderSchema = {
properties: {
complete: {
type: 'boolean',
Expand Down Expand Up @@ -38,7 +38,7 @@ export const $Order = {
},
} as const;

export const $Customer = {
export const CustomerSchema = {
properties: {
address: {
items: {
Expand Down Expand Up @@ -66,7 +66,7 @@ export const $Customer = {
},
} as const;

export const $Address = {
export const AddressSchema = {
properties: {
city: {
example: 'Palo Alto',
Expand All @@ -91,7 +91,7 @@ export const $Address = {
},
} as const;

export const $Category = {
export const CategorySchema = {
properties: {
id: {
example: 1,
Expand All @@ -110,7 +110,7 @@ export const $Category = {
},
} as const;

export const $User = {
export const UserSchema = {
properties: {
email: {
example: '[email protected]',
Expand Down Expand Up @@ -155,7 +155,7 @@ export const $User = {
},
} as const;

export const $Tag = {
export const TagSchema = {
properties: {
id: {
format: 'int64',
Expand All @@ -172,7 +172,7 @@ export const $Tag = {
},
} as const;

export const $Pet = {
export const PetSchema = {
properties: {
category: {
$ref: '#/components/schemas/Category',
Expand Down Expand Up @@ -224,7 +224,7 @@ export const $Pet = {
},
} as const;

export const $ApiResponse = {
export const ApiResponseSchema = {
properties: {
code: {
format: 'int32',
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-fetch/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions examples/openapi-ts-fetch/src/client/schemas.gen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is auto-generated by @hey-api/openapi-ts

export const $Order = {
export const OrderSchema = {
properties: {
complete: {
type: 'boolean',
Expand Down Expand Up @@ -38,7 +38,7 @@ export const $Order = {
},
} as const;

export const $Customer = {
export const CustomerSchema = {
properties: {
address: {
items: {
Expand Down Expand Up @@ -66,7 +66,7 @@ export const $Customer = {
},
} as const;

export const $Address = {
export const AddressSchema = {
properties: {
city: {
example: 'Palo Alto',
Expand All @@ -91,7 +91,7 @@ export const $Address = {
},
} as const;

export const $Category = {
export const CategorySchema = {
properties: {
id: {
example: 1,
Expand All @@ -110,7 +110,7 @@ export const $Category = {
},
} as const;

export const $User = {
export const UserSchema = {
properties: {
email: {
example: '[email protected]',
Expand Down Expand Up @@ -155,7 +155,7 @@ export const $User = {
},
} as const;

export const $Tag = {
export const TagSchema = {
properties: {
id: {
format: 'int64',
Expand All @@ -172,7 +172,7 @@ export const $Tag = {
},
} as const;

export const $Pet = {
export const PetSchema = {
properties: {
category: {
$ref: '#/components/schemas/Category',
Expand Down Expand Up @@ -224,7 +224,7 @@ export const $Pet = {
},
} as const;

export const $ApiResponse = {
export const ApiResponseSchema = {
properties: {
code: {
format: 'int32',
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-tanstack-react-query/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const createQueryKey = <TOptions extends Options>(
): QueryKey<TOptions>[0] => {
const params: QueryKey<TOptions>[0] = {
_id: id,
baseUrl: client.getConfig().baseUrl,
baseUrl: (options?.client ?? client).getConfig().baseUrl,
} as QueryKey<TOptions>[0];
if (infinite) {
params._infinite = infinite;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is auto-generated by @hey-api/openapi-ts

export const $Order = {
export const OrderSchema = {
properties: {
complete: {
type: 'boolean',
Expand Down Expand Up @@ -38,7 +38,7 @@ export const $Order = {
},
} as const;

export const $Customer = {
export const CustomerSchema = {
properties: {
address: {
items: {
Expand Down Expand Up @@ -66,7 +66,7 @@ export const $Customer = {
},
} as const;

export const $Address = {
export const AddressSchema = {
properties: {
city: {
example: 'Palo Alto',
Expand All @@ -91,7 +91,7 @@ export const $Address = {
},
} as const;

export const $Category = {
export const CategorySchema = {
properties: {
id: {
example: 1,
Expand All @@ -110,7 +110,7 @@ export const $Category = {
},
} as const;

export const $User = {
export const UserSchema = {
properties: {
email: {
example: '[email protected]',
Expand Down Expand Up @@ -155,7 +155,7 @@ export const $User = {
},
} as const;

export const $Tag = {
export const TagSchema = {
properties: {
id: {
format: 'int64',
Expand All @@ -172,7 +172,7 @@ export const $Tag = {
},
} as const;

export const $Pet = {
export const PetSchema = {
properties: {
category: {
$ref: '#/components/schemas/Category',
Expand Down Expand Up @@ -224,7 +224,7 @@ export const $Pet = {
},
} as const;

export const $ApiResponse = {
export const ApiResponseSchema = {
properties: {
code: {
format: 'int32',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const createQueryKey = <TOptions extends Options>(
): QueryKey<TOptions>[0] => {
const params: QueryKey<TOptions>[0] = {
_id: id,
baseUrl: client.getConfig().baseUrl,
baseUrl: (options?.client ?? client).getConfig().baseUrl,
} as QueryKey<TOptions>[0];
if (infinite) {
params._infinite = infinite;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is auto-generated by @hey-api/openapi-ts

export const $Order = {
export const OrderSchema = {
properties: {
complete: {
type: 'boolean',
Expand Down Expand Up @@ -38,7 +38,7 @@ export const $Order = {
},
} as const;

export const $Customer = {
export const CustomerSchema = {
properties: {
address: {
items: {
Expand Down Expand Up @@ -66,7 +66,7 @@ export const $Customer = {
},
} as const;

export const $Address = {
export const AddressSchema = {
properties: {
city: {
example: 'Palo Alto',
Expand All @@ -91,7 +91,7 @@ export const $Address = {
},
} as const;

export const $Category = {
export const CategorySchema = {
properties: {
id: {
example: 1,
Expand All @@ -110,7 +110,7 @@ export const $Category = {
},
} as const;

export const $User = {
export const UserSchema = {
properties: {
email: {
example: '[email protected]',
Expand Down Expand Up @@ -155,7 +155,7 @@ export const $User = {
},
} as const;

export const $Tag = {
export const TagSchema = {
properties: {
id: {
format: 'int64',
Expand All @@ -172,7 +172,7 @@ export const $Tag = {
},
} as const;

export const $Pet = {
export const PetSchema = {
properties: {
category: {
$ref: '#/components/schemas/Category',
Expand Down Expand Up @@ -224,7 +224,7 @@ export const $Pet = {
},
} as const;

export const $ApiResponse = {
export const ApiResponseSchema = {
properties: {
code: {
format: 'int32',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const createQueryKey = <TOptions extends Options>(
): QueryKey<TOptions>[0] => {
const params: QueryKey<TOptions>[0] = {
_id: id,
baseUrl: client.getConfig().baseUrl
baseUrl: (options?.client ?? client).getConfig().baseUrl
} as QueryKey<TOptions>[0]
if (infinite) {
params._infinite = infinite
Expand Down
Loading

0 comments on commit 12df29b

Please sign in to comment.