From dde769c58d43c3a999cb3e457b9545a9804adced Mon Sep 17 00:00:00 2001 From: soartec-lab Date: Fri, 27 Dec 2024 02:08:57 +0000 Subject: [PATCH 1/2] feat: add type annotation to response `data` in `fetch` --- packages/fetch/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fetch/src/index.ts b/packages/fetch/src/index.ts index 5a808bbc3..b700a61f2 100644 --- a/packages/fetch/src/index.ts +++ b/packages/fetch/src/index.ts @@ -176,7 +176,7 @@ ${ ` : `const res = await fetch(${fetchFnOptions}) - const data = await res.json() + const data:${response.definition.success} = await res.json() ${override.fetch.includeHttpResponseReturnType ? 'return { status: res.status, data, headers: res.headers }' : `return data as ${responseTypeName}`} `; From 31562f4996cc3f13eb78fcd90993bff5e5cdb544 Mon Sep 17 00:00:00 2001 From: soartec-lab Date: Fri, 27 Dec 2024 02:15:54 +0000 Subject: [PATCH 2/2] chore: update sample apps --- .../petstoreFromFileSpecWithConfig.ts | 20 +- .../petstoreFromFileSpecWithTransformer.ts | 16 +- samples/basic/api/model/pet.ts | 20 +- .../next-app/app/gen/pets/pets.ts | 8 +- .../hono-with-zod/src/petstore.schemas.ts | 16 +- .../app/gen/models/dachshund.ts | 2 +- .../app/gen/models/labradoodle.ts | 2 +- .../next-app-with-fetch/app/gen/models/pet.ts | 12 +- .../app/gen/pets/pets.msw.ts | 80 ++--- .../next-app-with-fetch/app/gen/pets/pets.ts | 8 +- ...petstoreFromFileSpecWithTransformer.msw.ts | 4 +- .../basic/src/api/model/pet.ts | 2 +- .../src/api/endpoints/swaggerPetstore.msw.ts | 6 +- .../src/api/endpoints/swaggerPetstore.ts | 9 +- .../fetch-client/src/api/models/pet.ts | 2 +- ...petstoreFromFileSpecWithTransformer.msw.ts | 22 +- .../petstoreFromFileSpecWithTransformer.ts | 306 +++++------------- .../react-query/basic/src/api/model/pet.ts | 20 +- ...petstoreFromFileSpecWithTransformer.msw.ts | 22 +- .../petstoreFromFileSpecWithTransformer.ts | 88 ++--- .../custom-client/src/api/model/pet.ts | 20 +- .../custom-fetch/src/gen/models/dachshund.ts | 2 +- .../src/gen/models/labradoodle.ts | 2 +- .../custom-fetch/src/gen/models/pet.ts | 12 +- .../custom-fetch/src/gen/pets/pets.msw.ts | 80 ++--- .../custom-fetch/src/gen/pets/pets.ts | 153 ++++----- .../petstoreFromFileSpecWithTransformer.ts | 71 ++-- .../custom-fetch/src/gen/models/dachshund.ts | 2 +- .../src/gen/models/labradoodle.ts | 2 +- .../custom-fetch/src/gen/models/pet.ts | 12 +- .../custom-fetch/src/gen/pets/pets.msw.ts | 80 ++--- .../custom-fetch/src/gen/pets/pets.ts | 94 +++--- .../src/gen/endpoints/pets/pets.msw.ts | 80 ++--- .../src/gen/endpoints/pets/pets.ts | 12 +- .../swr-with-zod/src/gen/models/dachshund.ts | 2 +- .../src/gen/models/labradoodle.ts | 2 +- samples/swr-with-zod/src/gen/models/pet.ts | 12 +- .../custom-fetch/src/gen/models/dachshund.ts | 2 +- .../src/gen/models/labradoodle.ts | 2 +- .../custom-fetch/src/gen/models/pet.ts | 12 +- .../custom-fetch/src/gen/pets/pets.msw.ts | 80 ++--- .../custom-fetch/src/gen/pets/pets.ts | 82 ++--- ...petstoreFromFileSpecWithTransformer.msw.ts | 8 +- .../petstoreFromFileSpecWithTransformer.ts | 138 +++----- .../vue-query-basic/src/api/model/pet.ts | 4 +- 45 files changed, 653 insertions(+), 978 deletions(-) diff --git a/samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts b/samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts index 52fea2509..4cbdce10a 100644 --- a/samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts +++ b/samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts @@ -58,16 +58,6 @@ export const PetCallingCode = { } as const; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -75,11 +65,21 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; } /** diff --git a/samples/basic/api/endpoints/petstoreFromFileSpecWithTransformer.ts b/samples/basic/api/endpoints/petstoreFromFileSpecWithTransformer.ts index 7333d90fc..b80ff1e7e 100644 --- a/samples/basic/api/endpoints/petstoreFromFileSpecWithTransformer.ts +++ b/samples/basic/api/endpoints/petstoreFromFileSpecWithTransformer.ts @@ -77,10 +77,14 @@ export const getListPetsResponseMock = (): PetsArray => { length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1, ).map(() => ({ + id: faker.number.int({ min: undefined, max: undefined }), + name: 'jon', age: faker.helpers.arrayElement([ faker.number.int({ min: 0, max: 30 }), undefined, ]), + tag: faker.helpers.arrayElement(['jon', null]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -92,10 +96,6 @@ export const getListPetsResponseMock = (): PetsArray => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: 'jon', - tag: faker.helpers.arrayElement(['jon', null]), })); export const getListPetsNestedArrayResponseMock = ( @@ -106,10 +106,14 @@ export const getListPetsNestedArrayResponseMock = ( { length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1, ).map(() => ({ + id: faker.number.int({ min: undefined, max: undefined }), + name: 'jon', age: faker.helpers.arrayElement([ faker.number.int({ min: 0, max: 30 }), undefined, ]), + tag: faker.helpers.arrayElement(['jon', null]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -121,10 +125,6 @@ export const getListPetsNestedArrayResponseMock = ( ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: 'jon', - tag: faker.helpers.arrayElement(['jon', null]), })), undefined, ]), diff --git a/samples/basic/api/model/pet.ts b/samples/basic/api/model/pet.ts index 80f8d0a2b..15f469683 100644 --- a/samples/basic/api/model/pet.ts +++ b/samples/basic/api/model/pet.ts @@ -8,16 +8,6 @@ import type { PetCallingCode } from './petCallingCode'; import type { PetCountry } from './petCountry'; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -25,9 +15,19 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; } diff --git a/samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts b/samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts index a5ce38504..d5f4e7ba2 100644 --- a/samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts +++ b/samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts @@ -43,7 +43,7 @@ export const listPets = async ( method: 'GET', }); - const data = await res.json(); + const data: Pets = await res.json(); return { status: res.status, data, headers: res.headers }; }; @@ -72,7 +72,7 @@ export const createPets = async ( body: JSON.stringify(createPetsBodyItem), }); - const data = await res.json(); + const data: Pet = await res.json(); return { status: res.status, data, headers: res.headers }; }; @@ -101,7 +101,7 @@ export const updatePets = async ( body: JSON.stringify(pet), }); - const data = await res.json(); + const data: Pet = await res.json(); return { status: res.status, data, headers: res.headers }; }; @@ -128,7 +128,7 @@ export const showPetById = async ( method: 'GET', }); - const data = await res.json(); + const data: Pet = await res.json(); return { status: res.status, data, headers: res.headers }; }; diff --git a/samples/hono/hono-with-zod/src/petstore.schemas.ts b/samples/hono/hono-with-zod/src/petstore.schemas.ts index fa2e2d7f8..3eee51f25 100644 --- a/samples/hono/hono-with-zod/src/petstore.schemas.ts +++ b/samples/hono/hono-with-zod/src/petstore.schemas.ts @@ -44,8 +44,8 @@ export const DachshundBreed = { } as const; export interface Dachshund { - breed: DachshundBreed; length: number; + breed: DachshundBreed; } export type LabradoodleBreed = @@ -57,8 +57,8 @@ export const LabradoodleBreed = { } as const; export interface Labradoodle { - breed: LabradoodleBreed; cuteness: number; + breed: LabradoodleBreed; } export type DogType = (typeof DogType)[keyof typeof DogType]; @@ -98,19 +98,19 @@ export const PetCallingCode = { export type Pet = | (Dog & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }) | (Cat & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }); diff --git a/samples/next-app-with-fetch/app/gen/models/dachshund.ts b/samples/next-app-with-fetch/app/gen/models/dachshund.ts index 149aafa89..7dbf20b0d 100644 --- a/samples/next-app-with-fetch/app/gen/models/dachshund.ts +++ b/samples/next-app-with-fetch/app/gen/models/dachshund.ts @@ -7,6 +7,6 @@ import type { DachshundBreed } from './dachshundBreed'; export interface Dachshund { - breed: DachshundBreed; length: number; + breed: DachshundBreed; } diff --git a/samples/next-app-with-fetch/app/gen/models/labradoodle.ts b/samples/next-app-with-fetch/app/gen/models/labradoodle.ts index 9ff0cc8de..0ca06f42f 100644 --- a/samples/next-app-with-fetch/app/gen/models/labradoodle.ts +++ b/samples/next-app-with-fetch/app/gen/models/labradoodle.ts @@ -7,6 +7,6 @@ import type { LabradoodleBreed } from './labradoodleBreed'; export interface Labradoodle { - breed: LabradoodleBreed; cuteness: number; + breed: LabradoodleBreed; } diff --git a/samples/next-app-with-fetch/app/gen/models/pet.ts b/samples/next-app-with-fetch/app/gen/models/pet.ts index 693b339b6..9b538f6eb 100644 --- a/samples/next-app-with-fetch/app/gen/models/pet.ts +++ b/samples/next-app-with-fetch/app/gen/models/pet.ts @@ -12,19 +12,19 @@ import type { PetCountry } from './petCountry'; export type Pet = | (Dog & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }) | (Cat & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }); diff --git a/samples/next-app-with-fetch/app/gen/pets/pets.msw.ts b/samples/next-app-with-fetch/app/gen/pets/pets.msw.ts index f25b4d844..b6cc1ab67 100644 --- a/samples/next-app-with-fetch/app/gen/pets/pets.msw.ts +++ b/samples/next-app-with-fetch/app/gen/pets/pets.msw.ts @@ -12,8 +12,8 @@ export const getListPetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -22,8 +22,8 @@ export const getListPetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -74,6 +74,10 @@ export const getListPetsResponseMock = (): Pets => { ...getListPetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -85,14 +89,14 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getListPetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -104,10 +108,6 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]), ); @@ -116,8 +116,8 @@ export const getCreatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -126,8 +126,8 @@ export const getCreatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -174,6 +174,10 @@ export const getCreatePetsResponseMock = (): Pet => { ...getCreatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -185,14 +189,14 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getCreatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -204,10 +208,6 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -215,8 +215,8 @@ export const getUpdatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -225,8 +225,8 @@ export const getUpdatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -273,6 +273,10 @@ export const getUpdatePetsResponseMock = (): Pet => { ...getUpdatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -284,14 +288,14 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getUpdatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -303,10 +307,6 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -314,8 +314,8 @@ export const getShowPetByIdResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -324,8 +324,8 @@ export const getShowPetByIdResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -372,6 +372,10 @@ export const getShowPetByIdResponseMock = (): Pet => { ...getShowPetByIdResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -383,14 +387,14 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getShowPetByIdResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -402,10 +406,6 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); diff --git a/samples/next-app-with-fetch/app/gen/pets/pets.ts b/samples/next-app-with-fetch/app/gen/pets/pets.ts index 9d8a7449e..052d77182 100644 --- a/samples/next-app-with-fetch/app/gen/pets/pets.ts +++ b/samples/next-app-with-fetch/app/gen/pets/pets.ts @@ -67,7 +67,7 @@ export const listPets = async ( params?: ListPetsParams, options?: RequestInit, ): Promise => { - return customFetch>(getListPetsUrl(params), { + return customFetch(getListPetsUrl(params), { ...options, method: 'GET', }); @@ -90,7 +90,7 @@ export const createPets = async ( createPetsBodyItem: CreatePetsBodyItem[], options?: RequestInit, ): Promise => { - return customFetch>(getCreatePetsUrl(), { + return customFetch(getCreatePetsUrl(), { ...options, method: 'POST', headers: { 'Content-Type': 'application/json', ...options?.headers }, @@ -115,7 +115,7 @@ export const updatePets = async ( pet: NonReadonly, options?: RequestInit, ): Promise => { - return customFetch>(getUpdatePetsUrl(), { + return customFetch(getUpdatePetsUrl(), { ...options, method: 'PUT', headers: { 'Content-Type': 'application/json', ...options?.headers }, @@ -140,7 +140,7 @@ export const showPetById = async ( petId: string, options?: RequestInit, ): Promise => { - return customFetch>(getShowPetByIdUrl(petId), { + return customFetch(getShowPetByIdUrl(petId), { ...options, method: 'GET', }); diff --git a/samples/react-app-with-swr/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts b/samples/react-app-with-swr/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts index c1c5e0bac..f625ecafa 100644 --- a/samples/react-app-with-swr/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts +++ b/samples/react-app-with-swr/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts @@ -14,20 +14,20 @@ export const getListPetsResponseMock = (): Pets => (_, i) => i + 1, ).map(() => ({ '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), id: (() => faker.number.int({ min: 1, max: 99999 }))(), name: (() => faker.person.lastName())(), tag: (() => faker.person.lastName())(), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), })); export const getCreatePetsResponseMock = ( overrideResponse: Partial = {}, ): Pet => ({ '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), id: faker.number.int({ min: undefined, max: undefined }), name: (() => faker.person.lastName())(), tag: (() => faker.person.lastName())(), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), ...overrideResponse, }); diff --git a/samples/react-app-with-swr/basic/src/api/model/pet.ts b/samples/react-app-with-swr/basic/src/api/model/pet.ts index e4cca6098..adb486cdd 100644 --- a/samples/react-app-with-swr/basic/src/api/model/pet.ts +++ b/samples/react-app-with-swr/basic/src/api/model/pet.ts @@ -7,8 +7,8 @@ export interface Pet { '@id'?: string; - email?: string; id: number; name: string; tag?: string; + email?: string; } diff --git a/samples/react-app-with-swr/fetch-client/src/api/endpoints/swaggerPetstore.msw.ts b/samples/react-app-with-swr/fetch-client/src/api/endpoints/swaggerPetstore.msw.ts index b01ab9105..8dab334ec 100644 --- a/samples/react-app-with-swr/fetch-client/src/api/endpoints/swaggerPetstore.msw.ts +++ b/samples/react-app-with-swr/fetch-client/src/api/endpoints/swaggerPetstore.msw.ts @@ -14,20 +14,20 @@ export const getListPetsResponseMock = (): Pets => (_, i) => i + 1, ).map(() => ({ '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), id: faker.number.int({ min: undefined, max: undefined }), name: faker.string.alpha(20), tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), })); export const getCreatePetsResponseMock = ( overrideResponse: Partial = {}, ): Pet => ({ '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), id: faker.number.int({ min: undefined, max: undefined }), name: faker.string.alpha(20), tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), ...overrideResponse, }); @@ -35,10 +35,10 @@ export const getShowPetByIdResponseMock = ( overrideResponse: Partial = {}, ): Pet => ({ '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), id: faker.number.int({ min: undefined, max: undefined }), name: faker.string.alpha(20), tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), ...overrideResponse, }); diff --git a/samples/react-app-with-swr/fetch-client/src/api/endpoints/swaggerPetstore.ts b/samples/react-app-with-swr/fetch-client/src/api/endpoints/swaggerPetstore.ts index 976b850e8..cfc3c0ad2 100644 --- a/samples/react-app-with-swr/fetch-client/src/api/endpoints/swaggerPetstore.ts +++ b/samples/react-app-with-swr/fetch-client/src/api/endpoints/swaggerPetstore.ts @@ -41,7 +41,8 @@ export const listPets = async ( ...options, method: 'GET', }); - const data = await res.json(); + + const data: Pets = await res.json(); return data as Pets; }; @@ -103,7 +104,8 @@ export const createPets = async ( headers: { 'Content-Type': 'application/json', ...options?.headers }, body: JSON.stringify(createPetsBody), }); - const data = await res.json(); + + const data: Pet = await res.json(); return data as Pet; }; @@ -162,7 +164,8 @@ export const showPetById = async ( ...options, method: 'GET', }); - const data = await res.json(); + + const data: Pet = await res.json(); return data as Pet; }; diff --git a/samples/react-app-with-swr/fetch-client/src/api/models/pet.ts b/samples/react-app-with-swr/fetch-client/src/api/models/pet.ts index e4cca6098..adb486cdd 100644 --- a/samples/react-app-with-swr/fetch-client/src/api/models/pet.ts +++ b/samples/react-app-with-swr/fetch-client/src/api/models/pet.ts @@ -7,8 +7,8 @@ export interface Pet { '@id'?: string; - email?: string; id: number; name: string; tag?: string; + email?: string; } diff --git a/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts b/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts index 5e9d0f4f7..a4c22154f 100644 --- a/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts +++ b/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts @@ -13,10 +13,14 @@ export const getListPetsResponseMock = (): PetsArray => { length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1, ).map(() => ({ + id: (() => faker.number.int({ min: 1, max: 99999 }))(), + name: (() => faker.person.lastName())(), age: faker.helpers.arrayElement([ faker.number.int({ min: 0, max: 30 }), undefined, ]), + tag: faker.helpers.arrayElement([(() => faker.person.lastName())(), null]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -28,10 +32,6 @@ export const getListPetsResponseMock = (): PetsArray => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: (() => faker.number.int({ min: 1, max: 99999 }))(), - name: (() => faker.person.lastName())(), - tag: faker.helpers.arrayElement([(() => faker.person.lastName())(), null]), })); export const getListPetsNestedArrayResponseMock = ( @@ -42,10 +42,17 @@ export const getListPetsNestedArrayResponseMock = ( { length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1, ).map(() => ({ + id: faker.number.int({ min: undefined, max: undefined }), + name: (() => faker.person.lastName())(), age: faker.helpers.arrayElement([ faker.number.int({ min: 0, max: 30 }), undefined, ]), + tag: faker.helpers.arrayElement([ + (() => faker.person.lastName())(), + null, + ]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -57,13 +64,6 @@ export const getListPetsNestedArrayResponseMock = ( ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: (() => faker.person.lastName())(), - tag: faker.helpers.arrayElement([ - (() => faker.person.lastName())(), - null, - ]), })), undefined, ]), diff --git a/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts b/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts index f47f73448..18dd2b76c 100644 --- a/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts +++ b/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts @@ -83,10 +83,10 @@ export const getListPetsInfiniteQueryOptions = < options?: { query?: Partial< UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -115,10 +115,10 @@ export const getListPetsInfiniteQueryOptions = < enabled: !!version, ...queryOptions, } as UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > & { queryKey: DataTag }; @@ -141,21 +141,16 @@ export function useListPetsInfinite< options: { query: Partial< UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > > & Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - TData, - QueryKey - >, + DefinedInitialDataOptions, 'initialData' >; }, @@ -174,21 +169,16 @@ export function useListPetsInfinite< options?: { query?: Partial< UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > > & Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - TData, - QueryKey - >, + UndefinedInitialDataOptions, 'initialData' >; }, @@ -207,10 +197,10 @@ export function useListPetsInfinite< options?: { query?: Partial< UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -235,10 +225,10 @@ export function useListPetsInfinite< options?: { query?: Partial< UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -269,11 +259,7 @@ export const getListPetsQueryOptions = < >( params?: ListPetsParams, version: number = 1, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ) => { const { query: queryOptions } = options ?? {}; @@ -289,7 +275,7 @@ export const getListPetsQueryOptions = < queryFn, enabled: !!version, ...queryOptions, - } as UseQueryOptions>, TError, TData> & { + } as UseQueryOptions & { queryKey: DataTag; }; }; @@ -306,17 +292,8 @@ export function useListPets< params: undefined | ListPetsParams, version: undefined | number, options: { - query: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query: Partial> & + Pick, 'initialData'>; }, ): DefinedUseQueryResult & { queryKey: DataTag; @@ -328,17 +305,8 @@ export function useListPets< params?: ListPetsParams, version?: number, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query?: Partial> & + Pick, 'initialData'>; }, ): UseQueryResult & { queryKey: DataTag }; export function useListPets< @@ -347,11 +315,7 @@ export function useListPets< >( params?: ListPetsParams, version?: number, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ): UseQueryResult & { queryKey: DataTag }; /** * @summary List all pets @@ -363,11 +327,7 @@ export function useListPets< >( params?: ListPetsParams, version: number = 1, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ): UseQueryResult & { queryKey: DataTag } { const queryOptions = getListPetsQueryOptions(params, version, options); @@ -386,15 +346,7 @@ export const getListPetsSuspenseQueryOptions = < >( params?: ListPetsParams, version: number = 1, - options?: { - query?: Partial< - UseSuspenseQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ) => { const { query: queryOptions } = options ?? {}; @@ -406,7 +358,7 @@ export const getListPetsSuspenseQueryOptions = < }) => listPets(params, version, signal); return { queryKey, queryFn, ...queryOptions } as UseSuspenseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: DataTag }; @@ -423,15 +375,7 @@ export function useListPetsSuspense< >( params: undefined | ListPetsParams, version: undefined | number, - options: { - query: Partial< - UseSuspenseQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options: { query: Partial> }, ): UseSuspenseQueryResult & { queryKey: DataTag; }; @@ -441,15 +385,7 @@ export function useListPetsSuspense< >( params?: ListPetsParams, version?: number, - options?: { - query?: Partial< - UseSuspenseQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ): UseSuspenseQueryResult & { queryKey: DataTag; }; @@ -459,15 +395,7 @@ export function useListPetsSuspense< >( params?: ListPetsParams, version?: number, - options?: { - query?: Partial< - UseSuspenseQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ): UseSuspenseQueryResult & { queryKey: DataTag; }; @@ -481,15 +409,7 @@ export function useListPetsSuspense< >( params?: ListPetsParams, version: number = 1, - options?: { - query?: Partial< - UseSuspenseQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ): UseSuspenseQueryResult & { queryKey: DataTag; } { @@ -521,10 +441,10 @@ export const getListPetsSuspenseInfiniteQueryOptions = < options?: { query?: Partial< UseSuspenseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -552,10 +472,10 @@ export const getListPetsSuspenseInfiniteQueryOptions = < queryFn, ...queryOptions, } as UseSuspenseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > & { queryKey: DataTag }; @@ -578,10 +498,10 @@ export function useListPetsSuspenseInfinite< options: { query: Partial< UseSuspenseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -602,10 +522,10 @@ export function useListPetsSuspenseInfinite< options?: { query?: Partial< UseSuspenseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -626,10 +546,10 @@ export function useListPetsSuspenseInfinite< options?: { query?: Partial< UseSuspenseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -654,10 +574,10 @@ export function useListPetsSuspenseInfinite< options?: { query?: Partial< UseSuspenseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -701,21 +621,17 @@ export const createPets = ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = ErrorType, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody; version?: number }, TContext >; -}): UseMutationOptions< - Awaited>, - TError, - { data: CreatePetsBody; version?: number }, - TContext -> => { +}) => { const mutationKey = ['createPets']; const { mutation: mutationOptions } = options ? options.mutation && @@ -734,7 +650,12 @@ export const getCreatePetsMutationOptions = < return createPets(data, version); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBody; version?: number }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -747,17 +668,18 @@ export type CreatePetsMutationError = ErrorType; * @summary Create a pet */ export const useCreatePets = < + TData = Awaited>, TError = ErrorType, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody; version?: number }, TContext >; }): UseMutationResult< - Awaited>, + TData, TError, { data: CreatePetsBody; version?: number }, TContext @@ -799,15 +721,7 @@ export const getListPetsNestedArrayQueryOptions = < >( params?: ListPetsNestedArrayParams, version: number = 1, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ) => { const { query: queryOptions } = options ?? {}; @@ -823,11 +737,9 @@ export const getListPetsNestedArrayQueryOptions = < queryFn, enabled: !!version, ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: DataTag }; + } as UseQueryOptions & { + queryKey: DataTag; + }; }; export type ListPetsNestedArrayQueryResult = NonNullable< @@ -842,21 +754,8 @@ export function useListPetsNestedArray< params: undefined | ListPetsNestedArrayParams, version: undefined | number, options: { - query: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query: Partial> & + Pick, 'initialData'>; }, ): DefinedUseQueryResult & { queryKey: DataTag; @@ -868,21 +767,8 @@ export function useListPetsNestedArray< params?: ListPetsNestedArrayParams, version?: number, options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query?: Partial> & + Pick, 'initialData'>; }, ): UseQueryResult & { queryKey: DataTag }; export function useListPetsNestedArray< @@ -891,15 +777,7 @@ export function useListPetsNestedArray< >( params?: ListPetsNestedArrayParams, version?: number, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ): UseQueryResult & { queryKey: DataTag }; /** * @summary List all pets as nested array @@ -911,15 +789,7 @@ export function useListPetsNestedArray< >( params?: ListPetsNestedArrayParams, version: number = 1, - options?: { - query?: Partial< - UseQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ): UseQueryResult & { queryKey: DataTag } { const queryOptions = getListPetsNestedArrayQueryOptions( params, @@ -961,11 +831,7 @@ export const getShowPetByIdQueryOptions = < >( petId: string, version: number = 1, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ) => { const { query: queryOptions } = options ?? {}; @@ -981,11 +847,9 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: !!(version && petId), ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: DataTag }; + } as UseQueryOptions & { + queryKey: DataTag; + }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -1000,17 +864,8 @@ export function useShowPetById< petId: string, version: undefined | number, options: { - query: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query: Partial> & + Pick, 'initialData'>; }, ): DefinedUseQueryResult & { queryKey: DataTag; @@ -1022,17 +877,8 @@ export function useShowPetById< petId: string, version?: number, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query?: Partial> & + Pick, 'initialData'>; }, ): UseQueryResult & { queryKey: DataTag }; export function useShowPetById< @@ -1041,11 +887,7 @@ export function useShowPetById< >( petId: string, version?: number, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ): UseQueryResult & { queryKey: DataTag }; /** * @summary Info for a specific pet @@ -1057,11 +899,7 @@ export function useShowPetById< >( petId: string, version: number = 1, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ): UseQueryResult & { queryKey: DataTag } { const queryOptions = getShowPetByIdQueryOptions(petId, version, options); diff --git a/samples/react-query/basic/src/api/model/pet.ts b/samples/react-query/basic/src/api/model/pet.ts index 80f8d0a2b..15f469683 100644 --- a/samples/react-query/basic/src/api/model/pet.ts +++ b/samples/react-query/basic/src/api/model/pet.ts @@ -8,16 +8,6 @@ import type { PetCallingCode } from './petCallingCode'; import type { PetCountry } from './petCountry'; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -25,9 +15,19 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; } diff --git a/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts b/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts index 5e9d0f4f7..a4c22154f 100644 --- a/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts +++ b/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts @@ -13,10 +13,14 @@ export const getListPetsResponseMock = (): PetsArray => { length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1, ).map(() => ({ + id: (() => faker.number.int({ min: 1, max: 99999 }))(), + name: (() => faker.person.lastName())(), age: faker.helpers.arrayElement([ faker.number.int({ min: 0, max: 30 }), undefined, ]), + tag: faker.helpers.arrayElement([(() => faker.person.lastName())(), null]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -28,10 +32,6 @@ export const getListPetsResponseMock = (): PetsArray => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: (() => faker.number.int({ min: 1, max: 99999 }))(), - name: (() => faker.person.lastName())(), - tag: faker.helpers.arrayElement([(() => faker.person.lastName())(), null]), })); export const getListPetsNestedArrayResponseMock = ( @@ -42,10 +42,17 @@ export const getListPetsNestedArrayResponseMock = ( { length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1, ).map(() => ({ + id: faker.number.int({ min: undefined, max: undefined }), + name: (() => faker.person.lastName())(), age: faker.helpers.arrayElement([ faker.number.int({ min: 0, max: 30 }), undefined, ]), + tag: faker.helpers.arrayElement([ + (() => faker.person.lastName())(), + null, + ]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -57,13 +64,6 @@ export const getListPetsNestedArrayResponseMock = ( ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: (() => faker.person.lastName())(), - tag: faker.helpers.arrayElement([ - (() => faker.person.lastName())(), - null, - ]), })), undefined, ]), diff --git a/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts b/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts index b07056393..30c23734f 100644 --- a/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts +++ b/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts @@ -63,13 +63,7 @@ export const useListPetsQueryOptions = < >( params?: ListPetsParams, version: number = 1, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -87,11 +81,7 @@ export const useListPetsQueryOptions = < queryFn, enabled: !!version, ...queryOptions, - } as UseQueryOptions< - Awaited>>, - TError, - TData - > & { queryKey: QueryKey }; + } as UseQueryOptions & { queryKey: QueryKey }; }; export type ListPetsQueryResult = NonNullable< @@ -109,13 +99,7 @@ export function useListPets< >( params?: ListPetsParams, version: number = 1, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = useListPetsQueryOptions(params, version, options); @@ -153,21 +137,17 @@ export const useCreatePetsHook = () => { }; export const useCreatePetsMutationOptions = < + TData = Awaited>>, TError = ErrorType, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>>, + TData, TError, { data: BodyType; version?: number }, TContext >; -}): UseMutationOptions< - Awaited>>, - TError, - { data: BodyType; version?: number }, - TContext -> => { +}) => { const mutationKey = ['createPets']; const { mutation: mutationOptions } = options ? options.mutation && @@ -188,7 +168,12 @@ export const useCreatePetsMutationOptions = < return createPets(data, version); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: BodyType; version?: number }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -201,17 +186,18 @@ export type CreatePetsMutationError = ErrorType; * @summary Create a pet */ export const useCreatePets = < + TData = Awaited>>, TError = ErrorType, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>>, + TData, TError, { data: BodyType; version?: number }, TContext >; }): UseMutationResult< - Awaited>>, + TData, TError, { data: BodyType; version?: number }, TContext @@ -260,13 +246,7 @@ export const useListPetsNestedArrayQueryOptions = < >( params?: ListPetsNestedArrayParams, version: number = 1, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -284,11 +264,7 @@ export const useListPetsNestedArrayQueryOptions = < queryFn, enabled: !!version, ...queryOptions, - } as UseQueryOptions< - Awaited>>, - TError, - TData - > & { queryKey: QueryKey }; + } as UseQueryOptions & { queryKey: QueryKey }; }; export type ListPetsNestedArrayQueryResult = NonNullable< @@ -306,13 +282,7 @@ export function useListPetsNestedArray< >( params?: ListPetsNestedArrayParams, version: number = 1, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = useListPetsNestedArrayQueryOptions( params, @@ -357,13 +327,7 @@ export const useShowPetByIdQueryOptions = < >( petId: string, version: number = 1, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -381,11 +345,7 @@ export const useShowPetByIdQueryOptions = < queryFn, enabled: !!(version && petId), ...queryOptions, - } as UseQueryOptions< - Awaited>>, - TError, - TData - > & { queryKey: QueryKey }; + } as UseQueryOptions & { queryKey: QueryKey }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -403,13 +363,7 @@ export function useShowPetById< >( petId: string, version: number = 1, - options?: { - query?: UseQueryOptions< - Awaited>>, - TError, - TData - >; - }, + options?: { query?: UseQueryOptions }, ): UseQueryResult & { queryKey: QueryKey } { const queryOptions = useShowPetByIdQueryOptions(petId, version, options); diff --git a/samples/react-query/custom-client/src/api/model/pet.ts b/samples/react-query/custom-client/src/api/model/pet.ts index 80f8d0a2b..15f469683 100644 --- a/samples/react-query/custom-client/src/api/model/pet.ts +++ b/samples/react-query/custom-client/src/api/model/pet.ts @@ -8,16 +8,6 @@ import type { PetCallingCode } from './petCallingCode'; import type { PetCountry } from './petCountry'; export interface Pet { - /** - * @minimum 0 - * @maximum 30 - * @exclusiveMinimum - * @exclusiveMaximum - */ - age?: number; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; /** * Name of pet @@ -25,9 +15,19 @@ export interface Pet { * @maxLength 0 */ name: string; + /** + * @minimum 0 + * @maximum 30 + * @exclusiveMinimum + * @exclusiveMaximum + */ + age?: number; /** * @nullable * @pattern ^\\d{3}-\\d{2}-\\d{4}$ */ tag?: string | null; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; } diff --git a/samples/react-query/custom-fetch/src/gen/models/dachshund.ts b/samples/react-query/custom-fetch/src/gen/models/dachshund.ts index 149aafa89..7dbf20b0d 100644 --- a/samples/react-query/custom-fetch/src/gen/models/dachshund.ts +++ b/samples/react-query/custom-fetch/src/gen/models/dachshund.ts @@ -7,6 +7,6 @@ import type { DachshundBreed } from './dachshundBreed'; export interface Dachshund { - breed: DachshundBreed; length: number; + breed: DachshundBreed; } diff --git a/samples/react-query/custom-fetch/src/gen/models/labradoodle.ts b/samples/react-query/custom-fetch/src/gen/models/labradoodle.ts index 9ff0cc8de..0ca06f42f 100644 --- a/samples/react-query/custom-fetch/src/gen/models/labradoodle.ts +++ b/samples/react-query/custom-fetch/src/gen/models/labradoodle.ts @@ -7,6 +7,6 @@ import type { LabradoodleBreed } from './labradoodleBreed'; export interface Labradoodle { - breed: LabradoodleBreed; cuteness: number; + breed: LabradoodleBreed; } diff --git a/samples/react-query/custom-fetch/src/gen/models/pet.ts b/samples/react-query/custom-fetch/src/gen/models/pet.ts index 693b339b6..9b538f6eb 100644 --- a/samples/react-query/custom-fetch/src/gen/models/pet.ts +++ b/samples/react-query/custom-fetch/src/gen/models/pet.ts @@ -12,19 +12,19 @@ import type { PetCountry } from './petCountry'; export type Pet = | (Dog & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }) | (Cat & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }); diff --git a/samples/react-query/custom-fetch/src/gen/pets/pets.msw.ts b/samples/react-query/custom-fetch/src/gen/pets/pets.msw.ts index f25b4d844..b6cc1ab67 100644 --- a/samples/react-query/custom-fetch/src/gen/pets/pets.msw.ts +++ b/samples/react-query/custom-fetch/src/gen/pets/pets.msw.ts @@ -12,8 +12,8 @@ export const getListPetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -22,8 +22,8 @@ export const getListPetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -74,6 +74,10 @@ export const getListPetsResponseMock = (): Pets => { ...getListPetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -85,14 +89,14 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getListPetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -104,10 +108,6 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]), ); @@ -116,8 +116,8 @@ export const getCreatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -126,8 +126,8 @@ export const getCreatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -174,6 +174,10 @@ export const getCreatePetsResponseMock = (): Pet => { ...getCreatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -185,14 +189,14 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getCreatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -204,10 +208,6 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -215,8 +215,8 @@ export const getUpdatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -225,8 +225,8 @@ export const getUpdatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -273,6 +273,10 @@ export const getUpdatePetsResponseMock = (): Pet => { ...getUpdatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -284,14 +288,14 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getUpdatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -303,10 +307,6 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -314,8 +314,8 @@ export const getShowPetByIdResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -324,8 +324,8 @@ export const getShowPetByIdResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -372,6 +372,10 @@ export const getShowPetByIdResponseMock = (): Pet => { ...getShowPetByIdResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -383,14 +387,14 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getShowPetByIdResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -402,10 +406,6 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); diff --git a/samples/react-query/custom-fetch/src/gen/pets/pets.ts b/samples/react-query/custom-fetch/src/gen/pets/pets.ts index eeaa98cbd..588e644a2 100644 --- a/samples/react-query/custom-fetch/src/gen/pets/pets.ts +++ b/samples/react-query/custom-fetch/src/gen/pets/pets.ts @@ -84,7 +84,7 @@ export const listPets = async ( params?: ListPetsParams, options?: RequestInit, ): Promise => { - return customFetch>(getListPetsUrl(params), { + return customFetch(getListPetsUrl(params), { ...options, method: 'GET', }); @@ -100,9 +100,7 @@ export const getListPetsQueryOptions = < >( params?: ListPetsParams, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ) => { @@ -115,7 +113,7 @@ export const getListPetsQueryOptions = < }) => listPets(params, { signal, ...requestOptions }); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: DataTag }; @@ -132,17 +130,8 @@ export function useListPets< >( params: undefined | ListPetsParams, options: { - query: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query: Partial> & + Pick, 'initialData'>; request?: SecondParameter; }, ): DefinedUseQueryResult & { @@ -154,17 +143,8 @@ export function useListPets< >( params?: ListPetsParams, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query?: Partial> & + Pick, 'initialData'>; request?: SecondParameter; }, ): UseQueryResult & { queryKey: DataTag }; @@ -174,9 +154,7 @@ export function useListPets< >( params?: ListPetsParams, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ): UseQueryResult & { queryKey: DataTag }; @@ -190,9 +168,7 @@ export function useListPets< >( params?: ListPetsParams, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ): UseQueryResult & { queryKey: DataTag } { @@ -224,7 +200,7 @@ export const createPets = async ( createPetsBodyItem: CreatePetsBodyItem[], options?: RequestInit, ): Promise => { - return customFetch>(getCreatePetsUrl(), { + return customFetch(getCreatePetsUrl(), { ...options, method: 'POST', headers: { 'Content-Type': 'application/json', ...options?.headers }, @@ -233,22 +209,18 @@ export const createPets = async ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext >; request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: CreatePetsBodyItem[] }, - TContext -> => { +}) => { const mutationKey = ['createPets']; const { mutation: mutationOptions, request: requestOptions } = options ? options.mutation && @@ -267,7 +239,12 @@ export const getCreatePetsMutationOptions = < return createPets(data, requestOptions); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBodyItem[] }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -279,16 +256,20 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const useCreatePets = (options?: { +export const useCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext >; request?: SecondParameter; }): UseMutationResult< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext @@ -314,7 +295,7 @@ export const updatePets = async ( pet: NonReadonly, options?: RequestInit, ): Promise => { - return customFetch>(getUpdatePetsUrl(), { + return customFetch(getUpdatePetsUrl(), { ...options, method: 'PUT', headers: { 'Content-Type': 'application/json', ...options?.headers }, @@ -323,22 +304,18 @@ export const updatePets = async ( }; export const getUpdatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: NonReadonly }, TContext >; request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: NonReadonly }, - TContext -> => { +}) => { const mutationKey = ['updatePets']; const { mutation: mutationOptions, request: requestOptions } = options ? options.mutation && @@ -357,7 +334,12 @@ export const getUpdatePetsMutationOptions = < return updatePets(data, requestOptions); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: NonReadonly }, + TContext + >; }; export type UpdatePetsMutationResult = NonNullable< @@ -369,20 +351,19 @@ export type UpdatePetsMutationError = Error; /** * @summary Update a pet */ -export const useUpdatePets = (options?: { +export const useUpdatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: NonReadonly }, TContext >; request?: SecondParameter; -}): UseMutationResult< - Awaited>, - TError, - { data: NonReadonly }, - TContext -> => { +}): UseMutationResult }, TContext> => { const mutationOptions = getUpdatePetsMutationOptions(options); return useMutation(mutationOptions); @@ -404,7 +385,7 @@ export const showPetById = async ( petId: string, options?: RequestInit, ): Promise => { - return customFetch>(getShowPetByIdUrl(petId), { + return customFetch(getShowPetByIdUrl(petId), { ...options, method: 'GET', }); @@ -420,9 +401,7 @@ export const getShowPetByIdQueryOptions = < >( petId: string, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ) => { @@ -439,11 +418,9 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: !!petId, ...queryOptions, - } as UseQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: DataTag }; + } as UseQueryOptions & { + queryKey: DataTag; + }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -457,17 +434,8 @@ export function useShowPetById< >( petId: string, options: { - query: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - DefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query: Partial> & + Pick, 'initialData'>; request?: SecondParameter; }, ): DefinedUseQueryResult & { @@ -479,17 +447,8 @@ export function useShowPetById< >( petId: string, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - > & - Pick< - UndefinedInitialDataOptions< - Awaited>, - TError, - TData - >, - 'initialData' - >; + query?: Partial> & + Pick, 'initialData'>; request?: SecondParameter; }, ): UseQueryResult & { queryKey: DataTag }; @@ -499,9 +458,7 @@ export function useShowPetById< >( petId: string, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ): UseQueryResult & { queryKey: DataTag }; @@ -515,9 +472,7 @@ export function useShowPetById< >( petId: string, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ): UseQueryResult & { queryKey: DataTag } { diff --git a/samples/svelte-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts b/samples/svelte-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts index 86f97bb29..574d27946 100644 --- a/samples/svelte-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts +++ b/samples/svelte-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts @@ -52,13 +52,7 @@ export const getListPetsQueryOptions = < >( params?: ListPetsParams, version: number = 1, - options?: { - query?: CreateQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: CreateQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -74,11 +68,7 @@ export const getListPetsQueryOptions = < queryFn, enabled: !!version, ...queryOptions, - } as CreateQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: QueryKey }; + } as CreateQueryOptions & { queryKey: QueryKey }; }; export type ListPetsQueryResult = NonNullable< @@ -96,13 +86,7 @@ export function createListPets< >( params?: ListPetsParams, version: number = 1, - options?: { - query?: CreateQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: CreateQueryOptions }, ): CreateQueryResult & { queryKey: QueryKey } { const queryOptions = getListPetsQueryOptions(params, version, options); @@ -134,21 +118,17 @@ export const createPets = ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: CreateMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody; version?: number }, TContext >; -}): CreateMutationOptions< - Awaited>, - TError, - { data: CreatePetsBody; version?: number }, - TContext -> => { +}) => { const mutationKey = ['createPets']; const { mutation: mutationOptions } = options ? options.mutation && @@ -167,7 +147,12 @@ export const getCreatePetsMutationOptions = < return createPets(data, version); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as CreateMutationOptions< + TData, + TError, + { data: CreatePetsBody; version?: number }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -179,15 +164,19 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const createCreatePets = (options?: { +export const createCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: CreateMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBody; version?: number }, TContext >; }): CreateMutationResult< - Awaited>, + TData, TError, { data: CreatePetsBody; version?: number }, TContext @@ -222,13 +211,7 @@ export const getShowPetByIdQueryOptions = < >( petId: string, version: number = 1, - options?: { - query?: CreateQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: CreateQueryOptions }, ) => { const { query: queryOptions } = options ?? {}; @@ -244,11 +227,7 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: !!(version && petId), ...queryOptions, - } as CreateQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: QueryKey }; + } as CreateQueryOptions & { queryKey: QueryKey }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -266,13 +245,7 @@ export function createShowPetById< >( petId: string, version: number = 1, - options?: { - query?: CreateQueryOptions< - Awaited>, - TError, - TData - >; - }, + options?: { query?: CreateQueryOptions }, ): CreateQueryResult & { queryKey: QueryKey } { const queryOptions = getShowPetByIdQueryOptions(petId, version, options); diff --git a/samples/svelte-query/custom-fetch/src/gen/models/dachshund.ts b/samples/svelte-query/custom-fetch/src/gen/models/dachshund.ts index 149aafa89..7dbf20b0d 100644 --- a/samples/svelte-query/custom-fetch/src/gen/models/dachshund.ts +++ b/samples/svelte-query/custom-fetch/src/gen/models/dachshund.ts @@ -7,6 +7,6 @@ import type { DachshundBreed } from './dachshundBreed'; export interface Dachshund { - breed: DachshundBreed; length: number; + breed: DachshundBreed; } diff --git a/samples/svelte-query/custom-fetch/src/gen/models/labradoodle.ts b/samples/svelte-query/custom-fetch/src/gen/models/labradoodle.ts index 9ff0cc8de..0ca06f42f 100644 --- a/samples/svelte-query/custom-fetch/src/gen/models/labradoodle.ts +++ b/samples/svelte-query/custom-fetch/src/gen/models/labradoodle.ts @@ -7,6 +7,6 @@ import type { LabradoodleBreed } from './labradoodleBreed'; export interface Labradoodle { - breed: LabradoodleBreed; cuteness: number; + breed: LabradoodleBreed; } diff --git a/samples/svelte-query/custom-fetch/src/gen/models/pet.ts b/samples/svelte-query/custom-fetch/src/gen/models/pet.ts index 693b339b6..9b538f6eb 100644 --- a/samples/svelte-query/custom-fetch/src/gen/models/pet.ts +++ b/samples/svelte-query/custom-fetch/src/gen/models/pet.ts @@ -12,19 +12,19 @@ import type { PetCountry } from './petCountry'; export type Pet = | (Dog & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }) | (Cat & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }); diff --git a/samples/svelte-query/custom-fetch/src/gen/pets/pets.msw.ts b/samples/svelte-query/custom-fetch/src/gen/pets/pets.msw.ts index f25b4d844..b6cc1ab67 100644 --- a/samples/svelte-query/custom-fetch/src/gen/pets/pets.msw.ts +++ b/samples/svelte-query/custom-fetch/src/gen/pets/pets.msw.ts @@ -12,8 +12,8 @@ export const getListPetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -22,8 +22,8 @@ export const getListPetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -74,6 +74,10 @@ export const getListPetsResponseMock = (): Pets => { ...getListPetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -85,14 +89,14 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getListPetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -104,10 +108,6 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]), ); @@ -116,8 +116,8 @@ export const getCreatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -126,8 +126,8 @@ export const getCreatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -174,6 +174,10 @@ export const getCreatePetsResponseMock = (): Pet => { ...getCreatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -185,14 +189,14 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getCreatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -204,10 +208,6 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -215,8 +215,8 @@ export const getUpdatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -225,8 +225,8 @@ export const getUpdatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -273,6 +273,10 @@ export const getUpdatePetsResponseMock = (): Pet => { ...getUpdatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -284,14 +288,14 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getUpdatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -303,10 +307,6 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -314,8 +314,8 @@ export const getShowPetByIdResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -324,8 +324,8 @@ export const getShowPetByIdResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -372,6 +372,10 @@ export const getShowPetByIdResponseMock = (): Pet => { ...getShowPetByIdResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -383,14 +387,14 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getShowPetByIdResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -402,10 +406,6 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); diff --git a/samples/svelte-query/custom-fetch/src/gen/pets/pets.ts b/samples/svelte-query/custom-fetch/src/gen/pets/pets.ts index f1a2756a9..b6e034737 100644 --- a/samples/svelte-query/custom-fetch/src/gen/pets/pets.ts +++ b/samples/svelte-query/custom-fetch/src/gen/pets/pets.ts @@ -80,7 +80,7 @@ export const listPets = async ( params?: ListPetsParams, options?: RequestInit, ): Promise => { - return customFetch>(getListPetsUrl(params), { + return customFetch(getListPetsUrl(params), { ...options, method: 'GET', }); @@ -96,11 +96,7 @@ export const getListPetsQueryOptions = < >( params?: ListPetsParams, options?: { - query?: CreateQueryOptions< - Awaited>, - TError, - TData - >; + query?: CreateQueryOptions; request?: SecondParameter; }, ) => { @@ -113,7 +109,7 @@ export const getListPetsQueryOptions = < }) => listPets(params, { signal, ...requestOptions }); return { queryKey, queryFn, ...queryOptions } as CreateQueryOptions< - Awaited>, + TData, TError, TData > & { queryKey: QueryKey }; @@ -134,11 +130,7 @@ export function createListPets< >( params?: ListPetsParams, options?: { - query?: CreateQueryOptions< - Awaited>, - TError, - TData - >; + query?: CreateQueryOptions; request?: SecondParameter; }, ): CreateQueryResult & { queryKey: QueryKey } { @@ -171,7 +163,7 @@ export const createPets = async ( createPetsBodyItem: CreatePetsBodyItem[], options?: RequestInit, ): Promise => { - return customFetch>(getCreatePetsUrl(), { + return customFetch(getCreatePetsUrl(), { ...options, method: 'POST', headers: { 'Content-Type': 'application/json', ...options?.headers }, @@ -180,22 +172,18 @@ export const createPets = async ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: CreateMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext >; request?: SecondParameter; -}): CreateMutationOptions< - Awaited>, - TError, - { data: CreatePetsBodyItem[] }, - TContext -> => { +}) => { const mutationKey = ['createPets']; const { mutation: mutationOptions, request: requestOptions } = options ? options.mutation && @@ -214,7 +202,12 @@ export const getCreatePetsMutationOptions = < return createPets(data, requestOptions); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as CreateMutationOptions< + TData, + TError, + { data: CreatePetsBodyItem[] }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -226,16 +219,20 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const createCreatePets = (options?: { +export const createCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: CreateMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext >; request?: SecondParameter; }): CreateMutationResult< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext @@ -261,7 +258,7 @@ export const updatePets = async ( pet: NonReadonly, options?: RequestInit, ): Promise => { - return customFetch>(getUpdatePetsUrl(), { + return customFetch(getUpdatePetsUrl(), { ...options, method: 'PUT', headers: { 'Content-Type': 'application/json', ...options?.headers }, @@ -270,22 +267,18 @@ export const updatePets = async ( }; export const getUpdatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: CreateMutationOptions< - Awaited>, + TData, TError, { data: NonReadonly }, TContext >; request?: SecondParameter; -}): CreateMutationOptions< - Awaited>, - TError, - { data: NonReadonly }, - TContext -> => { +}) => { const mutationKey = ['updatePets']; const { mutation: mutationOptions, request: requestOptions } = options ? options.mutation && @@ -304,7 +297,12 @@ export const getUpdatePetsMutationOptions = < return updatePets(data, requestOptions); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as CreateMutationOptions< + TData, + TError, + { data: NonReadonly }, + TContext + >; }; export type UpdatePetsMutationResult = NonNullable< @@ -316,16 +314,20 @@ export type UpdatePetsMutationError = Error; /** * @summary Update a pet */ -export const createUpdatePets = (options?: { +export const createUpdatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: CreateMutationOptions< - Awaited>, + TData, TError, { data: NonReadonly }, TContext >; request?: SecondParameter; }): CreateMutationResult< - Awaited>, + TData, TError, { data: NonReadonly }, TContext @@ -351,7 +353,7 @@ export const showPetById = async ( petId: string, options?: RequestInit, ): Promise => { - return customFetch>(getShowPetByIdUrl(petId), { + return customFetch(getShowPetByIdUrl(petId), { ...options, method: 'GET', }); @@ -367,11 +369,7 @@ export const getShowPetByIdQueryOptions = < >( petId: string, options?: { - query?: CreateQueryOptions< - Awaited>, - TError, - TData - >; + query?: CreateQueryOptions; request?: SecondParameter; }, ) => { @@ -388,11 +386,7 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: !!petId, ...queryOptions, - } as CreateQueryOptions< - Awaited>, - TError, - TData - > & { queryKey: QueryKey }; + } as CreateQueryOptions & { queryKey: QueryKey }; }; export type ShowPetByIdQueryResult = NonNullable< @@ -410,11 +404,7 @@ export function createShowPetById< >( petId: string, options?: { - query?: CreateQueryOptions< - Awaited>, - TError, - TData - >; + query?: CreateQueryOptions; request?: SecondParameter; }, ): CreateQueryResult & { queryKey: QueryKey } { diff --git a/samples/swr-with-zod/src/gen/endpoints/pets/pets.msw.ts b/samples/swr-with-zod/src/gen/endpoints/pets/pets.msw.ts index 2ce4c4290..63654dbd7 100644 --- a/samples/swr-with-zod/src/gen/endpoints/pets/pets.msw.ts +++ b/samples/swr-with-zod/src/gen/endpoints/pets/pets.msw.ts @@ -12,8 +12,8 @@ export const getListPetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -22,8 +22,8 @@ export const getListPetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -74,6 +74,10 @@ export const getListPetsResponseMock = (): Pets => { ...getListPetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -85,14 +89,14 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getListPetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -104,10 +108,6 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]), ); @@ -116,8 +116,8 @@ export const getCreatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -126,8 +126,8 @@ export const getCreatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -174,6 +174,10 @@ export const getCreatePetsResponseMock = (): Pet => { ...getCreatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -185,14 +189,14 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getCreatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -204,10 +208,6 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -215,8 +215,8 @@ export const getUpdatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -225,8 +225,8 @@ export const getUpdatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -273,6 +273,10 @@ export const getUpdatePetsResponseMock = (): Pet => { ...getUpdatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -284,14 +288,14 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getUpdatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -303,10 +307,6 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -314,8 +314,8 @@ export const getShowPetByIdResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -324,8 +324,8 @@ export const getShowPetByIdResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -372,6 +372,10 @@ export const getShowPetByIdResponseMock = (): Pet => { ...getShowPetByIdResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -383,14 +387,14 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getShowPetByIdResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -402,10 +406,6 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); diff --git a/samples/swr-with-zod/src/gen/endpoints/pets/pets.ts b/samples/swr-with-zod/src/gen/endpoints/pets/pets.ts index 51907d3e1..201c82f97 100644 --- a/samples/swr-with-zod/src/gen/endpoints/pets/pets.ts +++ b/samples/swr-with-zod/src/gen/endpoints/pets/pets.ts @@ -75,7 +75,8 @@ export const listPets = async ( ...options, method: 'GET', }); - const data = await res.json(); + + const data: Pets = await res.json(); return { status: res.status, data, headers: res.headers }; }; @@ -142,7 +143,8 @@ export const createPets = async ( headers: { 'Content-Type': 'application/json', ...options?.headers }, body: JSON.stringify(createPetsBodyItem), }); - const data = await res.json(); + + const data: Pet = await res.json(); return { status: res.status, data, headers: res.headers }; }; @@ -211,7 +213,8 @@ export const updatePets = async ( headers: { 'Content-Type': 'application/json', ...options?.headers }, body: JSON.stringify(pet), }); - const data = await res.json(); + + const data: Pet = await res.json(); return { status: res.status, data, headers: res.headers }; }; @@ -278,7 +281,8 @@ export const showPetById = async ( ...options, method: 'GET', }); - const data = await res.json(); + + const data: Pet = await res.json(); return { status: res.status, data, headers: res.headers }; }; diff --git a/samples/swr-with-zod/src/gen/models/dachshund.ts b/samples/swr-with-zod/src/gen/models/dachshund.ts index 149aafa89..7dbf20b0d 100644 --- a/samples/swr-with-zod/src/gen/models/dachshund.ts +++ b/samples/swr-with-zod/src/gen/models/dachshund.ts @@ -7,6 +7,6 @@ import type { DachshundBreed } from './dachshundBreed'; export interface Dachshund { - breed: DachshundBreed; length: number; + breed: DachshundBreed; } diff --git a/samples/swr-with-zod/src/gen/models/labradoodle.ts b/samples/swr-with-zod/src/gen/models/labradoodle.ts index 9ff0cc8de..0ca06f42f 100644 --- a/samples/swr-with-zod/src/gen/models/labradoodle.ts +++ b/samples/swr-with-zod/src/gen/models/labradoodle.ts @@ -7,6 +7,6 @@ import type { LabradoodleBreed } from './labradoodleBreed'; export interface Labradoodle { - breed: LabradoodleBreed; cuteness: number; + breed: LabradoodleBreed; } diff --git a/samples/swr-with-zod/src/gen/models/pet.ts b/samples/swr-with-zod/src/gen/models/pet.ts index 693b339b6..9b538f6eb 100644 --- a/samples/swr-with-zod/src/gen/models/pet.ts +++ b/samples/swr-with-zod/src/gen/models/pet.ts @@ -12,19 +12,19 @@ import type { PetCountry } from './petCountry'; export type Pet = | (Dog & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }) | (Cat & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }); diff --git a/samples/vue-query/custom-fetch/src/gen/models/dachshund.ts b/samples/vue-query/custom-fetch/src/gen/models/dachshund.ts index 149aafa89..7dbf20b0d 100644 --- a/samples/vue-query/custom-fetch/src/gen/models/dachshund.ts +++ b/samples/vue-query/custom-fetch/src/gen/models/dachshund.ts @@ -7,6 +7,6 @@ import type { DachshundBreed } from './dachshundBreed'; export interface Dachshund { - breed: DachshundBreed; length: number; + breed: DachshundBreed; } diff --git a/samples/vue-query/custom-fetch/src/gen/models/labradoodle.ts b/samples/vue-query/custom-fetch/src/gen/models/labradoodle.ts index 9ff0cc8de..0ca06f42f 100644 --- a/samples/vue-query/custom-fetch/src/gen/models/labradoodle.ts +++ b/samples/vue-query/custom-fetch/src/gen/models/labradoodle.ts @@ -7,6 +7,6 @@ import type { LabradoodleBreed } from './labradoodleBreed'; export interface Labradoodle { - breed: LabradoodleBreed; cuteness: number; + breed: LabradoodleBreed; } diff --git a/samples/vue-query/custom-fetch/src/gen/models/pet.ts b/samples/vue-query/custom-fetch/src/gen/models/pet.ts index 693b339b6..9b538f6eb 100644 --- a/samples/vue-query/custom-fetch/src/gen/models/pet.ts +++ b/samples/vue-query/custom-fetch/src/gen/models/pet.ts @@ -12,19 +12,19 @@ import type { PetCountry } from './petCountry'; export type Pet = | (Dog & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }) | (Cat & { '@id'?: string; - callingCode?: PetCallingCode; - country?: PetCountry; - email?: string; id: number; name: string; tag?: string; + email?: string; + callingCode?: PetCallingCode; + country?: PetCountry; }); diff --git a/samples/vue-query/custom-fetch/src/gen/pets/pets.msw.ts b/samples/vue-query/custom-fetch/src/gen/pets/pets.msw.ts index f25b4d844..b6cc1ab67 100644 --- a/samples/vue-query/custom-fetch/src/gen/pets/pets.msw.ts +++ b/samples/vue-query/custom-fetch/src/gen/pets/pets.msw.ts @@ -12,8 +12,8 @@ export const getListPetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -22,8 +22,8 @@ export const getListPetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -74,6 +74,10 @@ export const getListPetsResponseMock = (): Pets => { ...getListPetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -85,14 +89,14 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getListPetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -104,10 +108,6 @@ export const getListPetsResponseMock = (): Pets => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]), ); @@ -116,8 +116,8 @@ export const getCreatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -126,8 +126,8 @@ export const getCreatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -174,6 +174,10 @@ export const getCreatePetsResponseMock = (): Pet => { ...getCreatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -185,14 +189,14 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getCreatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -204,10 +208,6 @@ export const getCreatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -215,8 +215,8 @@ export const getUpdatePetsResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -225,8 +225,8 @@ export const getUpdatePetsResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -273,6 +273,10 @@ export const getUpdatePetsResponseMock = (): Pet => { ...getUpdatePetsResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -284,14 +288,14 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getUpdatePetsResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -303,10 +307,6 @@ export const getUpdatePetsResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); @@ -314,8 +314,8 @@ export const getShowPetByIdResponseLabradoodleMock = ( overrideResponse: Partial = {}, ): Labradoodle => ({ ...{ - breed: faker.helpers.arrayElement(['Labradoodle'] as const), cuteness: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Labradoodle'] as const), }, ...overrideResponse, }); @@ -324,8 +324,8 @@ export const getShowPetByIdResponseDachshundMock = ( overrideResponse: Partial = {}, ): Dachshund => ({ ...{ - breed: faker.helpers.arrayElement(['Dachshund'] as const), length: faker.number.int({ min: undefined, max: undefined }), + breed: faker.helpers.arrayElement(['Dachshund'] as const), }, ...overrideResponse, }); @@ -372,6 +372,10 @@ export const getShowPetByIdResponseMock = (): Pet => { ...getShowPetByIdResponseDogMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -383,14 +387,14 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, { ...getShowPetByIdResponseCatMock(), '@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + id: faker.number.int({ min: undefined, max: undefined }), + name: faker.string.alpha(20), + tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), callingCode: faker.helpers.arrayElement([ faker.helpers.arrayElement(['+33', '+420', '+33'] as const), undefined, @@ -402,10 +406,6 @@ export const getShowPetByIdResponseMock = (): Pet => ] as const), undefined, ]), - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), - id: faker.number.int({ min: undefined, max: undefined }), - name: faker.string.alpha(20), - tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]), }, ]); diff --git a/samples/vue-query/custom-fetch/src/gen/pets/pets.ts b/samples/vue-query/custom-fetch/src/gen/pets/pets.ts index 15c0c6ef8..8c6dc84d4 100644 --- a/samples/vue-query/custom-fetch/src/gen/pets/pets.ts +++ b/samples/vue-query/custom-fetch/src/gen/pets/pets.ts @@ -83,7 +83,7 @@ export const listPets = async ( params?: ListPetsParams, options?: RequestInit, ): Promise => { - return customFetch>(getListPetsUrl(params), { + return customFetch(getListPetsUrl(params), { ...options, method: 'GET', }); @@ -104,9 +104,7 @@ export const getListPetsQueryOptions = < >( params?: MaybeRef, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ) => { @@ -119,7 +117,7 @@ export const getListPetsQueryOptions = < }) => listPets(unref(params), { signal, ...requestOptions }); return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< - Awaited>, + TData, TError, TData >; @@ -140,9 +138,7 @@ export function useListPets< >( params?: MaybeRef, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ): UseQueryReturnType & { queryKey: DataTag } { @@ -174,7 +170,7 @@ export const createPets = async ( createPetsBodyItem: CreatePetsBodyItem[], options?: RequestInit, ): Promise => { - return customFetch>(getCreatePetsUrl(), { + return customFetch(getCreatePetsUrl(), { ...options, method: 'POST', headers: { 'Content-Type': 'application/json', ...options?.headers }, @@ -183,22 +179,18 @@ export const createPets = async ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext >; request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: CreatePetsBodyItem[] }, - TContext -> => { +}) => { const mutationKey = ['createPets']; const { mutation: mutationOptions, request: requestOptions } = options ? options.mutation && @@ -217,7 +209,12 @@ export const getCreatePetsMutationOptions = < return createPets(data, requestOptions); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBodyItem[] }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -229,16 +226,20 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const useCreatePets = (options?: { +export const useCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext >; request?: SecondParameter; }): UseMutationReturnType< - Awaited>, + TData, TError, { data: CreatePetsBodyItem[] }, TContext @@ -264,7 +265,7 @@ export const updatePets = async ( pet: NonReadonly, options?: RequestInit, ): Promise => { - return customFetch>(getUpdatePetsUrl(), { + return customFetch(getUpdatePetsUrl(), { ...options, method: 'PUT', headers: { 'Content-Type': 'application/json', ...options?.headers }, @@ -273,22 +274,18 @@ export const updatePets = async ( }; export const getUpdatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: NonReadonly }, TContext >; request?: SecondParameter; -}): UseMutationOptions< - Awaited>, - TError, - { data: NonReadonly }, - TContext -> => { +}) => { const mutationKey = ['updatePets']; const { mutation: mutationOptions, request: requestOptions } = options ? options.mutation && @@ -307,7 +304,12 @@ export const getUpdatePetsMutationOptions = < return updatePets(data, requestOptions); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: NonReadonly }, + TContext + >; }; export type UpdatePetsMutationResult = NonNullable< @@ -319,16 +321,20 @@ export type UpdatePetsMutationError = Error; /** * @summary Update a pet */ -export const useUpdatePets = (options?: { +export const useUpdatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, { data: NonReadonly }, TContext >; request?: SecondParameter; }): UseMutationReturnType< - Awaited>, + TData, TError, { data: NonReadonly }, TContext @@ -354,7 +360,7 @@ export const showPetById = async ( petId: string, options?: RequestInit, ): Promise => { - return customFetch>(getShowPetByIdUrl(petId), { + return customFetch(getShowPetByIdUrl(petId), { ...options, method: 'GET', }); @@ -370,9 +376,7 @@ export const getShowPetByIdQueryOptions = < >( petId: MaybeRef, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ) => { @@ -389,7 +393,7 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: computed(() => !!unref(petId)), ...queryOptions, - } as UseQueryOptions>, TError, TData>; + } as UseQueryOptions; }; export type ShowPetByIdQueryResult = NonNullable< @@ -407,9 +411,7 @@ export function useShowPetById< >( petId: MaybeRef, options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; + query?: Partial>; request?: SecondParameter; }, ): UseQueryReturnType & { queryKey: DataTag } { diff --git a/samples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts b/samples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts index fe0bb0523..3b26c38e0 100644 --- a/samples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts +++ b/samples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.ts @@ -14,27 +14,27 @@ export const getListPetsResponseMock = (): Pets => { length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1, ).map(() => ({ - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), id: (() => faker.number.int({ min: 1, max: 99999 }))(), name: (() => faker.person.lastName())(), + tag: (() => faker.person.lastName())(), status: faker.helpers.arrayElement([ faker.helpers.arrayElement(Object.values(DomainStatusEnum)), undefined, ]), - tag: (() => faker.person.lastName())(), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), })); export const getCreatePetsResponseMock = ( overrideResponse: Partial = {}, ): Pet => ({ - email: faker.helpers.arrayElement([faker.internet.email(), undefined]), id: faker.number.int({ min: undefined, max: undefined }), name: (() => faker.person.lastName())(), + tag: (() => faker.person.lastName())(), status: faker.helpers.arrayElement([ faker.helpers.arrayElement(Object.values(DomainStatusEnum)), undefined, ]), - tag: (() => faker.person.lastName())(), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), ...overrideResponse, }); diff --git a/samples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts b/samples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts index 74bcd84af..4c59cd38c 100644 --- a/samples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts +++ b/samples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts @@ -67,10 +67,10 @@ export const getListPetsInfiniteQueryOptions = < options?: { query?: Partial< UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -98,10 +98,10 @@ export const getListPetsInfiniteQueryOptions = < enabled: computed(() => !!unref(version)), ...queryOptions, } as UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] >; @@ -128,10 +128,10 @@ export function useListPetsInfinite< options?: { query?: Partial< UseInfiniteQueryOptions< - Awaited>, + TData, TError, TData, - Awaited>, + TData, QueryKey, ListPetsParams['limit'] > @@ -162,11 +162,7 @@ export const getListPetsQueryOptions = < >( params?: MaybeRef, version: MaybeRef = 1, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ) => { const { query: queryOptions } = options ?? {}; @@ -181,7 +177,7 @@ export const getListPetsQueryOptions = < queryFn, enabled: computed(() => !!unref(version)), ...queryOptions, - } as UseQueryOptions>, TError, TData>; + } as UseQueryOptions; }; export type ListPetsQueryResult = NonNullable< @@ -199,11 +195,7 @@ export function useListPets< >( params?: MaybeRef, version: MaybeRef = 1, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ): UseQueryReturnType & { queryKey: DataTag } { const queryOptions = getListPetsQueryOptions(params, version, options); @@ -237,21 +229,17 @@ export const createPets = ( }; export const getCreatePetsMutationOptions = < + TData = Awaited>, TError = Error, TContext = unknown, >(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, - { data: CreatePetsBody; version?: number }, + { data: CreatePetsBody; version?: number | undefined | null }, TContext >; -}): UseMutationOptions< - Awaited>, - TError, - { data: CreatePetsBody; version?: number }, - TContext -> => { +}) => { const mutationKey = ['createPets']; const { mutation: mutationOptions } = options ? options.mutation && @@ -263,14 +251,19 @@ export const getCreatePetsMutationOptions = < const mutationFn: MutationFunction< Awaited>, - { data: CreatePetsBody; version?: number } + { data: CreatePetsBody; version?: number | undefined | null } > = (props) => { const { data, version } = props ?? {}; return createPets(data, version); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + { data: CreatePetsBody; version?: number | undefined | null }, + TContext + >; }; export type CreatePetsMutationResult = NonNullable< @@ -282,17 +275,21 @@ export type CreatePetsMutationError = Error; /** * @summary Create a pet */ -export const useCreatePets = (options?: { +export const useCreatePets = < + TData = Awaited>, + TError = Error, + TContext = unknown, +>(options?: { mutation?: UseMutationOptions< - Awaited>, + TData, TError, - { data: CreatePetsBody; version?: number }, + { data: CreatePetsBody; version?: number | undefined | null }, TContext >; }): UseMutationReturnType< - Awaited>, + TData, TError, - { data: CreatePetsBody; version?: number }, + { data: CreatePetsBody; version?: number | undefined | null }, TContext > => { const mutationOptions = getCreatePetsMutationOptions(options); @@ -331,15 +328,7 @@ export const getShowPetByIdInfiniteQueryOptions = < >( petId: MaybeRef, version: MaybeRef = 1, - options?: { - query?: Partial< - UseInfiniteQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ) => { const { query: queryOptions } = options ?? {}; @@ -354,11 +343,7 @@ export const getShowPetByIdInfiniteQueryOptions = < queryFn, enabled: computed(() => !!(unref(version) && unref(petId))), ...queryOptions, - } as UseInfiniteQueryOptions< - Awaited>, - TError, - TData - >; + } as UseInfiniteQueryOptions; }; export type ShowPetByIdInfiniteQueryResult = NonNullable< @@ -376,15 +361,7 @@ export function useShowPetByIdInfinite< >( petId: MaybeRef, version: MaybeRef = 1, - options?: { - query?: Partial< - UseInfiniteQueryOptions< - Awaited>, - TError, - TData - > - >; - }, + options?: { query?: Partial> }, ): UseInfiniteQueryReturnType & { queryKey: DataTag; } { @@ -410,11 +387,7 @@ export const getShowPetByIdQueryOptions = < >( petId: MaybeRef, version: MaybeRef = 1, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ) => { const { query: queryOptions } = options ?? {}; @@ -429,7 +402,7 @@ export const getShowPetByIdQueryOptions = < queryFn, enabled: computed(() => !!(unref(version) && unref(petId))), ...queryOptions, - } as UseQueryOptions>, TError, TData>; + } as UseQueryOptions; }; export type ShowPetByIdQueryResult = NonNullable< @@ -447,11 +420,7 @@ export function useShowPetById< >( petId: MaybeRef, version: MaybeRef = 1, - options?: { - query?: Partial< - UseQueryOptions>, TError, TData> - >; - }, + options?: { query?: Partial> }, ): UseQueryReturnType & { queryKey: DataTag } { const queryOptions = getShowPetByIdQueryOptions(petId, version, options); @@ -476,21 +445,12 @@ export const postApiV1UserLogout = (signal?: AbortSignal) => { }; export const getPostApiV1UserLogoutMutationOptions = < + TData = Awaited>, TError = unknown, TContext = unknown, >(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - void, - TContext - >; -}): UseMutationOptions< - Awaited>, - TError, - void, - TContext -> => { + mutation?: UseMutationOptions; +}) => { const mutationKey = ['postApiV1UserLogout']; const { mutation: mutationOptions } = options ? options.mutation && @@ -507,7 +467,12 @@ export const getPostApiV1UserLogoutMutationOptions = < return postApiV1UserLogout(); }; - return { mutationFn, ...mutationOptions }; + return { mutationFn, ...mutationOptions } as UseMutationOptions< + TData, + TError, + void, + TContext + >; }; export type PostApiV1UserLogoutMutationResult = NonNullable< @@ -520,21 +485,12 @@ export type PostApiV1UserLogoutMutationError = unknown; * @summary This is required to test case when there are no parameters (this path is ignored in add-version transformer), see https://github.com/orval-labs/orval/issues/857#issuecomment-1835317990 */ export const usePostApiV1UserLogout = < + TData = Awaited>, TError = unknown, TContext = unknown, >(options?: { - mutation?: UseMutationOptions< - Awaited>, - TError, - void, - TContext - >; -}): UseMutationReturnType< - Awaited>, - TError, - void, - TContext -> => { + mutation?: UseMutationOptions; +}): UseMutationReturnType => { const mutationOptions = getPostApiV1UserLogoutMutationOptions(options); return useMutation(mutationOptions); diff --git a/samples/vue-query/vue-query-basic/src/api/model/pet.ts b/samples/vue-query/vue-query-basic/src/api/model/pet.ts index fca98490a..17c142999 100644 --- a/samples/vue-query/vue-query-basic/src/api/model/pet.ts +++ b/samples/vue-query/vue-query-basic/src/api/model/pet.ts @@ -7,9 +7,9 @@ import type { DomainStatusEnum } from './domainStatusEnum'; export interface Pet { - email?: string; id: number; name: string; - status?: DomainStatusEnum; tag?: string; + status?: DomainStatusEnum; + email?: string; }