From d330ff130ba9e197d8fb9b02414cb5d71adfef13 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Sat, 9 Mar 2024 11:10:52 +0100 Subject: [PATCH 1/2] feat: use of enumSuffix --- .changeset/proud-years-tell.md | 5 + docs/plugins/swagger-ts/index.md | 36 +++ examples/advanced/configs/kubb.config.ts | 255 ++++++++-------- examples/advanced/petStore.yaml | 9 + .../advanced/src/gen/clients/axios/index.ts | 2 +- .../advanced/src/gen/clients/hooks/index.ts | 2 +- examples/advanced/src/gen/index.ts | 6 +- .../advanced/src/gen/mocks/createOrder.ts | 2 + .../src/gen/models/ts/AddPetRequest.ts | 6 +- examples/advanced/src/gen/models/ts/Order.ts | 27 +- examples/advanced/src/gen/models/ts/Pet.ts | 6 +- examples/advanced/src/gen/models/ts/index.ts | 6 +- .../ts/petController/FindPetsByStatus.ts | 4 +- .../models/ts/petController/FindPetsByTags.ts | 6 +- .../models/ts/petsController/CreatePets.ts | 6 +- examples/advanced/src/gen/msw/index.ts | 2 +- examples/advanced/src/gen/schemas/Order.json | 2 + examples/advanced/src/gen/schemas2/Order.json | 2 + examples/advanced/src/gen/zod/index.ts | 6 +- examples/advanced/src/gen/zod/orderSchema.ts | 2 + .../react-query-v5/src/gen/hooks/index.ts | 40 +-- .../src/gen/hooks/useAddPetHook.ts | 72 ++--- .../src/gen/hooks/useCreateUserHook.ts | 72 ++--- .../hooks/useCreateUsersWithListInputHook.ts | 72 ++--- .../src/gen/hooks/useDeleteOrderHook.ts | 72 ++--- .../src/gen/hooks/useDeletePetHook.ts | 74 ++--- .../src/gen/hooks/useDeleteUserHook.ts | 72 ++--- .../src/gen/hooks/useFindPetsByStatusHook.ts | 184 ++++++------ .../src/gen/hooks/useFindPetsByTagsHook.ts | 278 ++++++++++-------- .../src/gen/hooks/useGetInventoryHook.ts | 174 +++++------ .../src/gen/hooks/useGetOrderByIdHook.ts | 180 ++++++------ .../src/gen/hooks/useGetPetByIdHook.ts | 178 +++++------ .../src/gen/hooks/useGetUserByNameHook.ts | 177 +++++------ .../src/gen/hooks/useLoginUserHook.ts | 178 +++++------ .../src/gen/hooks/useLogoutUserHook.ts | 170 +++++------ .../src/gen/hooks/usePlaceOrderHook.ts | 72 ++--- .../src/gen/hooks/usePlaceOrderPatchHook.ts | 72 ++--- .../src/gen/hooks/useUpdatePetHook.ts | 72 ++--- .../src/gen/hooks/useUpdatePetWithFormHook.ts | 77 ++--- .../src/gen/hooks/useUpdateUserHook.ts | 74 ++--- .../src/gen/hooks/useUploadFileHook.ts | 74 ++--- examples/react-query-v5/src/gen/index.ts | 4 +- .../react-query-v5/src/gen/models/AddPet.ts | 50 ++-- .../src/gen/models/AddPetRequest.ts | 66 ++--- .../react-query-v5/src/gen/models/Address.ts | 42 +-- .../src/gen/models/ApiResponse.ts | 26 +- .../react-query-v5/src/gen/models/Category.ts | 22 +- .../src/gen/models/CreateUser.ts | 22 +- .../gen/models/CreateUsersWithListInput.ts | 28 +- .../react-query-v5/src/gen/models/Customer.ts | 34 +-- .../src/gen/models/DeleteOrder.ts | 34 +-- .../src/gen/models/DeletePet.ts | 42 +-- .../src/gen/models/DeleteUser.ts | 34 +-- .../src/gen/models/FindPetsByStatus.ts | 54 ++-- .../src/gen/models/FindPetsByTags.ts | 62 ++-- .../src/gen/models/GetInventory.ts | 18 +- .../src/gen/models/GetOrderById.ts | 48 +-- .../src/gen/models/GetPetById.ts | 48 +-- .../src/gen/models/GetUserByName.ts | 48 +-- .../src/gen/models/LoginUser.ts | 48 +-- .../src/gen/models/LogoutUser.ts | 10 +- .../react-query-v5/src/gen/models/Order.ts | 92 +++--- examples/react-query-v5/src/gen/models/Pet.ts | 66 ++--- .../src/gen/models/PetNotFound.ts | 18 +- .../src/gen/models/PlaceOrder.ts | 30 +- .../src/gen/models/PlaceOrderPatch.ts | 30 +- examples/react-query-v5/src/gen/models/Tag.ts | 18 +- .../src/gen/models/UpdatePet.ts | 46 +-- .../src/gen/models/UpdatePetWithForm.ts | 54 ++-- .../src/gen/models/UpdateUser.ts | 38 +-- .../src/gen/models/UploadFile.ts | 54 ++-- .../react-query-v5/src/gen/models/User.ts | 84 +++--- .../src/gen/models/UserArray.ts | 4 +- .../react-query-v5/src/gen/models/index.ts | 62 ++-- packages/swagger-ts/src/TypeGenerator.test.ts | 18 ++ packages/swagger-ts/src/TypeGenerator.ts | 4 +- packages/swagger-ts/src/plugin.ts | 2 + packages/swagger-ts/src/types.ts | 8 + 78 files changed, 2175 insertions(+), 2019 deletions(-) create mode 100644 .changeset/proud-years-tell.md diff --git a/.changeset/proud-years-tell.md b/.changeset/proud-years-tell.md new file mode 100644 index 000000000..239532fd8 --- /dev/null +++ b/.changeset/proud-years-tell.md @@ -0,0 +1,5 @@ +--- +"@kubb/swagger-ts": minor +--- + +use of `enumSuffix` diff --git a/docs/plugins/swagger-ts/index.md b/docs/plugins/swagger-ts/index.md index fa2d95640..c1a6ee70b 100644 --- a/docs/plugins/swagger-ts/index.md +++ b/docs/plugins/swagger-ts/index.md @@ -360,6 +360,42 @@ export default defineConfig({ ::: +### enumSuffix + +Set a suffix for the generated enums. + +::: info Type + +::: info + +Type: `string`
+Default: `''` + +::: code-group + +```typescript +import { defineConfig } from '@kubb/core' +import createSwagger from '@kubb/swagger' +import createSwaggerTS from '@kubb/swagger-ts' + +export default defineConfig({ + input: { + path: './petStore.yaml', + }, + output: { + path: './src/gen', + }, + plugins: [ + createSwagger({ output: false }), + createSwaggerTS({ + enumSuffix: 'enum', + }), + ], +}) +``` + +::: + ### dateType Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`. diff --git a/examples/advanced/configs/kubb.config.ts b/examples/advanced/configs/kubb.config.ts index 107cda121..4125bd7e5 100644 --- a/examples/advanced/configs/kubb.config.ts +++ b/examples/advanced/configs/kubb.config.ts @@ -1,4 +1,13 @@ import { defineConfig } from '@kubb/core' +import { definePlugin as swagger } from '@kubb/swagger' +import { definePlugin as swaggerTS } from '@kubb/swagger-ts' +import { definePlugin as swaggerTanstackQuery } from '@kubb/swagger-tanstack-query' +import { definePlugin as swaggerSwr } from '@kubb/swagger-swr' +import { definePlugin as swaggerClient } from '@kubb/swagger-client' +import { definePlugin as swaggerZod } from '@kubb/swagger-zod' +import { definePlugin as swaggerZodios } from '@kubb/swagger-zodios' +import { definePlugin as swaggerFaker } from '@kubb/swagger-faker' +import { definePlugin as swaggerMsw } from '@kubb/swagger-msw' export default defineConfig(async () => { await setTimeout(() => { @@ -19,161 +28,141 @@ export default defineConfig(async () => { // done: ['npx eslint --fix ./src/gen', 'prettier --write "**/*.{ts,tsx}"', 'pnpm typecheck'], }, plugins: [ - ['@kubb/swagger', { + swagger({ output: { path: 'schemas', }, validate: true, - }], - ['@kubb/swagger', { + }), + swagger({ output: { path: 'schemas2', }, validate: true, - }], - [ - '@kubb/swagger-ts', - { - output: { - path: 'models/ts', - extName: '.js', - }, - group: { - type: 'tag', - }, - enumType: 'asPascalConst', - dateType: 'date', - override: [ - { - type: 'operationId', - pattern: 'findPetsByStatus', - options: { - enumType: 'enum', - }, - }, - ], + }), + swaggerTS({ + output: { + path: 'models/ts', + extName: '.js', }, - ], - [ - '@kubb/swagger-tanstack-query', - { - output: { - path: './clients/hooks', - exportAs: 'hooks', - }, - exclude: [ - { - type: 'tag', - pattern: 'store', - }, - ], - override: [ - { - type: 'tag', - pattern: 'pet', - options: { - infinite: { - queryParam: 'test', - }, - }, - }, - ], - group: { type: 'tag' }, - client: { - importPath: '../../../../tanstack-query-client.ts', - }, - infinite: {}, - dataReturnType: 'full', - parser: 'zod', + group: { + type: 'tag', }, - ], - [ - '@kubb/swagger-swr', - { - output: { - path: './clients/swr', - exportAs: 'swrHooks', - }, - exclude: [ - { - type: 'tag', - pattern: 'store', + enumType: 'asPascalConst', + enumSuffix: 'enum', + dateType: 'date', + override: [ + { + type: 'operationId', + pattern: 'findPetsByStatus', + options: { + enumType: 'enum', }, - ], - group: { type: 'tag' }, - client: { - importPath: '../../../../swr-client.ts', }, - dataReturnType: 'full', + ], + }), + swaggerTanstackQuery({ + output: { + path: './clients/hooks', + exportAs: 'hooks', }, - ], - [ - '@kubb/swagger-client', - { - output: { - path: './clients/axios', - exportAs: 'clients', + exclude: [ + { + type: 'tag', + pattern: 'store', }, - exclude: [ - { - type: 'tag', - pattern: 'store', + ], + override: [ + { + type: 'tag', + pattern: 'pet', + options: { + infinite: { + queryParam: 'test', + initialPageParam: '0', + }, }, - ], - group: { type: 'tag', output: './clients/axios/{{tag}}Service' }, - client: { - importPath: '../../../../axios-client.ts', }, - dataReturnType: 'full', - pathParamsType: 'object', + ], + group: { type: 'tag' }, + client: { + importPath: '../../../../tanstack-query-client.ts', }, - ], - [ - '@kubb/swagger-zod', - { - output: { - path: './zod', - exportAs: 'zod', + infinite: {}, + dataReturnType: 'full', + parser: 'zod', + }), + swaggerSwr({ + output: { + path: './clients/swr', + exportAs: 'swrHooks', + }, + exclude: [ + { + type: 'tag', + pattern: 'store', }, - exclude: [ - { - type: 'tag', - pattern: 'store', - }, - ], - group: { type: 'tag' }, - dateType: 'date', - typed: true, + ], + group: { type: 'tag' }, + client: { + importPath: '../../../../swr-client.ts', }, - ], - [ - '@kubb/swagger-zodios', - { - output: { - path: 'zodios.ts', - exportAs: 'zodios', + dataReturnType: 'full', + }), + swaggerClient({ + output: { + path: './clients/axios', + exportAs: 'clients', + }, + exclude: [ + { + type: 'tag', + pattern: 'store', }, + ], + group: { type: 'tag', output: './clients/axios/{{tag}}Service' }, + client: { + importPath: '../../../../axios-client.ts', }, - ], - [ - '@kubb/swagger-faker', - { - output: { - path: 'mocks', - exportAs: 'faker', + dataReturnType: 'full', + pathParamsType: 'object', + }), + swaggerZod({ + output: { + path: './zod', + exportAs: 'zod', + }, + exclude: [ + { + type: 'tag', + pattern: 'store', }, - exclude: [ - { - type: 'tag', - pattern: 'store', - }, - ], - group: { type: 'tag' }, - dateType: 'date', + ], + group: { type: 'tag' }, + dateType: 'date', + typed: true, + }), + swaggerZodios({ + output: { + path: 'zodios.ts', + exportAs: 'zodios', + }, + }), + swaggerFaker({ + output: { + path: 'mocks', + exportAs: 'faker', }, - ], - [ - '@kubb/swagger-msw', + exclude: [ + { + type: 'tag', + pattern: 'store', + }, + ], + group: { type: 'tag' }, + dateType: 'date', + }), + swaggerMsw( { output: { path: 'msw', @@ -187,7 +176,7 @@ export default defineConfig(async () => { ], group: { type: 'tag' }, }, - ], + ), ], } }) diff --git a/examples/advanced/petStore.yaml b/examples/advanced/petStore.yaml index 0c2b67859..253847309 100644 --- a/examples/advanced/petStore.yaml +++ b/examples/advanced/petStore.yaml @@ -706,6 +706,15 @@ components: type: integer format: int32 example: 7 + orderType: + type: string + enum: + - foo + - bar + type: + type: string + description: Order Status + example: approved shipDate: type: string format: date-time diff --git a/examples/advanced/src/gen/clients/axios/index.ts b/examples/advanced/src/gen/clients/axios/index.ts index 0b1ae337b..1a19f613d 100644 --- a/examples/advanced/src/gen/clients/axios/index.ts +++ b/examples/advanced/src/gen/clients/axios/index.ts @@ -1,4 +1,4 @@ export * from './operations' -export * as petService from './petService/index' export * as petsService from './petsService/index' +export * as petService from './petService/index' export * as userService from './userService/index' diff --git a/examples/advanced/src/gen/clients/hooks/index.ts b/examples/advanced/src/gen/clients/hooks/index.ts index 06f51f5d9..f810e25ca 100644 --- a/examples/advanced/src/gen/clients/hooks/index.ts +++ b/examples/advanced/src/gen/clients/hooks/index.ts @@ -1,3 +1,3 @@ -export * as petHooks from './petController/index' export * as petsHooks from './petsController/index' +export * as petHooks from './petController/index' export * as userHooks from './userController/index' diff --git a/examples/advanced/src/gen/index.ts b/examples/advanced/src/gen/index.ts index 4cf3b8513..7a102c087 100644 --- a/examples/advanced/src/gen/index.ts +++ b/examples/advanced/src/gen/index.ts @@ -1,7 +1,7 @@ -export * as clients from './clients/axios/index' +export * from './models/ts/index.js' export * as hooks from './clients/hooks/index' export * as swrHooks from './clients/swr/index' +export * as clients from './clients/axios/index' +export * as zod from './zod/index' export * as faker from './mocks/index' -export * from './models/ts/index.js' export * as msw from './msw/index' -export * as zod from './zod/index' diff --git a/examples/advanced/src/gen/mocks/createOrder.ts b/examples/advanced/src/gen/mocks/createOrder.ts index 8db84b13b..8ed86b5be 100644 --- a/examples/advanced/src/gen/mocks/createOrder.ts +++ b/examples/advanced/src/gen/mocks/createOrder.ts @@ -7,6 +7,8 @@ export function createOrder(override: NonNullable> = {}): NonNull 'id': faker.number.float({}), 'petId': faker.number.float({}), 'quantity': faker.number.float({}), + 'orderType': faker.helpers.arrayElement([`foo`, `bar`]), + 'type': faker.string.alpha(), 'shipDate': faker.date.anytime(), 'status': faker.helpers.arrayElement([`placed`, `approved`, `delivered`]), 'http_status': faker.helpers.arrayElement([`ok`, `not_found`]), diff --git a/examples/advanced/src/gen/models/ts/AddPetRequest.ts b/examples/advanced/src/gen/models/ts/AddPetRequest.ts index e2874133e..e5700430f 100644 --- a/examples/advanced/src/gen/models/ts/AddPetRequest.ts +++ b/examples/advanced/src/gen/models/ts/AddPetRequest.ts @@ -1,12 +1,12 @@ import type { Category } from './Category' import type { TagTag } from './tag/Tag' -export const AddPetRequestStatus = { +export const AddPetRequestStatusEnum = { 'available': 'available', 'pending': 'pending', 'sold': 'sold', } as const -export type AddPetRequestStatus = (typeof AddPetRequestStatus)[keyof typeof AddPetRequestStatus] +export type AddPetRequestStatusEnum = (typeof AddPetRequestStatusEnum)[keyof typeof AddPetRequestStatusEnum] export type AddPetRequest = { /** * @type integer | undefined int64 @@ -31,5 +31,5 @@ export type AddPetRequest = { * @description pet status in the store * @type string | undefined */ - status?: AddPetRequestStatus + status?: AddPetRequestStatusEnum } diff --git a/examples/advanced/src/gen/models/ts/Order.ts b/examples/advanced/src/gen/models/ts/Order.ts index bf3fb9d97..50437e694 100644 --- a/examples/advanced/src/gen/models/ts/Order.ts +++ b/examples/advanced/src/gen/models/ts/Order.ts @@ -1,14 +1,19 @@ -export const OrderStatus = { +export const OrderOrderTypeEnum = { + 'foo': 'foo', + 'bar': 'bar', +} as const +export type OrderOrderTypeEnum = (typeof OrderOrderTypeEnum)[keyof typeof OrderOrderTypeEnum] +export const OrderStatusEnum = { 'placed': 'placed', 'approved': 'approved', 'delivered': 'delivered', } as const -export type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus] -export const OrderHttpStatus = { +export type OrderStatusEnum = (typeof OrderStatusEnum)[keyof typeof OrderStatusEnum] +export const OrderHttpStatusEnum = { 'ok': 200, 'not_found': 400, } as const -export type OrderHttpStatus = (typeof OrderHttpStatus)[keyof typeof OrderHttpStatus] +export type OrderHttpStatusEnum = (typeof OrderHttpStatusEnum)[keyof typeof OrderHttpStatusEnum] export type Order = { /** * @type integer | undefined int64 @@ -25,6 +30,16 @@ export type Order = { * @example 7 */ quantity?: number + /** + * @type string | undefined + */ + orderType?: OrderOrderTypeEnum + /** + * @description Order Status + * @type string | undefined + * @example approved + */ + type?: string /** * @type string | undefined date-time */ @@ -34,13 +49,13 @@ export type Order = { * @type string | undefined * @example approved */ - status?: OrderStatus + status?: OrderStatusEnum /** * @description HTTP Status * @type number | undefined * @example 200 */ - http_status?: OrderHttpStatus + http_status?: OrderHttpStatusEnum /** * @type boolean | undefined */ diff --git a/examples/advanced/src/gen/models/ts/Pet.ts b/examples/advanced/src/gen/models/ts/Pet.ts index 67c515d37..86def1696 100644 --- a/examples/advanced/src/gen/models/ts/Pet.ts +++ b/examples/advanced/src/gen/models/ts/Pet.ts @@ -1,12 +1,12 @@ import type { Category } from './Category' import type { TagTag } from './tag/Tag' -export const PetStatus = { +export const PetStatusEnum = { 'available': 'available', 'pending': 'pending', 'sold': 'sold', } as const -export type PetStatus = (typeof PetStatus)[keyof typeof PetStatus] +export type PetStatusEnum = (typeof PetStatusEnum)[keyof typeof PetStatusEnum] export type Pet = { /** * @type integer | undefined int64 @@ -31,5 +31,5 @@ export type Pet = { * @description pet status in the store * @type string | undefined */ - status?: PetStatus + status?: PetStatusEnum } diff --git a/examples/advanced/src/gen/models/ts/index.ts b/examples/advanced/src/gen/models/ts/index.ts index 1251cd573..bc8cf77ae 100644 --- a/examples/advanced/src/gen/models/ts/index.ts +++ b/examples/advanced/src/gen/models/ts/index.ts @@ -5,11 +5,11 @@ export * from './Category.js' export * from './Customer.js' export * from './Order.js' export * from './Pet.js' -export * from './petController/index.js' export * from './PetNotFound.js' +export * from './User.js' +export * from './UserArray.js' +export * from './petController/index.js' export * from './petsController/index.js' export * from './storeController/index.js' export * from './tag/index.js' -export * from './User.js' -export * from './UserArray.js' export * from './userController/index.js' diff --git a/examples/advanced/src/gen/models/ts/petController/FindPetsByStatus.ts b/examples/advanced/src/gen/models/ts/petController/FindPetsByStatus.ts index fad7ae628..78d8bc113 100644 --- a/examples/advanced/src/gen/models/ts/petController/FindPetsByStatus.ts +++ b/examples/advanced/src/gen/models/ts/petController/FindPetsByStatus.ts @@ -5,7 +5,7 @@ import type { Pet } from '../Pet' */ export type FindPetsByStatus400 = any -export enum FindPetsByStatusQueryParamsStatus { +export enum FindPetsByStatusQueryParamsStatusEnum { 'available' = 'available', 'pending' = 'pending', 'sold' = 'sold', @@ -16,7 +16,7 @@ export type FindPetsByStatusQueryParams = { * @type string | undefined * @default 'available' */ - status?: FindPetsByStatusQueryParamsStatus + status?: FindPetsByStatusQueryParamsStatusEnum } | undefined /** diff --git a/examples/advanced/src/gen/models/ts/petController/FindPetsByTags.ts b/examples/advanced/src/gen/models/ts/petController/FindPetsByTags.ts index 93dac62ed..80860eb02 100644 --- a/examples/advanced/src/gen/models/ts/petController/FindPetsByTags.ts +++ b/examples/advanced/src/gen/models/ts/petController/FindPetsByTags.ts @@ -5,18 +5,18 @@ import type { Pet } from '../Pet' */ export type FindPetsByTags400 = any -export const FindPetsByTagsHeaderParamsXExample = { +export const FindPetsByTagsHeaderParamsXExampleEnum = { 'ONE': 'ONE', 'TWO': 'TWO', 'THREE': 'THREE', } as const -export type FindPetsByTagsHeaderParamsXExample = (typeof FindPetsByTagsHeaderParamsXExample)[keyof typeof FindPetsByTagsHeaderParamsXExample] +export type FindPetsByTagsHeaderParamsXExampleEnum = (typeof FindPetsByTagsHeaderParamsXExampleEnum)[keyof typeof FindPetsByTagsHeaderParamsXExampleEnum] export type FindPetsByTagsHeaderParams = { /** * @description Header parameters * @type string */ - 'X-EXAMPLE': FindPetsByTagsHeaderParamsXExample + 'X-EXAMPLE': FindPetsByTagsHeaderParamsXExampleEnum } export type FindPetsByTagsQueryParams = { diff --git a/examples/advanced/src/gen/models/ts/petsController/CreatePets.ts b/examples/advanced/src/gen/models/ts/petsController/CreatePets.ts index 27f5a3623..6ee78d8dc 100644 --- a/examples/advanced/src/gen/models/ts/petsController/CreatePets.ts +++ b/examples/advanced/src/gen/models/ts/petsController/CreatePets.ts @@ -5,18 +5,18 @@ import type { PetNotFound } from '../PetNotFound' */ export type CreatePets201 = any -export const CreatePetsHeaderParamsXExample = { +export const CreatePetsHeaderParamsXExampleEnum = { 'ONE': 'ONE', 'TWO': 'TWO', 'THREE': 'THREE', } as const -export type CreatePetsHeaderParamsXExample = (typeof CreatePetsHeaderParamsXExample)[keyof typeof CreatePetsHeaderParamsXExample] +export type CreatePetsHeaderParamsXExampleEnum = (typeof CreatePetsHeaderParamsXExampleEnum)[keyof typeof CreatePetsHeaderParamsXExampleEnum] export type CreatePetsHeaderParams = { /** * @description Header parameters * @type string */ - 'X-EXAMPLE': CreatePetsHeaderParamsXExample + 'X-EXAMPLE': CreatePetsHeaderParamsXExampleEnum } export type CreatePetsMutationRequest = { diff --git a/examples/advanced/src/gen/msw/index.ts b/examples/advanced/src/gen/msw/index.ts index c14a7e57f..dcedf908f 100644 --- a/examples/advanced/src/gen/msw/index.ts +++ b/examples/advanced/src/gen/msw/index.ts @@ -1,4 +1,4 @@ export * from './handlers' -export * as petHandlers from './petController/index' export * as petsHandlers from './petsController/index' +export * as petHandlers from './petController/index' export * as userHandlers from './userController/index' diff --git a/examples/advanced/src/gen/schemas/Order.json b/examples/advanced/src/gen/schemas/Order.json index 29eb2b533..b6a5e8038 100644 --- a/examples/advanced/src/gen/schemas/Order.json +++ b/examples/advanced/src/gen/schemas/Order.json @@ -4,6 +4,8 @@ "id": { "type": "integer", "format": "int64", "example": 10 }, "petId": { "type": "integer", "format": "int64", "example": 198772 }, "quantity": { "type": "integer", "format": "int32", "example": 7 }, + "orderType": { "type": "string", "enum": ["foo", "bar"] }, + "type": { "type": "string", "description": "Order Status", "example": "approved" }, "shipDate": { "type": "string", "format": "date-time" }, "status": { "type": "string", "description": "Order Status", "example": "approved", "enum": ["placed", "approved", "delivered"] }, "http_status": { "type": "number", "description": "HTTP Status", "example": 200, "enum": [200, 400, 500], "x-enumNames": ["ok", "not_found"] }, diff --git a/examples/advanced/src/gen/schemas2/Order.json b/examples/advanced/src/gen/schemas2/Order.json index 29eb2b533..b6a5e8038 100644 --- a/examples/advanced/src/gen/schemas2/Order.json +++ b/examples/advanced/src/gen/schemas2/Order.json @@ -4,6 +4,8 @@ "id": { "type": "integer", "format": "int64", "example": 10 }, "petId": { "type": "integer", "format": "int64", "example": 198772 }, "quantity": { "type": "integer", "format": "int32", "example": 7 }, + "orderType": { "type": "string", "enum": ["foo", "bar"] }, + "type": { "type": "string", "description": "Order Status", "example": "approved" }, "shipDate": { "type": "string", "format": "date-time" }, "status": { "type": "string", "description": "Order Status", "example": "approved", "enum": ["placed", "approved", "delivered"] }, "http_status": { "type": "number", "description": "HTTP Status", "example": 200, "enum": [200, 400, 500], "x-enumNames": ["ok", "not_found"] }, diff --git a/examples/advanced/src/gen/zod/index.ts b/examples/advanced/src/gen/zod/index.ts index f09682b9d..b28c65a55 100644 --- a/examples/advanced/src/gen/zod/index.ts +++ b/examples/advanced/src/gen/zod/index.ts @@ -4,11 +4,11 @@ export * from './apiResponseSchema' export * from './categorySchema' export * from './customerSchema' export * from './orderSchema' -export * as petSchemas from './petController/index' export * from './petNotFoundSchema' export * from './petSchema' -export * as petsSchemas from './petsController/index' export * from './tag/index' export * from './userArraySchema' -export * as userSchemas from './userController/index' export * from './userSchema' +export * as petsSchemas from './petsController/index' +export * as petSchemas from './petController/index' +export * as userSchemas from './userController/index' diff --git a/examples/advanced/src/gen/zod/orderSchema.ts b/examples/advanced/src/gen/zod/orderSchema.ts index a85557d81..115946c3c 100644 --- a/examples/advanced/src/gen/zod/orderSchema.ts +++ b/examples/advanced/src/gen/zod/orderSchema.ts @@ -5,6 +5,8 @@ export const orderSchema = z.object({ 'id': z.number().optional(), 'petId': z.number().optional(), 'quantity': z.number().optional(), + 'orderType': z.enum([`foo`, `bar`]).optional(), + 'type': z.string().describe(`Order Status`).optional(), 'shipDate': z.date().optional(), 'status': z.enum([`placed`, `approved`, `delivered`]).describe(`Order Status`).optional(), 'http_status': z.union([z.literal(200), z.literal(400)]).describe(`HTTP Status`).optional(), diff --git a/examples/react-query-v5/src/gen/hooks/index.ts b/examples/react-query-v5/src/gen/hooks/index.ts index ad8585388..3cd1ec1db 100644 --- a/examples/react-query-v5/src/gen/hooks/index.ts +++ b/examples/react-query-v5/src/gen/hooks/index.ts @@ -1,20 +1,20 @@ -export * from "./useAddPetHook"; -export * from "./useCreateUserHook"; -export * from "./useCreateUsersWithListInputHook"; -export * from "./useDeleteOrderHook"; -export * from "./useDeletePetHook"; -export * from "./useDeleteUserHook"; -export * from "./useFindPetsByStatusHook"; -export * from "./useFindPetsByTagsHook"; -export * from "./useGetInventoryHook"; -export * from "./useGetOrderByIdHook"; -export * from "./useGetPetByIdHook"; -export * from "./useGetUserByNameHook"; -export * from "./useLoginUserHook"; -export * from "./useLogoutUserHook"; -export * from "./usePlaceOrderHook"; -export * from "./usePlaceOrderPatchHook"; -export * from "./useUpdatePetHook"; -export * from "./useUpdatePetWithFormHook"; -export * from "./useUpdateUserHook"; -export * from "./useUploadFileHook"; \ No newline at end of file +export * from './useAddPetHook' +export * from './useCreateUserHook' +export * from './useCreateUsersWithListInputHook' +export * from './useDeleteOrderHook' +export * from './useDeletePetHook' +export * from './useDeleteUserHook' +export * from './useFindPetsByStatusHook' +export * from './useFindPetsByTagsHook' +export * from './useGetInventoryHook' +export * from './useGetOrderByIdHook' +export * from './useGetPetByIdHook' +export * from './useGetUserByNameHook' +export * from './useLoginUserHook' +export * from './useLogoutUserHook' +export * from './usePlaceOrderHook' +export * from './usePlaceOrderPatchHook' +export * from './useUpdatePetHook' +export * from './useUpdatePetWithFormHook' +export * from './useUpdateUserHook' +export * from './useUploadFileHook' diff --git a/examples/react-query-v5/src/gen/hooks/useAddPetHook.ts b/examples/react-query-v5/src/gen/hooks/useAddPetHook.ts index 4e3b7b7b8..8e9e1a3aa 100644 --- a/examples/react-query-v5/src/gen/hooks/useAddPetHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useAddPetHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from "../models/AddPet"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../models/AddPet' +import type { UseMutationOptions } from '@tanstack/react-query' - type AddPetClient = typeof client; +type AddPetClient = typeof client type AddPet = { - data: AddPetMutationResponse; - error: AddPet405; - request: AddPetMutationRequest; - pathParams: never; - queryParams: never; - headerParams: never; - response: AddPetMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: AddPetMutationResponse + error: AddPet405 + request: AddPetMutationRequest + pathParams: never + queryParams: never + headerParams: never + response: AddPetMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description Add a new pet to the store - * @summary Add a new pet to the store - * @link /pet */ + * @description Add a new pet to the store + * @summary Add a new pet to the store + * @link /pet */ export function useAddPetHook(options: { - mutation?: UseMutationOptions; - client?: AddPet["client"]["parameters"]; + mutation?: UseMutationOptions + client?: AddPet['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async (data) => { - const res = await client({ - method: "post", - url: `/pet`, - data, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async (data) => { + const res = await client({ + method: 'post', + url: `/pet`, + data, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts b/examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts index c84f7ea6a..090f2f4cb 100644 --- a/examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useCreateUserHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { CreateUserMutationRequest, CreateUserMutationResponse } from "../models/CreateUser"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../models/CreateUser' +import type { UseMutationOptions } from '@tanstack/react-query' - type CreateUserClient = typeof client; +type CreateUserClient = typeof client type CreateUser = { - data: CreateUserMutationResponse; - error: never; - request: CreateUserMutationRequest; - pathParams: never; - queryParams: never; - headerParams: never; - response: CreateUserMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: CreateUserMutationResponse + error: never + request: CreateUserMutationRequest + pathParams: never + queryParams: never + headerParams: never + response: CreateUserMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description This can only be done by the logged in user. - * @summary Create user - * @link /user */ + * @description This can only be done by the logged in user. + * @summary Create user + * @link /user */ export function useCreateUserHook(options: { - mutation?: UseMutationOptions; - client?: CreateUser["client"]["parameters"]; + mutation?: UseMutationOptions + client?: CreateUser['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async (data) => { - const res = await client({ - method: "post", - url: `/user`, - data, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async (data) => { + const res = await client({ + method: 'post', + url: `/user`, + data, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useCreateUsersWithListInputHook.ts b/examples/react-query-v5/src/gen/hooks/useCreateUsersWithListInputHook.ts index 0a8192a11..712ab7678 100644 --- a/examples/react-query-v5/src/gen/hooks/useCreateUsersWithListInputHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useCreateUsersWithListInputHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { CreateUsersWithListInputMutationRequest, CreateUsersWithListInputMutationResponse } from "../models/CreateUsersWithListInput"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { CreateUsersWithListInputMutationRequest, CreateUsersWithListInputMutationResponse } from '../models/CreateUsersWithListInput' +import type { UseMutationOptions } from '@tanstack/react-query' - type CreateUsersWithListInputClient = typeof client; +type CreateUsersWithListInputClient = typeof client type CreateUsersWithListInput = { - data: CreateUsersWithListInputMutationResponse; - error: never; - request: CreateUsersWithListInputMutationRequest; - pathParams: never; - queryParams: never; - headerParams: never; - response: CreateUsersWithListInputMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: CreateUsersWithListInputMutationResponse + error: never + request: CreateUsersWithListInputMutationRequest + pathParams: never + queryParams: never + headerParams: never + response: CreateUsersWithListInputMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description Creates list of users with given input array - * @summary Creates list of users with given input array - * @link /user/createWithList */ + * @description Creates list of users with given input array + * @summary Creates list of users with given input array + * @link /user/createWithList */ export function useCreateUsersWithListInputHook(options: { - mutation?: UseMutationOptions; - client?: CreateUsersWithListInput["client"]["parameters"]; + mutation?: UseMutationOptions + client?: CreateUsersWithListInput['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async (data) => { - const res = await client({ - method: "post", - url: `/user/createWithList`, - data, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async (data) => { + const res = await client({ + method: 'post', + url: `/user/createWithList`, + data, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts b/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts index 5452bf0db..d23039648 100644 --- a/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useDeleteOrderHook.ts @@ -1,40 +1,40 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400, DeleteOrder404 } from "../models/DeleteOrder"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400, DeleteOrder404 } from '../models/DeleteOrder' +import type { UseMutationOptions } from '@tanstack/react-query' - type DeleteOrderClient = typeof client; +type DeleteOrderClient = typeof client type DeleteOrder = { - data: DeleteOrderMutationResponse; - error: DeleteOrder400 | DeleteOrder404; - request: never; - pathParams: DeleteOrderPathParams; - queryParams: never; - headerParams: never; - response: DeleteOrderMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: DeleteOrderMutationResponse + error: DeleteOrder400 | DeleteOrder404 + request: never + pathParams: DeleteOrderPathParams + queryParams: never + headerParams: never + response: DeleteOrderMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * @summary Delete purchase order by ID - * @link /store/order/:orderId */ -export function useDeleteOrderHook(orderId: DeleteOrderPathParams["orderId"], options: { - mutation?: UseMutationOptions; - client?: DeleteOrder["client"]["parameters"]; + * @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @summary Delete purchase order by ID + * @link /store/order/:orderId */ +export function useDeleteOrderHook(orderId: DeleteOrderPathParams['orderId'], options: { + mutation?: UseMutationOptions + client?: DeleteOrder['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async () => { - const res = await client({ - method: "delete", - url: `/store/order/${orderId}`, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async () => { + const res = await client({ + method: 'delete', + url: `/store/order/${orderId}`, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts b/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts index 20879748f..71455d09d 100644 --- a/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useDeletePetHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from "../models/DeletePet"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from '../models/DeletePet' +import type { UseMutationOptions } from '@tanstack/react-query' - type DeletePetClient = typeof client; +type DeletePetClient = typeof client type DeletePet = { - data: DeletePetMutationResponse; - error: DeletePet400; - request: never; - pathParams: DeletePetPathParams; - queryParams: never; - headerParams: DeletePetHeaderParams; - response: DeletePetMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: DeletePetMutationResponse + error: DeletePet400 + request: never + pathParams: DeletePetPathParams + queryParams: never + headerParams: DeletePetHeaderParams + response: DeletePetMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description delete a pet - * @summary Deletes a pet - * @link /pet/:petId */ -export function useDeletePetHook(petId: DeletePetPathParams["petId"], headers?: DeletePet["headerParams"], options: { - mutation?: UseMutationOptions; - client?: DeletePet["client"]["parameters"]; + * @description delete a pet + * @summary Deletes a pet + * @link /pet/:petId */ +export function useDeletePetHook(petId: DeletePetPathParams['petId'], headers?: DeletePet['headerParams'], options: { + mutation?: UseMutationOptions + client?: DeletePet['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async () => { - const res = await client({ - method: "delete", - url: `/pet/${petId}`, - headers: { ...headers, ...clientOptions.headers }, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async () => { + const res = await client({ + method: 'delete', + url: `/pet/${petId}`, + headers: { ...headers, ...clientOptions.headers }, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts b/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts index 85888edb2..e5cbaaede 100644 --- a/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useDeleteUserHook.ts @@ -1,40 +1,40 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, DeleteUser404 } from "../models/DeleteUser"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, DeleteUser404 } from '../models/DeleteUser' +import type { UseMutationOptions } from '@tanstack/react-query' - type DeleteUserClient = typeof client; +type DeleteUserClient = typeof client type DeleteUser = { - data: DeleteUserMutationResponse; - error: DeleteUser400 | DeleteUser404; - request: never; - pathParams: DeleteUserPathParams; - queryParams: never; - headerParams: never; - response: DeleteUserMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: DeleteUserMutationResponse + error: DeleteUser400 | DeleteUser404 + request: never + pathParams: DeleteUserPathParams + queryParams: never + headerParams: never + response: DeleteUserMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description This can only be done by the logged in user. - * @summary Delete user - * @link /user/:username */ -export function useDeleteUserHook(username: DeleteUserPathParams["username"], options: { - mutation?: UseMutationOptions; - client?: DeleteUser["client"]["parameters"]; + * @description This can only be done by the logged in user. + * @summary Delete user + * @link /user/:username */ +export function useDeleteUserHook(username: DeleteUserPathParams['username'], options: { + mutation?: UseMutationOptions + client?: DeleteUser['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async () => { - const res = await client({ - method: "delete", - url: `/user/${username}`, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async () => { + const res = await client({ + method: 'delete', + url: `/user/${username}`, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useFindPetsByStatusHook.ts b/examples/react-query-v5/src/gen/hooks/useFindPetsByStatusHook.ts index ef2a250ce..2454689b8 100644 --- a/examples/react-query-v5/src/gen/hooks/useFindPetsByStatusHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useFindPetsByStatusHook.ts @@ -1,97 +1,105 @@ -import client from "@kubb/swagger-client/client"; -import { useQuery, queryOptions, useSuspenseQuery } from "@tanstack/react-query"; -import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPetsByStatus400 } from "../models/FindPetsByStatus"; -import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useQuery, queryOptions, useSuspenseQuery } from '@tanstack/react-query' +import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPetsByStatus400 } from '../models/FindPetsByStatus' +import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query' - type FindPetsByStatusClient = typeof client; +type FindPetsByStatusClient = typeof client type FindPetsByStatus = { - data: FindPetsByStatusQueryResponse; - error: FindPetsByStatus400; - request: never; - pathParams: never; - queryParams: FindPetsByStatusQueryParams; - headerParams: never; - response: FindPetsByStatusQueryResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; -export const findPetsByStatusQueryKey = (params?: FindPetsByStatus["queryParams"]) => ["v5", { url: "/pet/findByStatus" }, ...(params ? [params] : [])] as const; -export type FindPetsByStatusQueryKey = ReturnType; -export function findPetsByStatusQueryOptions(params?: FindPetsByStatus["queryParams"], options: FindPetsByStatus["client"]["parameters"] = {}) { - const queryKey = findPetsByStatusQueryKey(params); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/pet/findByStatus`, - params, - ...options - }); - return res.data; - }, - }); + data: FindPetsByStatusQueryResponse + error: FindPetsByStatus400 + request: never + pathParams: never + queryParams: FindPetsByStatusQueryParams + headerParams: never + response: FindPetsByStatusQueryResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} +export const findPetsByStatusQueryKey = (params?: FindPetsByStatus['queryParams']) => ['v5', { url: '/pet/findByStatus' }, ...(params ? [params] : [])] as const +export type FindPetsByStatusQueryKey = ReturnType +export function findPetsByStatusQueryOptions(params?: FindPetsByStatus['queryParams'], options: FindPetsByStatus['client']['parameters'] = {}) { + const queryKey = findPetsByStatusQueryKey(params) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/pet/findByStatus`, + params, + ...options, + }) + return res.data + }, + }) } /** - * @description Multiple status values can be provided with comma separated strings - * @summary Finds Pets by status - * @link /pet/findByStatus */ -export function useFindPetsByStatusHook(params?: FindPetsByStatus["queryParams"], options: { - query?: Partial>; - client?: FindPetsByStatus["client"]["parameters"]; -} = {}): UseQueryResult & { - queryKey: TQueryKey; + * @description Multiple status values can be provided with comma separated strings + * @summary Finds Pets by status + * @link /pet/findByStatus */ +export function useFindPetsByStatusHook< + TData = FindPetsByStatus['response'], + TQueryData = FindPetsByStatus['response'], + TQueryKey extends QueryKey = FindPetsByStatusQueryKey, +>(params?: FindPetsByStatus['queryParams'], options: { + query?: Partial> + client?: FindPetsByStatus['client']['parameters'] +} = {}): UseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? findPetsByStatusQueryKey(params); - const query = useQuery({ - ...findPetsByStatusQueryOptions(params, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? findPetsByStatusQueryKey(params) + const query = useQuery({ + ...findPetsByStatusQueryOptions(params, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const findPetsByStatusSuspenseQueryKey = (params?: FindPetsByStatus["queryParams"]) => ["v5", { url: "/pet/findByStatus" }, ...(params ? [params] : [])] as const; -export type FindPetsByStatusSuspenseQueryKey = ReturnType; -export function findPetsByStatusSuspenseQueryOptions(params?: FindPetsByStatus["queryParams"], options: FindPetsByStatus["client"]["parameters"] = {}) { - const queryKey = findPetsByStatusSuspenseQueryKey(params); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/pet/findByStatus`, - params, - ...options - }); - return res.data; - }, - }); +export const findPetsByStatusSuspenseQueryKey = (params?: FindPetsByStatus['queryParams']) => + ['v5', { url: '/pet/findByStatus' }, ...(params ? [params] : [])] as const +export type FindPetsByStatusSuspenseQueryKey = ReturnType +export function findPetsByStatusSuspenseQueryOptions(params?: FindPetsByStatus['queryParams'], options: FindPetsByStatus['client']['parameters'] = {}) { + const queryKey = findPetsByStatusSuspenseQueryKey(params) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/pet/findByStatus`, + params, + ...options, + }) + return res.data + }, + }) } /** - * @description Multiple status values can be provided with comma separated strings - * @summary Finds Pets by status - * @link /pet/findByStatus */ -export function useFindPetsByStatusHookSuspense(params?: FindPetsByStatus["queryParams"], options: { - query?: Partial>; - client?: FindPetsByStatus["client"]["parameters"]; -} = {}): UseSuspenseQueryResult & { - queryKey: TQueryKey; + * @description Multiple status values can be provided with comma separated strings + * @summary Finds Pets by status + * @link /pet/findByStatus */ +export function useFindPetsByStatusHookSuspense( + params?: FindPetsByStatus['queryParams'], + options: { + query?: Partial> + client?: FindPetsByStatus['client']['parameters'] + } = {}, +): UseSuspenseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? findPetsByStatusSuspenseQueryKey(params); - const query = useSuspenseQuery({ - ...findPetsByStatusSuspenseQueryOptions(params, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseSuspenseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; -} \ No newline at end of file + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? findPetsByStatusSuspenseQueryKey(params) + const query = useSuspenseQuery({ + ...findPetsByStatusSuspenseQueryOptions(params, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query-v5/src/gen/hooks/useFindPetsByTagsHook.ts b/examples/react-query-v5/src/gen/hooks/useFindPetsByTagsHook.ts index 9aab7268c..8dfd16269 100644 --- a/examples/react-query-v5/src/gen/hooks/useFindPetsByTagsHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useFindPetsByTagsHook.ts @@ -1,143 +1,163 @@ -import client from "@kubb/swagger-client/client"; -import { useQuery, queryOptions, useInfiniteQuery, infiniteQueryOptions, useSuspenseQuery } from "@tanstack/react-query"; -import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsByTags400 } from "../models/FindPetsByTags"; -import type { QueryObserverOptions, UseQueryResult, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult, InfiniteData, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useQuery, queryOptions, useInfiniteQuery, infiniteQueryOptions, useSuspenseQuery } from '@tanstack/react-query' +import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsByTags400 } from '../models/FindPetsByTags' +import type { + QueryObserverOptions, + UseQueryResult, + QueryKey, + InfiniteQueryObserverOptions, + UseInfiniteQueryResult, + InfiniteData, + UseSuspenseQueryOptions, + UseSuspenseQueryResult, +} from '@tanstack/react-query' - type FindPetsByTagsClient = typeof client; +type FindPetsByTagsClient = typeof client type FindPetsByTags = { - data: FindPetsByTagsQueryResponse; - error: FindPetsByTags400; - request: never; - pathParams: never; - queryParams: FindPetsByTagsQueryParams; - headerParams: never; - response: Awaited>; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; -export const findPetsByTagsQueryKey = (params?: FindPetsByTags["queryParams"]) => ["/pet/findByTags", ...(params ? [params] : [])] as const; -export type FindPetsByTagsQueryKey = ReturnType; -export function findPetsByTagsQueryOptions(params?: FindPetsByTags["queryParams"], options: FindPetsByTags["client"]["parameters"] = {}) { - const queryKey = findPetsByTagsQueryKey(params); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/pet/findByTags`, - params, - ...options - }); - return res; - }, - }); + data: FindPetsByTagsQueryResponse + error: FindPetsByTags400 + request: never + pathParams: never + queryParams: FindPetsByTagsQueryParams + headerParams: never + response: Awaited> + client: { + parameters: Partial[0]> + return: Awaited> + } +} +export const findPetsByTagsQueryKey = (params?: FindPetsByTags['queryParams']) => ['/pet/findByTags', ...(params ? [params] : [])] as const +export type FindPetsByTagsQueryKey = ReturnType +export function findPetsByTagsQueryOptions(params?: FindPetsByTags['queryParams'], options: FindPetsByTags['client']['parameters'] = {}) { + const queryKey = findPetsByTagsQueryKey(params) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/pet/findByTags`, + params, + ...options, + }) + return res + }, + }) } /** - * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * @summary Finds Pets by tags - * @link /pet/findByTags */ -export function useFindPetsByTagsHook(params?: FindPetsByTags["queryParams"], options: { - query?: Partial>; - client?: FindPetsByTags["client"]["parameters"]; -} = {}): UseQueryResult & { - queryKey: TQueryKey; + * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @summary Finds Pets by tags + * @link /pet/findByTags */ +export function useFindPetsByTagsHook< + TData = FindPetsByTags['response'], + TQueryData = FindPetsByTags['response'], + TQueryKey extends QueryKey = FindPetsByTagsQueryKey, +>(params?: FindPetsByTags['queryParams'], options: { + query?: Partial> + client?: FindPetsByTags['client']['parameters'] +} = {}): UseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params); - const query = useQuery({ - ...findPetsByTagsQueryOptions(params, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) + const query = useQuery({ + ...findPetsByTagsQueryOptions(params, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTags["queryParams"]) => ["/pet/findByTags", ...(params ? [params] : [])] as const; -export type FindPetsByTagsInfiniteQueryKey = ReturnType; -export function findPetsByTagsInfiniteQueryOptions(params?: FindPetsByTags["queryParams"], options: FindPetsByTags["client"]["parameters"] = {}) { - const queryKey = findPetsByTagsInfiniteQueryKey(params); - return infiniteQueryOptions({ - queryKey, - queryFn: async ({ pageParam }) => { - const res = await client({ - method: "get", - url: `/pet/findByTags`, - ...options, - params: { - ...params, - ["pageSize"]: pageParam, - ...(options.params || {}), - } - }); - return res; +export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTags['queryParams']) => ['/pet/findByTags', ...(params ? [params] : [])] as const +export type FindPetsByTagsInfiniteQueryKey = ReturnType +export function findPetsByTagsInfiniteQueryOptions(params?: FindPetsByTags['queryParams'], options: FindPetsByTags['client']['parameters'] = {}) { + const queryKey = findPetsByTagsInfiniteQueryKey(params) + return infiniteQueryOptions({ + queryKey, + queryFn: async ({ pageParam }) => { + const res = await client({ + method: 'get', + url: `/pet/findByTags`, + ...options, + params: { + ...params, + ['pageSize']: pageParam, + ...(options.params || {}), }, - initialPageParam: 0, - getNextPageParam: (lastPage, allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1, - getPreviousPageParam: (firstPage, allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1 - }); + }) + return res + }, + initialPageParam: 0, + getNextPageParam: (lastPage, allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1, + getPreviousPageParam: (firstPage, allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1, + }) } /** - * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * @summary Finds Pets by tags - * @link /pet/findByTags */ -export function useFindPetsByTagsHookInfinite, TQueryData = FindPetsByTags["response"], TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(params?: FindPetsByTags["queryParams"], options: { - query?: Partial>; - client?: FindPetsByTags["client"]["parameters"]; -} = {}): UseInfiniteQueryResult & { - queryKey: TQueryKey; + * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @summary Finds Pets by tags + * @link /pet/findByTags */ +export function useFindPetsByTagsHookInfinite< + TData = InfiniteData, + TQueryData = FindPetsByTags['response'], + TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey, +>(params?: FindPetsByTags['queryParams'], options: { + query?: Partial> + client?: FindPetsByTags['client']['parameters'] +} = {}): UseInfiniteQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? findPetsByTagsInfiniteQueryKey(params); - const query = useInfiniteQuery({ - ...findPetsByTagsInfiniteQueryOptions(params, clientOptions) as InfiniteQueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseInfiniteQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? findPetsByTagsInfiniteQueryKey(params) + const query = useInfiniteQuery({ + ...findPetsByTagsInfiniteQueryOptions(params, clientOptions) as InfiniteQueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseInfiniteQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const findPetsByTagsSuspenseQueryKey = (params?: FindPetsByTags["queryParams"]) => ["/pet/findByTags", ...(params ? [params] : [])] as const; -export type FindPetsByTagsSuspenseQueryKey = ReturnType; -export function findPetsByTagsSuspenseQueryOptions(params?: FindPetsByTags["queryParams"], options: FindPetsByTags["client"]["parameters"] = {}) { - const queryKey = findPetsByTagsSuspenseQueryKey(params); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/pet/findByTags`, - params, - ...options - }); - return res; - }, - }); +export const findPetsByTagsSuspenseQueryKey = (params?: FindPetsByTags['queryParams']) => ['/pet/findByTags', ...(params ? [params] : [])] as const +export type FindPetsByTagsSuspenseQueryKey = ReturnType +export function findPetsByTagsSuspenseQueryOptions(params?: FindPetsByTags['queryParams'], options: FindPetsByTags['client']['parameters'] = {}) { + const queryKey = findPetsByTagsSuspenseQueryKey(params) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/pet/findByTags`, + params, + ...options, + }) + return res + }, + }) } /** - * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * @summary Finds Pets by tags - * @link /pet/findByTags */ -export function useFindPetsByTagsHookSuspense(params?: FindPetsByTags["queryParams"], options: { - query?: Partial>; - client?: FindPetsByTags["client"]["parameters"]; -} = {}): UseSuspenseQueryResult & { - queryKey: TQueryKey; + * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @summary Finds Pets by tags + * @link /pet/findByTags */ +export function useFindPetsByTagsHookSuspense( + params?: FindPetsByTags['queryParams'], + options: { + query?: Partial> + client?: FindPetsByTags['client']['parameters'] + } = {}, +): UseSuspenseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? findPetsByTagsSuspenseQueryKey(params); - const query = useSuspenseQuery({ - ...findPetsByTagsSuspenseQueryOptions(params, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseSuspenseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; -} \ No newline at end of file + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? findPetsByTagsSuspenseQueryKey(params) + const query = useSuspenseQuery({ + ...findPetsByTagsSuspenseQueryOptions(params, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query-v5/src/gen/hooks/useGetInventoryHook.ts b/examples/react-query-v5/src/gen/hooks/useGetInventoryHook.ts index ca5bdb21d..5c029de22 100644 --- a/examples/react-query-v5/src/gen/hooks/useGetInventoryHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useGetInventoryHook.ts @@ -1,95 +1,97 @@ -import client from "@kubb/swagger-client/client"; -import { useQuery, queryOptions, useSuspenseQuery } from "@tanstack/react-query"; -import type { GetInventoryQueryResponse } from "../models/GetInventory"; -import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useQuery, queryOptions, useSuspenseQuery } from '@tanstack/react-query' +import type { GetInventoryQueryResponse } from '../models/GetInventory' +import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query' - type GetInventoryClient = typeof client; +type GetInventoryClient = typeof client type GetInventory = { - data: GetInventoryQueryResponse; - error: never; - request: never; - pathParams: never; - queryParams: never; - headerParams: never; - response: GetInventoryQueryResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; -export const getInventoryQueryKey = () => ["v5", { url: "/store/inventory" }] as const; -export type GetInventoryQueryKey = ReturnType; -export function getInventoryQueryOptions(options: GetInventory["client"]["parameters"] = {}) { - const queryKey = getInventoryQueryKey(); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/store/inventory`, - ...options - }); - return res.data; - }, - }); + data: GetInventoryQueryResponse + error: never + request: never + pathParams: never + queryParams: never + headerParams: never + response: GetInventoryQueryResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} +export const getInventoryQueryKey = () => ['v5', { url: '/store/inventory' }] as const +export type GetInventoryQueryKey = ReturnType +export function getInventoryQueryOptions(options: GetInventory['client']['parameters'] = {}) { + const queryKey = getInventoryQueryKey() + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/store/inventory`, + ...options, + }) + return res.data + }, + }) } /** - * @description Returns a map of status codes to quantities - * @summary Returns pet inventories by status - * @link /store/inventory */ -export function useGetInventoryHook(options: { - query?: Partial>; - client?: GetInventory["client"]["parameters"]; -} = {}): UseQueryResult & { - queryKey: TQueryKey; + * @description Returns a map of status codes to quantities + * @summary Returns pet inventories by status + * @link /store/inventory */ +export function useGetInventoryHook( + options: { + query?: Partial> + client?: GetInventory['client']['parameters'] + } = {}, +): UseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getInventoryQueryKey(); - const query = useQuery({ - ...getInventoryQueryOptions(clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getInventoryQueryKey() + const query = useQuery({ + ...getInventoryQueryOptions(clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const getInventorySuspenseQueryKey = () => ["v5", { url: "/store/inventory" }] as const; -export type GetInventorySuspenseQueryKey = ReturnType; -export function getInventorySuspenseQueryOptions(options: GetInventory["client"]["parameters"] = {}) { - const queryKey = getInventorySuspenseQueryKey(); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/store/inventory`, - ...options - }); - return res.data; - }, - }); +export const getInventorySuspenseQueryKey = () => ['v5', { url: '/store/inventory' }] as const +export type GetInventorySuspenseQueryKey = ReturnType +export function getInventorySuspenseQueryOptions(options: GetInventory['client']['parameters'] = {}) { + const queryKey = getInventorySuspenseQueryKey() + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/store/inventory`, + ...options, + }) + return res.data + }, + }) } /** - * @description Returns a map of status codes to quantities - * @summary Returns pet inventories by status - * @link /store/inventory */ -export function useGetInventoryHookSuspense(options: { - query?: Partial>; - client?: GetInventory["client"]["parameters"]; -} = {}): UseSuspenseQueryResult & { - queryKey: TQueryKey; + * @description Returns a map of status codes to quantities + * @summary Returns pet inventories by status + * @link /store/inventory */ +export function useGetInventoryHookSuspense(options: { + query?: Partial> + client?: GetInventory['client']['parameters'] +} = {}): UseSuspenseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getInventorySuspenseQueryKey(); - const query = useSuspenseQuery({ - ...getInventorySuspenseQueryOptions(clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseSuspenseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; -} \ No newline at end of file + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getInventorySuspenseQueryKey() + const query = useSuspenseQuery({ + ...getInventorySuspenseQueryOptions(clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query-v5/src/gen/hooks/useGetOrderByIdHook.ts b/examples/react-query-v5/src/gen/hooks/useGetOrderByIdHook.ts index 7251a2dff..518d47da0 100644 --- a/examples/react-query-v5/src/gen/hooks/useGetOrderByIdHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useGetOrderByIdHook.ts @@ -1,95 +1,103 @@ -import client from "@kubb/swagger-client/client"; -import { useQuery, queryOptions, useSuspenseQuery } from "@tanstack/react-query"; -import type { GetOrderByIdQueryResponse, GetOrderByIdPathParams, GetOrderById400, GetOrderById404 } from "../models/GetOrderById"; -import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useQuery, queryOptions, useSuspenseQuery } from '@tanstack/react-query' +import type { GetOrderByIdQueryResponse, GetOrderByIdPathParams, GetOrderById400, GetOrderById404 } from '../models/GetOrderById' +import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query' - type GetOrderByIdClient = typeof client; +type GetOrderByIdClient = typeof client type GetOrderById = { - data: GetOrderByIdQueryResponse; - error: GetOrderById400 | GetOrderById404; - request: never; - pathParams: GetOrderByIdPathParams; - queryParams: never; - headerParams: never; - response: GetOrderByIdQueryResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; -export const getOrderByIdQueryKey = (orderId: GetOrderByIdPathParams["orderId"]) => ["v5", { url: "/store/order/:orderId", params: { orderId: orderId } }] as const; -export type GetOrderByIdQueryKey = ReturnType; -export function getOrderByIdQueryOptions(orderId: GetOrderByIdPathParams["orderId"], options: GetOrderById["client"]["parameters"] = {}) { - const queryKey = getOrderByIdQueryKey(orderId); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/store/order/${orderId}`, - ...options - }); - return res.data; - }, - }); + data: GetOrderByIdQueryResponse + error: GetOrderById400 | GetOrderById404 + request: never + pathParams: GetOrderByIdPathParams + queryParams: never + headerParams: never + response: GetOrderByIdQueryResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} +export const getOrderByIdQueryKey = (orderId: GetOrderByIdPathParams['orderId']) => + ['v5', { url: '/store/order/:orderId', params: { orderId: orderId } }] as const +export type GetOrderByIdQueryKey = ReturnType +export function getOrderByIdQueryOptions(orderId: GetOrderByIdPathParams['orderId'], options: GetOrderById['client']['parameters'] = {}) { + const queryKey = getOrderByIdQueryKey(orderId) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/store/order/${orderId}`, + ...options, + }) + return res.data + }, + }) } /** - * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. - * @summary Find purchase order by ID - * @link /store/order/:orderId */ -export function useGetOrderByIdHook(orderId: GetOrderByIdPathParams["orderId"], options: { - query?: Partial>; - client?: GetOrderById["client"]["parameters"]; -} = {}): UseQueryResult & { - queryKey: TQueryKey; + * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. + * @summary Find purchase order by ID + * @link /store/order/:orderId */ +export function useGetOrderByIdHook( + orderId: GetOrderByIdPathParams['orderId'], + options: { + query?: Partial> + client?: GetOrderById['client']['parameters'] + } = {}, +): UseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getOrderByIdQueryKey(orderId); - const query = useQuery({ - ...getOrderByIdQueryOptions(orderId, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getOrderByIdQueryKey(orderId) + const query = useQuery({ + ...getOrderByIdQueryOptions(orderId, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const getOrderByIdSuspenseQueryKey = (orderId: GetOrderByIdPathParams["orderId"]) => ["v5", { url: "/store/order/:orderId", params: { orderId: orderId } }] as const; -export type GetOrderByIdSuspenseQueryKey = ReturnType; -export function getOrderByIdSuspenseQueryOptions(orderId: GetOrderByIdPathParams["orderId"], options: GetOrderById["client"]["parameters"] = {}) { - const queryKey = getOrderByIdSuspenseQueryKey(orderId); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/store/order/${orderId}`, - ...options - }); - return res.data; - }, - }); +export const getOrderByIdSuspenseQueryKey = (orderId: GetOrderByIdPathParams['orderId']) => + ['v5', { url: '/store/order/:orderId', params: { orderId: orderId } }] as const +export type GetOrderByIdSuspenseQueryKey = ReturnType +export function getOrderByIdSuspenseQueryOptions(orderId: GetOrderByIdPathParams['orderId'], options: GetOrderById['client']['parameters'] = {}) { + const queryKey = getOrderByIdSuspenseQueryKey(orderId) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/store/order/${orderId}`, + ...options, + }) + return res.data + }, + }) } /** - * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. - * @summary Find purchase order by ID - * @link /store/order/:orderId */ -export function useGetOrderByIdHookSuspense(orderId: GetOrderByIdPathParams["orderId"], options: { - query?: Partial>; - client?: GetOrderById["client"]["parameters"]; -} = {}): UseSuspenseQueryResult & { - queryKey: TQueryKey; + * @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. + * @summary Find purchase order by ID + * @link /store/order/:orderId */ +export function useGetOrderByIdHookSuspense( + orderId: GetOrderByIdPathParams['orderId'], + options: { + query?: Partial> + client?: GetOrderById['client']['parameters'] + } = {}, +): UseSuspenseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getOrderByIdSuspenseQueryKey(orderId); - const query = useSuspenseQuery({ - ...getOrderByIdSuspenseQueryOptions(orderId, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseSuspenseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; -} \ No newline at end of file + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getOrderByIdSuspenseQueryKey(orderId) + const query = useSuspenseQuery({ + ...getOrderByIdSuspenseQueryOptions(orderId, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query-v5/src/gen/hooks/useGetPetByIdHook.ts b/examples/react-query-v5/src/gen/hooks/useGetPetByIdHook.ts index 2d46dc957..81fc8cc85 100644 --- a/examples/react-query-v5/src/gen/hooks/useGetPetByIdHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useGetPetByIdHook.ts @@ -1,95 +1,101 @@ -import client from "@kubb/swagger-client/client"; -import { useQuery, queryOptions, useSuspenseQuery } from "@tanstack/react-query"; -import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetPetById404 } from "../models/GetPetById"; -import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useQuery, queryOptions, useSuspenseQuery } from '@tanstack/react-query' +import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetPetById404 } from '../models/GetPetById' +import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query' - type GetPetByIdClient = typeof client; +type GetPetByIdClient = typeof client type GetPetById = { - data: GetPetByIdQueryResponse; - error: GetPetById400 | GetPetById404; - request: never; - pathParams: GetPetByIdPathParams; - queryParams: never; - headerParams: never; - response: GetPetByIdQueryResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; -export const getPetByIdQueryKey = (petId: GetPetByIdPathParams["petId"]) => ["v5", { url: "/pet/:petId", params: { petId: petId } }] as const; -export type GetPetByIdQueryKey = ReturnType; -export function getPetByIdQueryOptions(petId: GetPetByIdPathParams["petId"], options: GetPetById["client"]["parameters"] = {}) { - const queryKey = getPetByIdQueryKey(petId); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/pet/${petId}`, - ...options - }); - return res.data; - }, - }); + data: GetPetByIdQueryResponse + error: GetPetById400 | GetPetById404 + request: never + pathParams: GetPetByIdPathParams + queryParams: never + headerParams: never + response: GetPetByIdQueryResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} +export const getPetByIdQueryKey = (petId: GetPetByIdPathParams['petId']) => ['v5', { url: '/pet/:petId', params: { petId: petId } }] as const +export type GetPetByIdQueryKey = ReturnType +export function getPetByIdQueryOptions(petId: GetPetByIdPathParams['petId'], options: GetPetById['client']['parameters'] = {}) { + const queryKey = getPetByIdQueryKey(petId) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/pet/${petId}`, + ...options, + }) + return res.data + }, + }) } /** - * @description Returns a single pet - * @summary Find pet by ID - * @link /pet/:petId */ -export function useGetPetByIdHook(petId: GetPetByIdPathParams["petId"], options: { - query?: Partial>; - client?: GetPetById["client"]["parameters"]; -} = {}): UseQueryResult & { - queryKey: TQueryKey; + * @description Returns a single pet + * @summary Find pet by ID + * @link /pet/:petId */ +export function useGetPetByIdHook( + petId: GetPetByIdPathParams['petId'], + options: { + query?: Partial> + client?: GetPetById['client']['parameters'] + } = {}, +): UseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey(petId); - const query = useQuery({ - ...getPetByIdQueryOptions(petId, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey(petId) + const query = useQuery({ + ...getPetByIdQueryOptions(petId, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const getPetByIdSuspenseQueryKey = (petId: GetPetByIdPathParams["petId"]) => ["v5", { url: "/pet/:petId", params: { petId: petId } }] as const; -export type GetPetByIdSuspenseQueryKey = ReturnType; -export function getPetByIdSuspenseQueryOptions(petId: GetPetByIdPathParams["petId"], options: GetPetById["client"]["parameters"] = {}) { - const queryKey = getPetByIdSuspenseQueryKey(petId); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/pet/${petId}`, - ...options - }); - return res.data; - }, - }); +export const getPetByIdSuspenseQueryKey = (petId: GetPetByIdPathParams['petId']) => ['v5', { url: '/pet/:petId', params: { petId: petId } }] as const +export type GetPetByIdSuspenseQueryKey = ReturnType +export function getPetByIdSuspenseQueryOptions(petId: GetPetByIdPathParams['petId'], options: GetPetById['client']['parameters'] = {}) { + const queryKey = getPetByIdSuspenseQueryKey(petId) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/pet/${petId}`, + ...options, + }) + return res.data + }, + }) } /** - * @description Returns a single pet - * @summary Find pet by ID - * @link /pet/:petId */ -export function useGetPetByIdHookSuspense(petId: GetPetByIdPathParams["petId"], options: { - query?: Partial>; - client?: GetPetById["client"]["parameters"]; -} = {}): UseSuspenseQueryResult & { - queryKey: TQueryKey; + * @description Returns a single pet + * @summary Find pet by ID + * @link /pet/:petId */ +export function useGetPetByIdHookSuspense( + petId: GetPetByIdPathParams['petId'], + options: { + query?: Partial> + client?: GetPetById['client']['parameters'] + } = {}, +): UseSuspenseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getPetByIdSuspenseQueryKey(petId); - const query = useSuspenseQuery({ - ...getPetByIdSuspenseQueryOptions(petId, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseSuspenseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; -} \ No newline at end of file + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getPetByIdSuspenseQueryKey(petId) + const query = useSuspenseQuery({ + ...getPetByIdSuspenseQueryOptions(petId, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query-v5/src/gen/hooks/useGetUserByNameHook.ts b/examples/react-query-v5/src/gen/hooks/useGetUserByNameHook.ts index 51d2eb3f8..92a7e10ef 100644 --- a/examples/react-query-v5/src/gen/hooks/useGetUserByNameHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useGetUserByNameHook.ts @@ -1,93 +1,102 @@ -import client from "@kubb/swagger-client/client"; -import { useQuery, queryOptions, useSuspenseQuery } from "@tanstack/react-query"; -import type { GetUserByNameQueryResponse, GetUserByNamePathParams, GetUserByName400, GetUserByName404 } from "../models/GetUserByName"; -import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useQuery, queryOptions, useSuspenseQuery } from '@tanstack/react-query' +import type { GetUserByNameQueryResponse, GetUserByNamePathParams, GetUserByName400, GetUserByName404 } from '../models/GetUserByName' +import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query' - type GetUserByNameClient = typeof client; +type GetUserByNameClient = typeof client type GetUserByName = { - data: GetUserByNameQueryResponse; - error: GetUserByName400 | GetUserByName404; - request: never; - pathParams: GetUserByNamePathParams; - queryParams: never; - headerParams: never; - response: GetUserByNameQueryResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; -export const getUserByNameQueryKey = (username: GetUserByNamePathParams["username"]) => ["v5", { url: "/user/:username", params: { username: username } }] as const; -export type GetUserByNameQueryKey = ReturnType; -export function getUserByNameQueryOptions(username: GetUserByNamePathParams["username"], options: GetUserByName["client"]["parameters"] = {}) { - const queryKey = getUserByNameQueryKey(username); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/user/${username}`, - ...options - }); - return res.data; - }, - }); + data: GetUserByNameQueryResponse + error: GetUserByName400 | GetUserByName404 + request: never + pathParams: GetUserByNamePathParams + queryParams: never + headerParams: never + response: GetUserByNameQueryResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} +export const getUserByNameQueryKey = (username: GetUserByNamePathParams['username']) => + ['v5', { url: '/user/:username', params: { username: username } }] as const +export type GetUserByNameQueryKey = ReturnType +export function getUserByNameQueryOptions(username: GetUserByNamePathParams['username'], options: GetUserByName['client']['parameters'] = {}) { + const queryKey = getUserByNameQueryKey(username) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/user/${username}`, + ...options, + }) + return res.data + }, + }) } /** - * @summary Get user by user name - * @link /user/:username */ -export function useGetUserByNameHook(username: GetUserByNamePathParams["username"], options: { - query?: Partial>; - client?: GetUserByName["client"]["parameters"]; -} = {}): UseQueryResult & { - queryKey: TQueryKey; + * @summary Get user by user name + * @link /user/:username */ +export function useGetUserByNameHook< + TData = GetUserByName['response'], + TQueryData = GetUserByName['response'], + TQueryKey extends QueryKey = GetUserByNameQueryKey, +>(username: GetUserByNamePathParams['username'], options: { + query?: Partial> + client?: GetUserByName['client']['parameters'] +} = {}): UseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getUserByNameQueryKey(username); - const query = useQuery({ - ...getUserByNameQueryOptions(username, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getUserByNameQueryKey(username) + const query = useQuery({ + ...getUserByNameQueryOptions(username, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const getUserByNameSuspenseQueryKey = (username: GetUserByNamePathParams["username"]) => ["v5", { url: "/user/:username", params: { username: username } }] as const; -export type GetUserByNameSuspenseQueryKey = ReturnType; -export function getUserByNameSuspenseQueryOptions(username: GetUserByNamePathParams["username"], options: GetUserByName["client"]["parameters"] = {}) { - const queryKey = getUserByNameSuspenseQueryKey(username); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/user/${username}`, - ...options - }); - return res.data; - }, - }); +export const getUserByNameSuspenseQueryKey = (username: GetUserByNamePathParams['username']) => + ['v5', { url: '/user/:username', params: { username: username } }] as const +export type GetUserByNameSuspenseQueryKey = ReturnType +export function getUserByNameSuspenseQueryOptions(username: GetUserByNamePathParams['username'], options: GetUserByName['client']['parameters'] = {}) { + const queryKey = getUserByNameSuspenseQueryKey(username) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/user/${username}`, + ...options, + }) + return res.data + }, + }) } /** - * @summary Get user by user name - * @link /user/:username */ -export function useGetUserByNameHookSuspense(username: GetUserByNamePathParams["username"], options: { - query?: Partial>; - client?: GetUserByName["client"]["parameters"]; -} = {}): UseSuspenseQueryResult & { - queryKey: TQueryKey; + * @summary Get user by user name + * @link /user/:username */ +export function useGetUserByNameHookSuspense( + username: GetUserByNamePathParams['username'], + options: { + query?: Partial> + client?: GetUserByName['client']['parameters'] + } = {}, +): UseSuspenseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? getUserByNameSuspenseQueryKey(username); - const query = useSuspenseQuery({ - ...getUserByNameSuspenseQueryOptions(username, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseSuspenseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; -} \ No newline at end of file + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? getUserByNameSuspenseQueryKey(username) + const query = useSuspenseQuery({ + ...getUserByNameSuspenseQueryOptions(username, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query-v5/src/gen/hooks/useLoginUserHook.ts b/examples/react-query-v5/src/gen/hooks/useLoginUserHook.ts index 860bd8c33..f289a0b0d 100644 --- a/examples/react-query-v5/src/gen/hooks/useLoginUserHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useLoginUserHook.ts @@ -1,95 +1,101 @@ -import client from "@kubb/swagger-client/client"; -import { useQuery, queryOptions, useSuspenseQuery } from "@tanstack/react-query"; -import type { LoginUserQueryResponse, LoginUserQueryParams, LoginUser400 } from "../models/LoginUser"; -import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useQuery, queryOptions, useSuspenseQuery } from '@tanstack/react-query' +import type { LoginUserQueryResponse, LoginUserQueryParams, LoginUser400 } from '../models/LoginUser' +import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query' - type LoginUserClient = typeof client; +type LoginUserClient = typeof client type LoginUser = { - data: LoginUserQueryResponse; - error: LoginUser400; - request: never; - pathParams: never; - queryParams: LoginUserQueryParams; - headerParams: never; - response: LoginUserQueryResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; -export const loginUserQueryKey = (params?: LoginUser["queryParams"]) => ["v5", { url: "/user/login" }, ...(params ? [params] : [])] as const; -export type LoginUserQueryKey = ReturnType; -export function loginUserQueryOptions(params?: LoginUser["queryParams"], options: LoginUser["client"]["parameters"] = {}) { - const queryKey = loginUserQueryKey(params); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/user/login`, - params, - ...options - }); - return res.data; - }, - }); + data: LoginUserQueryResponse + error: LoginUser400 + request: never + pathParams: never + queryParams: LoginUserQueryParams + headerParams: never + response: LoginUserQueryResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} +export const loginUserQueryKey = (params?: LoginUser['queryParams']) => ['v5', { url: '/user/login' }, ...(params ? [params] : [])] as const +export type LoginUserQueryKey = ReturnType +export function loginUserQueryOptions(params?: LoginUser['queryParams'], options: LoginUser['client']['parameters'] = {}) { + const queryKey = loginUserQueryKey(params) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/user/login`, + params, + ...options, + }) + return res.data + }, + }) } /** - * @summary Logs user into the system - * @link /user/login */ -export function useLoginUserHook(params?: LoginUser["queryParams"], options: { - query?: Partial>; - client?: LoginUser["client"]["parameters"]; -} = {}): UseQueryResult & { - queryKey: TQueryKey; + * @summary Logs user into the system + * @link /user/login */ +export function useLoginUserHook( + params?: LoginUser['queryParams'], + options: { + query?: Partial> + client?: LoginUser['client']['parameters'] + } = {}, +): UseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? loginUserQueryKey(params); - const query = useQuery({ - ...loginUserQueryOptions(params, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? loginUserQueryKey(params) + const query = useQuery({ + ...loginUserQueryOptions(params, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const loginUserSuspenseQueryKey = (params?: LoginUser["queryParams"]) => ["v5", { url: "/user/login" }, ...(params ? [params] : [])] as const; -export type LoginUserSuspenseQueryKey = ReturnType; -export function loginUserSuspenseQueryOptions(params?: LoginUser["queryParams"], options: LoginUser["client"]["parameters"] = {}) { - const queryKey = loginUserSuspenseQueryKey(params); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/user/login`, - params, - ...options - }); - return res.data; - }, - }); +export const loginUserSuspenseQueryKey = (params?: LoginUser['queryParams']) => ['v5', { url: '/user/login' }, ...(params ? [params] : [])] as const +export type LoginUserSuspenseQueryKey = ReturnType +export function loginUserSuspenseQueryOptions(params?: LoginUser['queryParams'], options: LoginUser['client']['parameters'] = {}) { + const queryKey = loginUserSuspenseQueryKey(params) + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/user/login`, + params, + ...options, + }) + return res.data + }, + }) } /** - * @summary Logs user into the system - * @link /user/login */ -export function useLoginUserHookSuspense(params?: LoginUser["queryParams"], options: { - query?: Partial>; - client?: LoginUser["client"]["parameters"]; -} = {}): UseSuspenseQueryResult & { - queryKey: TQueryKey; + * @summary Logs user into the system + * @link /user/login */ +export function useLoginUserHookSuspense( + params?: LoginUser['queryParams'], + options: { + query?: Partial> + client?: LoginUser['client']['parameters'] + } = {}, +): UseSuspenseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? loginUserSuspenseQueryKey(params); - const query = useSuspenseQuery({ - ...loginUserSuspenseQueryOptions(params, clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseSuspenseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; -} \ No newline at end of file + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? loginUserSuspenseQueryKey(params) + const query = useSuspenseQuery({ + ...loginUserSuspenseQueryOptions(params, clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query-v5/src/gen/hooks/useLogoutUserHook.ts b/examples/react-query-v5/src/gen/hooks/useLogoutUserHook.ts index 475d4be6b..006039c0f 100644 --- a/examples/react-query-v5/src/gen/hooks/useLogoutUserHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useLogoutUserHook.ts @@ -1,93 +1,95 @@ -import client from "@kubb/swagger-client/client"; -import { useQuery, queryOptions, useSuspenseQuery } from "@tanstack/react-query"; -import type { LogoutUserQueryResponse } from "../models/LogoutUser"; -import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useQuery, queryOptions, useSuspenseQuery } from '@tanstack/react-query' +import type { LogoutUserQueryResponse } from '../models/LogoutUser' +import type { QueryObserverOptions, UseQueryResult, QueryKey, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query' - type LogoutUserClient = typeof client; +type LogoutUserClient = typeof client type LogoutUser = { - data: LogoutUserQueryResponse; - error: never; - request: never; - pathParams: never; - queryParams: never; - headerParams: never; - response: LogoutUserQueryResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; -export const logoutUserQueryKey = () => ["v5", { url: "/user/logout" }] as const; -export type LogoutUserQueryKey = ReturnType; -export function logoutUserQueryOptions(options: LogoutUser["client"]["parameters"] = {}) { - const queryKey = logoutUserQueryKey(); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/user/logout`, - ...options - }); - return res.data; - }, - }); + data: LogoutUserQueryResponse + error: never + request: never + pathParams: never + queryParams: never + headerParams: never + response: LogoutUserQueryResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} +export const logoutUserQueryKey = () => ['v5', { url: '/user/logout' }] as const +export type LogoutUserQueryKey = ReturnType +export function logoutUserQueryOptions(options: LogoutUser['client']['parameters'] = {}) { + const queryKey = logoutUserQueryKey() + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/user/logout`, + ...options, + }) + return res.data + }, + }) } /** - * @summary Logs out current logged in user session - * @link /user/logout */ -export function useLogoutUserHook(options: { - query?: Partial>; - client?: LogoutUser["client"]["parameters"]; -} = {}): UseQueryResult & { - queryKey: TQueryKey; + * @summary Logs out current logged in user session + * @link /user/logout */ +export function useLogoutUserHook( + options: { + query?: Partial> + client?: LogoutUser['client']['parameters'] + } = {}, +): UseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? logoutUserQueryKey(); - const query = useQuery({ - ...logoutUserQueryOptions(clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? logoutUserQueryKey() + const query = useQuery({ + ...logoutUserQueryOptions(clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query } -export const logoutUserSuspenseQueryKey = () => ["v5", { url: "/user/logout" }] as const; -export type LogoutUserSuspenseQueryKey = ReturnType; -export function logoutUserSuspenseQueryOptions(options: LogoutUser["client"]["parameters"] = {}) { - const queryKey = logoutUserSuspenseQueryKey(); - return queryOptions({ - queryKey, - queryFn: async () => { - const res = await client({ - method: "get", - url: `/user/logout`, - ...options - }); - return res.data; - }, - }); +export const logoutUserSuspenseQueryKey = () => ['v5', { url: '/user/logout' }] as const +export type LogoutUserSuspenseQueryKey = ReturnType +export function logoutUserSuspenseQueryOptions(options: LogoutUser['client']['parameters'] = {}) { + const queryKey = logoutUserSuspenseQueryKey() + return queryOptions({ + queryKey, + queryFn: async () => { + const res = await client({ + method: 'get', + url: `/user/logout`, + ...options, + }) + return res.data + }, + }) } /** - * @summary Logs out current logged in user session - * @link /user/logout */ -export function useLogoutUserHookSuspense(options: { - query?: Partial>; - client?: LogoutUser["client"]["parameters"]; -} = {}): UseSuspenseQueryResult & { - queryKey: TQueryKey; + * @summary Logs out current logged in user session + * @link /user/logout */ +export function useLogoutUserHookSuspense(options: { + query?: Partial> + client?: LogoutUser['client']['parameters'] +} = {}): UseSuspenseQueryResult & { + queryKey: TQueryKey } { - const { query: queryOptions, client: clientOptions = {} } = options ?? {}; - const queryKey = queryOptions?.queryKey ?? logoutUserSuspenseQueryKey(); - const query = useSuspenseQuery({ - ...logoutUserSuspenseQueryOptions(clientOptions) as QueryObserverOptions, - queryKey, - ...queryOptions as unknown as Omit - }) as UseSuspenseQueryResult & { - queryKey: TQueryKey; - }; - query.queryKey = queryKey as TQueryKey; - return query; -} \ No newline at end of file + const { query: queryOptions, client: clientOptions = {} } = options ?? {} + const queryKey = queryOptions?.queryKey ?? logoutUserSuspenseQueryKey() + const query = useSuspenseQuery({ + ...logoutUserSuspenseQueryOptions(clientOptions) as QueryObserverOptions, + queryKey, + ...queryOptions as unknown as Omit, + }) as UseSuspenseQueryResult & { + queryKey: TQueryKey + } + query.queryKey = queryKey as TQueryKey + return query +} diff --git a/examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts b/examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts index b2f23f8c6..a6767827f 100644 --- a/examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts +++ b/examples/react-query-v5/src/gen/hooks/usePlaceOrderHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { PlaceOrderMutationRequest, PlaceOrderMutationResponse, PlaceOrder405 } from "../models/PlaceOrder"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { PlaceOrderMutationRequest, PlaceOrderMutationResponse, PlaceOrder405 } from '../models/PlaceOrder' +import type { UseMutationOptions } from '@tanstack/react-query' - type PlaceOrderClient = typeof client; +type PlaceOrderClient = typeof client type PlaceOrder = { - data: PlaceOrderMutationResponse; - error: PlaceOrder405; - request: PlaceOrderMutationRequest; - pathParams: never; - queryParams: never; - headerParams: never; - response: PlaceOrderMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: PlaceOrderMutationResponse + error: PlaceOrder405 + request: PlaceOrderMutationRequest + pathParams: never + queryParams: never + headerParams: never + response: PlaceOrderMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description Place a new order in the store - * @summary Place an order for a pet - * @link /store/order */ + * @description Place a new order in the store + * @summary Place an order for a pet + * @link /store/order */ export function usePlaceOrderHook(options: { - mutation?: UseMutationOptions; - client?: PlaceOrder["client"]["parameters"]; + mutation?: UseMutationOptions + client?: PlaceOrder['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async (data) => { - const res = await client({ - method: "post", - url: `/store/order`, - data, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async (data) => { + const res = await client({ + method: 'post', + url: `/store/order`, + data, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts b/examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts index 7bb3b73b7..b0bfa3bc0 100644 --- a/examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts +++ b/examples/react-query-v5/src/gen/hooks/usePlaceOrderPatchHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { PlaceOrderPatchMutationRequest, PlaceOrderPatchMutationResponse, PlaceOrderPatch405 } from "../models/PlaceOrderPatch"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { PlaceOrderPatchMutationRequest, PlaceOrderPatchMutationResponse, PlaceOrderPatch405 } from '../models/PlaceOrderPatch' +import type { UseMutationOptions } from '@tanstack/react-query' - type PlaceOrderPatchClient = typeof client; +type PlaceOrderPatchClient = typeof client type PlaceOrderPatch = { - data: PlaceOrderPatchMutationResponse; - error: PlaceOrderPatch405; - request: PlaceOrderPatchMutationRequest; - pathParams: never; - queryParams: never; - headerParams: never; - response: PlaceOrderPatchMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: PlaceOrderPatchMutationResponse + error: PlaceOrderPatch405 + request: PlaceOrderPatchMutationRequest + pathParams: never + queryParams: never + headerParams: never + response: PlaceOrderPatchMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description Place a new order in the store with patch - * @summary Place an order for a pet with patch - * @link /store/order */ + * @description Place a new order in the store with patch + * @summary Place an order for a pet with patch + * @link /store/order */ export function usePlaceOrderPatchHook(options: { - mutation?: UseMutationOptions; - client?: PlaceOrderPatch["client"]["parameters"]; + mutation?: UseMutationOptions + client?: PlaceOrderPatch['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async (data) => { - const res = await client({ - method: "patch", - url: `/store/order`, - data, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async (data) => { + const res = await client({ + method: 'patch', + url: `/store/order`, + data, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts b/examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts index 039a447ed..509f41ed0 100644 --- a/examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useUpdatePetHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { UpdatePetMutationRequest, UpdatePetMutationResponse, UpdatePet400, UpdatePet404, UpdatePet405 } from "../models/UpdatePet"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { UpdatePetMutationRequest, UpdatePetMutationResponse, UpdatePet400, UpdatePet404, UpdatePet405 } from '../models/UpdatePet' +import type { UseMutationOptions } from '@tanstack/react-query' - type UpdatePetClient = typeof client; +type UpdatePetClient = typeof client type UpdatePet = { - data: UpdatePetMutationResponse; - error: UpdatePet400 | UpdatePet404 | UpdatePet405; - request: UpdatePetMutationRequest; - pathParams: never; - queryParams: never; - headerParams: never; - response: UpdatePetMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: UpdatePetMutationResponse + error: UpdatePet400 | UpdatePet404 | UpdatePet405 + request: UpdatePetMutationRequest + pathParams: never + queryParams: never + headerParams: never + response: UpdatePetMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description Update an existing pet by Id - * @summary Update an existing pet - * @link /pet */ + * @description Update an existing pet by Id + * @summary Update an existing pet + * @link /pet */ export function useUpdatePetHook(options: { - mutation?: UseMutationOptions; - client?: UpdatePet["client"]["parameters"]; + mutation?: UseMutationOptions + client?: UpdatePet['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async (data) => { - const res = await client({ - method: "put", - url: `/pet`, - data, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async (data) => { + const res = await client({ + method: 'put', + url: `/pet`, + data, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts b/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts index 85a0fb408..c9600a116 100644 --- a/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useUpdatePetWithFormHook.ts @@ -1,40 +1,45 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { UpdatePetWithFormMutationResponse, UpdatePetWithFormPathParams, UpdatePetWithFormQueryParams, UpdatePetWithForm405 } from "../models/UpdatePetWithForm"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { + UpdatePetWithFormMutationResponse, + UpdatePetWithFormPathParams, + UpdatePetWithFormQueryParams, + UpdatePetWithForm405, +} from '../models/UpdatePetWithForm' +import type { UseMutationOptions } from '@tanstack/react-query' - type UpdatePetWithFormClient = typeof client; +type UpdatePetWithFormClient = typeof client type UpdatePetWithForm = { - data: UpdatePetWithFormMutationResponse; - error: UpdatePetWithForm405; - request: never; - pathParams: UpdatePetWithFormPathParams; - queryParams: UpdatePetWithFormQueryParams; - headerParams: never; - response: UpdatePetWithFormMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: UpdatePetWithFormMutationResponse + error: UpdatePetWithForm405 + request: never + pathParams: UpdatePetWithFormPathParams + queryParams: UpdatePetWithFormQueryParams + headerParams: never + response: UpdatePetWithFormMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @summary Updates a pet in the store with form data - * @link /pet/:petId */ -export function useUpdatePetWithFormHook(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithForm["queryParams"], options: { - mutation?: UseMutationOptions; - client?: UpdatePetWithForm["client"]["parameters"]; + * @summary Updates a pet in the store with form data + * @link /pet/:petId */ +export function useUpdatePetWithFormHook(petId: UpdatePetWithFormPathParams['petId'], params?: UpdatePetWithForm['queryParams'], options: { + mutation?: UseMutationOptions + client?: UpdatePetWithForm['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async () => { - const res = await client({ - method: "post", - url: `/pet/${petId}`, - params, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async () => { + const res = await client({ + method: 'post', + url: `/pet/${petId}`, + params, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts b/examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts index b1db5a30c..17523d215 100644 --- a/examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useUpdateUserHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserPathParams } from "../models/UpdateUser"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserPathParams } from '../models/UpdateUser' +import type { UseMutationOptions } from '@tanstack/react-query' - type UpdateUserClient = typeof client; +type UpdateUserClient = typeof client type UpdateUser = { - data: UpdateUserMutationResponse; - error: never; - request: UpdateUserMutationRequest; - pathParams: UpdateUserPathParams; - queryParams: never; - headerParams: never; - response: UpdateUserMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: UpdateUserMutationResponse + error: never + request: UpdateUserMutationRequest + pathParams: UpdateUserPathParams + queryParams: never + headerParams: never + response: UpdateUserMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @description This can only be done by the logged in user. - * @summary Update user - * @link /user/:username */ -export function useUpdateUserHook(username: UpdateUserPathParams["username"], options: { - mutation?: UseMutationOptions; - client?: UpdateUser["client"]["parameters"]; + * @description This can only be done by the logged in user. + * @summary Update user + * @link /user/:username */ +export function useUpdateUserHook(username: UpdateUserPathParams['username'], options: { + mutation?: UseMutationOptions + client?: UpdateUser['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async (data) => { - const res = await client({ - method: "put", - url: `/user/${username}`, - data, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async (data) => { + const res = await client({ + method: 'put', + url: `/user/${username}`, + data, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts b/examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts index b353c57b6..a14013320 100644 --- a/examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts +++ b/examples/react-query-v5/src/gen/hooks/useUploadFileHook.ts @@ -1,41 +1,41 @@ -import client from "@kubb/swagger-client/client"; -import { useMutation } from "@tanstack/react-query"; -import type { UploadFileMutationRequest, UploadFileMutationResponse, UploadFilePathParams, UploadFileQueryParams } from "../models/UploadFile"; -import type { UseMutationOptions } from "@tanstack/react-query"; +import client from '@kubb/swagger-client/client' +import { useMutation } from '@tanstack/react-query' +import type { UploadFileMutationRequest, UploadFileMutationResponse, UploadFilePathParams, UploadFileQueryParams } from '../models/UploadFile' +import type { UseMutationOptions } from '@tanstack/react-query' - type UploadFileClient = typeof client; +type UploadFileClient = typeof client type UploadFile = { - data: UploadFileMutationResponse; - error: never; - request: UploadFileMutationRequest; - pathParams: UploadFilePathParams; - queryParams: UploadFileQueryParams; - headerParams: never; - response: UploadFileMutationResponse; - client: { - parameters: Partial[0]>; - return: Awaited>; - }; -}; + data: UploadFileMutationResponse + error: never + request: UploadFileMutationRequest + pathParams: UploadFilePathParams + queryParams: UploadFileQueryParams + headerParams: never + response: UploadFileMutationResponse + client: { + parameters: Partial[0]> + return: Awaited> + } +} /** - * @summary uploads an image - * @link /pet/:petId/uploadImage */ -export function useUploadFileHook(petId: UploadFilePathParams["petId"], params?: UploadFile["queryParams"], options: { - mutation?: UseMutationOptions; - client?: UploadFile["client"]["parameters"]; + * @summary uploads an image + * @link /pet/:petId/uploadImage */ +export function useUploadFileHook(petId: UploadFilePathParams['petId'], params?: UploadFile['queryParams'], options: { + mutation?: UseMutationOptions + client?: UploadFile['client']['parameters'] } = {}) { - const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}; - return useMutation({ - mutationFn: async (data) => { - const res = await client({ - method: "post", - url: `/pet/${petId}/uploadImage`, - params, - data, - ...clientOptions - }); - return res.data; - }, - ...mutationOptions - }); -} \ No newline at end of file + const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {} + return useMutation({ + mutationFn: async (data) => { + const res = await client({ + method: 'post', + url: `/pet/${petId}/uploadImage`, + params, + data, + ...clientOptions, + }) + return res.data + }, + ...mutationOptions, + }) +} diff --git a/examples/react-query-v5/src/gen/index.ts b/examples/react-query-v5/src/gen/index.ts index 91cd800f9..6e6f12d44 100644 --- a/examples/react-query-v5/src/gen/index.ts +++ b/examples/react-query-v5/src/gen/index.ts @@ -1,2 +1,2 @@ -export * from "./models/index"; -export * from "./hooks/index"; \ No newline at end of file +export * from './models/index' +export * from './hooks/index' diff --git a/examples/react-query-v5/src/gen/models/AddPet.ts b/examples/react-query-v5/src/gen/models/AddPet.ts index 4d0758aa7..df8322e73 100644 --- a/examples/react-query-v5/src/gen/models/AddPet.ts +++ b/examples/react-query-v5/src/gen/models/AddPet.ts @@ -1,33 +1,33 @@ -import type { Pet } from "./Pet"; -import type { AddPetRequest } from "./AddPetRequest"; +import type { Pet } from './Pet' +import type { AddPetRequest } from './AddPetRequest' - export type AddPet405 = { - /** - * @type integer | undefined int32 - */ - code?: number; - /** - * @type string | undefined - */ - message?: string; -}; +export type AddPet405 = { + /** + * @type integer | undefined int32 + */ + code?: number + /** + * @type string | undefined + */ + message?: string +} - /** +/** * @description Successful operation -*/ -export type AddPet200 = Pet; + */ +export type AddPet200 = Pet - /** +/** * @description Create a new pet in the store -*/ -export type AddPetMutationRequest = AddPetRequest; + */ +export type AddPetMutationRequest = AddPetRequest - /** +/** * @description Successful operation -*/ -export type AddPetMutationResponse = Pet; + */ +export type AddPetMutationResponse = Pet export type AddPetMutation = { - Response: AddPetMutationResponse; - Request: AddPetMutationRequest; - Errors: AddPet405; -}; \ No newline at end of file + Response: AddPetMutationResponse + Request: AddPetMutationRequest + Errors: AddPet405 +} diff --git a/examples/react-query-v5/src/gen/models/AddPetRequest.ts b/examples/react-query-v5/src/gen/models/AddPetRequest.ts index 0b8ac309d..bdf0bf29c 100644 --- a/examples/react-query-v5/src/gen/models/AddPetRequest.ts +++ b/examples/react-query-v5/src/gen/models/AddPetRequest.ts @@ -1,35 +1,35 @@ -import type { Category } from "./Category"; -import type { Tag } from "./Tag"; +import type { Category } from './Category' +import type { Tag } from './Tag' - export const addPetRequestStatus = { - "available": "available", - "pending": "pending", - "sold": "sold" -} as const; -export type AddPetRequestStatus = (typeof addPetRequestStatus)[keyof typeof addPetRequestStatus]; +export const addPetRequestStatus = { + 'available': 'available', + 'pending': 'pending', + 'sold': 'sold', +} as const +export type AddPetRequestStatus = (typeof addPetRequestStatus)[keyof typeof addPetRequestStatus] export type AddPetRequest = { - /** - * @type integer | undefined int64 - * @example 10 - */ - id?: number; - /** - * @type string - * @example doggie - */ - name: string; - category?: Category; - /** - * @type array - */ - photoUrls: string[]; - /** - * @type array | undefined - */ - tags?: Tag[]; - /** - * @description pet status in the store - * @type string | undefined - */ - status?: AddPetRequestStatus; -}; \ No newline at end of file + /** + * @type integer | undefined int64 + * @example 10 + */ + id?: number + /** + * @type string + * @example doggie + */ + name: string + category?: Category + /** + * @type array + */ + photoUrls: string[] + /** + * @type array | undefined + */ + tags?: Tag[] + /** + * @description pet status in the store + * @type string | undefined + */ + status?: AddPetRequestStatus +} diff --git a/examples/react-query-v5/src/gen/models/Address.ts b/examples/react-query-v5/src/gen/models/Address.ts index 31c48bb16..dd04fd4a1 100644 --- a/examples/react-query-v5/src/gen/models/Address.ts +++ b/examples/react-query-v5/src/gen/models/Address.ts @@ -1,22 +1,22 @@ export type Address = { - /** - * @type string | undefined - * @example 437 Lytton - */ - street?: string; - /** - * @type string | undefined - * @example Palo Alto - */ - city?: string; - /** - * @type string | undefined - * @example CA - */ - state?: string; - /** - * @type string | undefined - * @example 94301 - */ - zip?: string; -}; \ No newline at end of file + /** + * @type string | undefined + * @example 437 Lytton + */ + street?: string + /** + * @type string | undefined + * @example Palo Alto + */ + city?: string + /** + * @type string | undefined + * @example CA + */ + state?: string + /** + * @type string | undefined + * @example 94301 + */ + zip?: string +} diff --git a/examples/react-query-v5/src/gen/models/ApiResponse.ts b/examples/react-query-v5/src/gen/models/ApiResponse.ts index c006d2618..499e9e9ca 100644 --- a/examples/react-query-v5/src/gen/models/ApiResponse.ts +++ b/examples/react-query-v5/src/gen/models/ApiResponse.ts @@ -1,14 +1,14 @@ export type ApiResponse = { - /** - * @type integer | undefined int32 - */ - code?: number; - /** - * @type string | undefined - */ - type?: string; - /** - * @type string | undefined - */ - message?: string; -}; \ No newline at end of file + /** + * @type integer | undefined int32 + */ + code?: number + /** + * @type string | undefined + */ + type?: string + /** + * @type string | undefined + */ + message?: string +} diff --git a/examples/react-query-v5/src/gen/models/Category.ts b/examples/react-query-v5/src/gen/models/Category.ts index ca358b57f..04c882cef 100644 --- a/examples/react-query-v5/src/gen/models/Category.ts +++ b/examples/react-query-v5/src/gen/models/Category.ts @@ -1,12 +1,12 @@ export type Category = { - /** - * @type integer | undefined int64 - * @example 1 - */ - id?: number; - /** - * @type string | undefined - * @example Dogs - */ - name?: string; -}; \ No newline at end of file + /** + * @type integer | undefined int64 + * @example 1 + */ + id?: number + /** + * @type string | undefined + * @example Dogs + */ + name?: string +} diff --git a/examples/react-query-v5/src/gen/models/CreateUser.ts b/examples/react-query-v5/src/gen/models/CreateUser.ts index ce5eb0af0..71911e3d5 100644 --- a/examples/react-query-v5/src/gen/models/CreateUser.ts +++ b/examples/react-query-v5/src/gen/models/CreateUser.ts @@ -1,17 +1,17 @@ -import type { User } from "./User"; +import type { User } from './User' - export type CreateUserMutationResponse = any; +export type CreateUserMutationResponse = any - /** +/** * @description successful operation -*/ -export type CreateUserError = User; + */ +export type CreateUserError = User - /** +/** * @description Created user object -*/ -export type CreateUserMutationRequest = User; + */ +export type CreateUserMutationRequest = User export type CreateUserMutation = { - Response: CreateUserMutationResponse; - Request: CreateUserMutationRequest; -}; \ No newline at end of file + Response: CreateUserMutationResponse + Request: CreateUserMutationRequest +} diff --git a/examples/react-query-v5/src/gen/models/CreateUsersWithListInput.ts b/examples/react-query-v5/src/gen/models/CreateUsersWithListInput.ts index 4e06178fc..5812f069a 100644 --- a/examples/react-query-v5/src/gen/models/CreateUsersWithListInput.ts +++ b/examples/react-query-v5/src/gen/models/CreateUsersWithListInput.ts @@ -1,22 +1,22 @@ -import type { User } from "./User"; +import type { User } from './User' - /** +/** * @description successful operation -*/ -export type CreateUsersWithListInputError = any; + */ +export type CreateUsersWithListInputError = any - /** +/** * @description Successful operation -*/ -export type CreateUsersWithListInput200 = User; + */ +export type CreateUsersWithListInput200 = User - export type CreateUsersWithListInputMutationRequest = User[]; +export type CreateUsersWithListInputMutationRequest = User[] - /** +/** * @description Successful operation -*/ -export type CreateUsersWithListInputMutationResponse = User; + */ +export type CreateUsersWithListInputMutationResponse = User export type CreateUsersWithListInputMutation = { - Response: CreateUsersWithListInputMutationResponse; - Request: CreateUsersWithListInputMutationRequest; -}; \ No newline at end of file + Response: CreateUsersWithListInputMutationResponse + Request: CreateUsersWithListInputMutationRequest +} diff --git a/examples/react-query-v5/src/gen/models/Customer.ts b/examples/react-query-v5/src/gen/models/Customer.ts index 8f1cadf58..39bbb4a6e 100644 --- a/examples/react-query-v5/src/gen/models/Customer.ts +++ b/examples/react-query-v5/src/gen/models/Customer.ts @@ -1,18 +1,18 @@ -import type { Address } from "./Address"; +import type { Address } from './Address' - export type Customer = { - /** - * @type integer | undefined int64 - * @example 100000 - */ - id?: number; - /** - * @type string | undefined - * @example fehguy - */ - username?: string; - /** - * @type array | undefined - */ - address?: Address[]; -}; \ No newline at end of file +export type Customer = { + /** + * @type integer | undefined int64 + * @example 100000 + */ + id?: number + /** + * @type string | undefined + * @example fehguy + */ + username?: string + /** + * @type array | undefined + */ + address?: Address[] +} diff --git a/examples/react-query-v5/src/gen/models/DeleteOrder.ts b/examples/react-query-v5/src/gen/models/DeleteOrder.ts index b2dbcc3b3..26edce6d7 100644 --- a/examples/react-query-v5/src/gen/models/DeleteOrder.ts +++ b/examples/react-query-v5/src/gen/models/DeleteOrder.ts @@ -1,24 +1,24 @@ /** * @description Invalid ID supplied -*/ -export type DeleteOrder400 = any; + */ +export type DeleteOrder400 = any - /** +/** * @description Order not found -*/ -export type DeleteOrder404 = any; + */ +export type DeleteOrder404 = any - export type DeleteOrderMutationResponse = any; +export type DeleteOrderMutationResponse = any - export type DeleteOrderPathParams = { - /** - * @description ID of the order that needs to be deleted - * @type integer int64 - */ - orderId: number; -}; +export type DeleteOrderPathParams = { + /** + * @description ID of the order that needs to be deleted + * @type integer int64 + */ + orderId: number +} export type DeleteOrderMutation = { - Response: DeleteOrderMutationResponse; - PathParams: DeleteOrderPathParams; - Errors: DeleteOrder400 | DeleteOrder404; -}; \ No newline at end of file + Response: DeleteOrderMutationResponse + PathParams: DeleteOrderPathParams + Errors: DeleteOrder400 | DeleteOrder404 +} diff --git a/examples/react-query-v5/src/gen/models/DeletePet.ts b/examples/react-query-v5/src/gen/models/DeletePet.ts index 5d8705d4e..67d54c120 100644 --- a/examples/react-query-v5/src/gen/models/DeletePet.ts +++ b/examples/react-query-v5/src/gen/models/DeletePet.ts @@ -1,27 +1,27 @@ /** * @description Invalid pet value -*/ -export type DeletePet400 = any; + */ +export type DeletePet400 = any - export type DeletePetHeaderParams = { - /** - * @type string | undefined - */ - api_key?: string; -} | undefined; +export type DeletePetHeaderParams = { + /** + * @type string | undefined + */ + api_key?: string +} | undefined - export type DeletePetMutationResponse = any; +export type DeletePetMutationResponse = any - export type DeletePetPathParams = { - /** - * @description Pet id to delete - * @type integer int64 - */ - petId: number; -}; +export type DeletePetPathParams = { + /** + * @description Pet id to delete + * @type integer int64 + */ + petId: number +} export type DeletePetMutation = { - Response: DeletePetMutationResponse; - PathParams: DeletePetPathParams; - HeaderParams: DeletePetHeaderParams; - Errors: DeletePet400; -}; \ No newline at end of file + Response: DeletePetMutationResponse + PathParams: DeletePetPathParams + HeaderParams: DeletePetHeaderParams + Errors: DeletePet400 +} diff --git a/examples/react-query-v5/src/gen/models/DeleteUser.ts b/examples/react-query-v5/src/gen/models/DeleteUser.ts index 5213a2d28..4616f1f9f 100644 --- a/examples/react-query-v5/src/gen/models/DeleteUser.ts +++ b/examples/react-query-v5/src/gen/models/DeleteUser.ts @@ -1,24 +1,24 @@ /** * @description Invalid username supplied -*/ -export type DeleteUser400 = any; + */ +export type DeleteUser400 = any - /** +/** * @description User not found -*/ -export type DeleteUser404 = any; + */ +export type DeleteUser404 = any - export type DeleteUserMutationResponse = any; +export type DeleteUserMutationResponse = any - export type DeleteUserPathParams = { - /** - * @description The name that needs to be deleted - * @type string - */ - username: string; -}; +export type DeleteUserPathParams = { + /** + * @description The name that needs to be deleted + * @type string + */ + username: string +} export type DeleteUserMutation = { - Response: DeleteUserMutationResponse; - PathParams: DeleteUserPathParams; - Errors: DeleteUser400 | DeleteUser404; -}; \ No newline at end of file + Response: DeleteUserMutationResponse + PathParams: DeleteUserPathParams + Errors: DeleteUser400 | DeleteUser404 +} diff --git a/examples/react-query-v5/src/gen/models/FindPetsByStatus.ts b/examples/react-query-v5/src/gen/models/FindPetsByStatus.ts index 1db0f121e..e9cfeb018 100644 --- a/examples/react-query-v5/src/gen/models/FindPetsByStatus.ts +++ b/examples/react-query-v5/src/gen/models/FindPetsByStatus.ts @@ -1,36 +1,36 @@ -import type { Pet } from "./Pet"; +import type { Pet } from './Pet' - /** +/** * @description Invalid status value -*/ -export type FindPetsByStatus400 = any; + */ +export type FindPetsByStatus400 = any - export const findPetsByStatusQueryParamsStatus = { - "available": "available", - "pending": "pending", - "sold": "sold" -} as const; -export type FindPetsByStatusQueryParamsStatus = (typeof findPetsByStatusQueryParamsStatus)[keyof typeof findPetsByStatusQueryParamsStatus]; +export const findPetsByStatusQueryParamsStatus = { + 'available': 'available', + 'pending': 'pending', + 'sold': 'sold', +} as const +export type FindPetsByStatusQueryParamsStatus = (typeof findPetsByStatusQueryParamsStatus)[keyof typeof findPetsByStatusQueryParamsStatus] export type FindPetsByStatusQueryParams = { - /** - * @description Status values that need to be considered for filter - * @type string | undefined - * @default 'available' - */ - status?: FindPetsByStatusQueryParamsStatus; -} | undefined; + /** + * @description Status values that need to be considered for filter + * @type string | undefined + * @default 'available' + */ + status?: FindPetsByStatusQueryParamsStatus +} | undefined - /** +/** * @description successful operation -*/ -export type FindPetsByStatus200 = Pet[]; + */ +export type FindPetsByStatus200 = Pet[] - /** +/** * @description successful operation -*/ -export type FindPetsByStatusQueryResponse = Pet[]; + */ +export type FindPetsByStatusQueryResponse = Pet[] export type FindPetsByStatusQuery = { - Response: FindPetsByStatusQueryResponse; - QueryParams: FindPetsByStatusQueryParams; - Errors: FindPetsByStatus400; -}; \ No newline at end of file + Response: FindPetsByStatusQueryResponse + QueryParams: FindPetsByStatusQueryParams + Errors: FindPetsByStatus400 +} diff --git a/examples/react-query-v5/src/gen/models/FindPetsByTags.ts b/examples/react-query-v5/src/gen/models/FindPetsByTags.ts index d9380e150..48f940004 100644 --- a/examples/react-query-v5/src/gen/models/FindPetsByTags.ts +++ b/examples/react-query-v5/src/gen/models/FindPetsByTags.ts @@ -1,39 +1,39 @@ -import type { Pet } from "./Pet"; +import type { Pet } from './Pet' - /** +/** * @description Invalid tag value -*/ -export type FindPetsByTags400 = any; + */ +export type FindPetsByTags400 = any - export type FindPetsByTagsQueryParams = { - /** - * @description Tags to filter by - * @type array | undefined - */ - tags?: string[]; - /** - * @description to request with required page number or pagination - * @type string | undefined - */ - page?: string; - /** - * @description to request with required page size - * @type string | undefined - */ - pageSize?: string; -} | undefined; +export type FindPetsByTagsQueryParams = { + /** + * @description Tags to filter by + * @type array | undefined + */ + tags?: string[] + /** + * @description to request with required page number or pagination + * @type string | undefined + */ + page?: string + /** + * @description to request with required page size + * @type string | undefined + */ + pageSize?: string +} | undefined - /** +/** * @description successful operation -*/ -export type FindPetsByTags200 = Pet[]; + */ +export type FindPetsByTags200 = Pet[] - /** +/** * @description successful operation -*/ -export type FindPetsByTagsQueryResponse = Pet[]; + */ +export type FindPetsByTagsQueryResponse = Pet[] export type FindPetsByTagsQuery = { - Response: FindPetsByTagsQueryResponse; - QueryParams: FindPetsByTagsQueryParams; - Errors: FindPetsByTags400; -}; \ No newline at end of file + Response: FindPetsByTagsQueryResponse + QueryParams: FindPetsByTagsQueryParams + Errors: FindPetsByTags400 +} diff --git a/examples/react-query-v5/src/gen/models/GetInventory.ts b/examples/react-query-v5/src/gen/models/GetInventory.ts index 447e82d32..727a142c9 100644 --- a/examples/react-query-v5/src/gen/models/GetInventory.ts +++ b/examples/react-query-v5/src/gen/models/GetInventory.ts @@ -1,16 +1,16 @@ /** * @description successful operation -*/ + */ export type GetInventory200 = { - [key: string]: number; -}; + [key: string]: number +} - /** +/** * @description successful operation -*/ + */ export type GetInventoryQueryResponse = { - [key: string]: number; -}; + [key: string]: number +} export type GetInventoryQuery = { - Response: GetInventoryQueryResponse; -}; \ No newline at end of file + Response: GetInventoryQueryResponse +} diff --git a/examples/react-query-v5/src/gen/models/GetOrderById.ts b/examples/react-query-v5/src/gen/models/GetOrderById.ts index 6f142b258..4f6a2747c 100644 --- a/examples/react-query-v5/src/gen/models/GetOrderById.ts +++ b/examples/react-query-v5/src/gen/models/GetOrderById.ts @@ -1,34 +1,34 @@ -import type { Order } from "./Order"; +import type { Order } from './Order' - /** +/** * @description Invalid ID supplied -*/ -export type GetOrderById400 = any; + */ +export type GetOrderById400 = any - /** +/** * @description Order not found -*/ -export type GetOrderById404 = any; + */ +export type GetOrderById404 = any - export type GetOrderByIdPathParams = { - /** - * @description ID of order that needs to be fetched - * @type integer int64 - */ - orderId: number; -}; +export type GetOrderByIdPathParams = { + /** + * @description ID of order that needs to be fetched + * @type integer int64 + */ + orderId: number +} - /** +/** * @description successful operation -*/ -export type GetOrderById200 = Order; + */ +export type GetOrderById200 = Order - /** +/** * @description successful operation -*/ -export type GetOrderByIdQueryResponse = Order; + */ +export type GetOrderByIdQueryResponse = Order export type GetOrderByIdQuery = { - Response: GetOrderByIdQueryResponse; - PathParams: GetOrderByIdPathParams; - Errors: GetOrderById400 | GetOrderById404; -}; \ No newline at end of file + Response: GetOrderByIdQueryResponse + PathParams: GetOrderByIdPathParams + Errors: GetOrderById400 | GetOrderById404 +} diff --git a/examples/react-query-v5/src/gen/models/GetPetById.ts b/examples/react-query-v5/src/gen/models/GetPetById.ts index 992564aac..f2257b91f 100644 --- a/examples/react-query-v5/src/gen/models/GetPetById.ts +++ b/examples/react-query-v5/src/gen/models/GetPetById.ts @@ -1,34 +1,34 @@ -import type { Pet } from "./Pet"; +import type { Pet } from './Pet' - /** +/** * @description Invalid ID supplied -*/ -export type GetPetById400 = any; + */ +export type GetPetById400 = any - /** +/** * @description Pet not found -*/ -export type GetPetById404 = any; + */ +export type GetPetById404 = any - export type GetPetByIdPathParams = { - /** - * @description ID of pet to return - * @type integer int64 - */ - petId: number; -}; +export type GetPetByIdPathParams = { + /** + * @description ID of pet to return + * @type integer int64 + */ + petId: number +} - /** +/** * @description successful operation -*/ -export type GetPetById200 = Pet; + */ +export type GetPetById200 = Pet - /** +/** * @description successful operation -*/ -export type GetPetByIdQueryResponse = Pet; + */ +export type GetPetByIdQueryResponse = Pet export type GetPetByIdQuery = { - Response: GetPetByIdQueryResponse; - PathParams: GetPetByIdPathParams; - Errors: GetPetById400 | GetPetById404; -}; \ No newline at end of file + Response: GetPetByIdQueryResponse + PathParams: GetPetByIdPathParams + Errors: GetPetById400 | GetPetById404 +} diff --git a/examples/react-query-v5/src/gen/models/GetUserByName.ts b/examples/react-query-v5/src/gen/models/GetUserByName.ts index b355f6c60..cc795365a 100644 --- a/examples/react-query-v5/src/gen/models/GetUserByName.ts +++ b/examples/react-query-v5/src/gen/models/GetUserByName.ts @@ -1,34 +1,34 @@ -import type { User } from "./User"; +import type { User } from './User' - /** +/** * @description Invalid username supplied -*/ -export type GetUserByName400 = any; + */ +export type GetUserByName400 = any - /** +/** * @description User not found -*/ -export type GetUserByName404 = any; + */ +export type GetUserByName404 = any - export type GetUserByNamePathParams = { - /** - * @description The name that needs to be fetched. Use user1 for testing. - * @type string - */ - username: string; -}; +export type GetUserByNamePathParams = { + /** + * @description The name that needs to be fetched. Use user1 for testing. + * @type string + */ + username: string +} - /** +/** * @description successful operation -*/ -export type GetUserByName200 = User; + */ +export type GetUserByName200 = User - /** +/** * @description successful operation -*/ -export type GetUserByNameQueryResponse = User; + */ +export type GetUserByNameQueryResponse = User export type GetUserByNameQuery = { - Response: GetUserByNameQueryResponse; - PathParams: GetUserByNamePathParams; - Errors: GetUserByName400 | GetUserByName404; -}; \ No newline at end of file + Response: GetUserByNameQueryResponse + PathParams: GetUserByNamePathParams + Errors: GetUserByName400 | GetUserByName404 +} diff --git a/examples/react-query-v5/src/gen/models/LoginUser.ts b/examples/react-query-v5/src/gen/models/LoginUser.ts index 352847fc3..119afdb34 100644 --- a/examples/react-query-v5/src/gen/models/LoginUser.ts +++ b/examples/react-query-v5/src/gen/models/LoginUser.ts @@ -1,32 +1,32 @@ /** * @description successful operation -*/ -export type LoginUser200 = string; + */ +export type LoginUser200 = string - /** +/** * @description Invalid username/password supplied -*/ -export type LoginUser400 = any; + */ +export type LoginUser400 = any - export type LoginUserQueryParams = { - /** - * @description The user name for login - * @type string | undefined - */ - username?: string; - /** - * @description The password for login in clear text - * @type string | undefined - */ - password?: string; -} | undefined; +export type LoginUserQueryParams = { + /** + * @description The user name for login + * @type string | undefined + */ + username?: string + /** + * @description The password for login in clear text + * @type string | undefined + */ + password?: string +} | undefined - /** +/** * @description successful operation -*/ -export type LoginUserQueryResponse = string; + */ +export type LoginUserQueryResponse = string export type LoginUserQuery = { - Response: LoginUserQueryResponse; - QueryParams: LoginUserQueryParams; - Errors: LoginUser400; -}; \ No newline at end of file + Response: LoginUserQueryResponse + QueryParams: LoginUserQueryParams + Errors: LoginUser400 +} diff --git a/examples/react-query-v5/src/gen/models/LogoutUser.ts b/examples/react-query-v5/src/gen/models/LogoutUser.ts index d949ed815..72c41681a 100644 --- a/examples/react-query-v5/src/gen/models/LogoutUser.ts +++ b/examples/react-query-v5/src/gen/models/LogoutUser.ts @@ -1,9 +1,9 @@ /** * @description successful operation -*/ -export type LogoutUserError = any; + */ +export type LogoutUserError = any - export type LogoutUserQueryResponse = any; +export type LogoutUserQueryResponse = any export type LogoutUserQuery = { - Response: LogoutUserQueryResponse; -}; \ No newline at end of file + Response: LogoutUserQueryResponse +} diff --git a/examples/react-query-v5/src/gen/models/Order.ts b/examples/react-query-v5/src/gen/models/Order.ts index 66e7e3eba..820fff2c2 100644 --- a/examples/react-query-v5/src/gen/models/Order.ts +++ b/examples/react-query-v5/src/gen/models/Order.ts @@ -1,49 +1,49 @@ export const orderStatus = { - "placed": "placed", - "approved": "approved", - "delivered": "delivered" -} as const; -export type OrderStatus = (typeof orderStatus)[keyof typeof orderStatus]; + 'placed': 'placed', + 'approved': 'approved', + 'delivered': 'delivered', +} as const +export type OrderStatus = (typeof orderStatus)[keyof typeof orderStatus] export const orderHttpStatus = { - "200": 200, - "400": 400, - "500": 500 -} as const; -export type OrderHttpStatus = (typeof orderHttpStatus)[keyof typeof orderHttpStatus]; + '200': 200, + '400': 400, + '500': 500, +} as const +export type OrderHttpStatus = (typeof orderHttpStatus)[keyof typeof orderHttpStatus] export type Order = { - /** - * @type integer | undefined int64 - * @example 10 - */ - id?: number; - /** - * @type integer | undefined int64 - * @example 198772 - */ - petId?: number; - /** - * @type integer | undefined int32 - * @example 7 - */ - quantity?: number; - /** - * @type string | undefined date-time - */ - shipDate?: string; - /** - * @description Order Status - * @type string | undefined - * @example approved - */ - status?: OrderStatus; - /** - * @description HTTP Status - * @type number | undefined - * @example 200 - */ - http_status?: OrderHttpStatus; - /** - * @type boolean | undefined - */ - complete?: boolean; -}; \ No newline at end of file + /** + * @type integer | undefined int64 + * @example 10 + */ + id?: number + /** + * @type integer | undefined int64 + * @example 198772 + */ + petId?: number + /** + * @type integer | undefined int32 + * @example 7 + */ + quantity?: number + /** + * @type string | undefined date-time + */ + shipDate?: string + /** + * @description Order Status + * @type string | undefined + * @example approved + */ + status?: OrderStatus + /** + * @description HTTP Status + * @type number | undefined + * @example 200 + */ + http_status?: OrderHttpStatus + /** + * @type boolean | undefined + */ + complete?: boolean +} diff --git a/examples/react-query-v5/src/gen/models/Pet.ts b/examples/react-query-v5/src/gen/models/Pet.ts index ff366de62..2655333aa 100644 --- a/examples/react-query-v5/src/gen/models/Pet.ts +++ b/examples/react-query-v5/src/gen/models/Pet.ts @@ -1,35 +1,35 @@ -import type { Category } from "./Category"; -import type { Tag } from "./Tag"; +import type { Category } from './Category' +import type { Tag } from './Tag' - export const petStatus = { - "available": "available", - "pending": "pending", - "sold": "sold" -} as const; -export type PetStatus = (typeof petStatus)[keyof typeof petStatus]; +export const petStatus = { + 'available': 'available', + 'pending': 'pending', + 'sold': 'sold', +} as const +export type PetStatus = (typeof petStatus)[keyof typeof petStatus] export type Pet = { - /** - * @type integer | undefined int64 - * @example 10 - */ - id?: number; - /** - * @type string - * @example doggie - */ - name: string; - category?: Category; - /** - * @type array - */ - photoUrls: string[]; - /** - * @type array | undefined - */ - tags?: Tag[]; - /** - * @description pet status in the store - * @type string | undefined - */ - status?: PetStatus; -}; \ No newline at end of file + /** + * @type integer | undefined int64 + * @example 10 + */ + id?: number + /** + * @type string + * @example doggie + */ + name: string + category?: Category + /** + * @type array + */ + photoUrls: string[] + /** + * @type array | undefined + */ + tags?: Tag[] + /** + * @description pet status in the store + * @type string | undefined + */ + status?: PetStatus +} diff --git a/examples/react-query-v5/src/gen/models/PetNotFound.ts b/examples/react-query-v5/src/gen/models/PetNotFound.ts index 47159c4a4..676a15893 100644 --- a/examples/react-query-v5/src/gen/models/PetNotFound.ts +++ b/examples/react-query-v5/src/gen/models/PetNotFound.ts @@ -1,10 +1,10 @@ export type PetNotFound = { - /** - * @type integer | undefined int32 - */ - code?: number; - /** - * @type string | undefined - */ - message?: string; -}; \ No newline at end of file + /** + * @type integer | undefined int32 + */ + code?: number + /** + * @type string | undefined + */ + message?: string +} diff --git a/examples/react-query-v5/src/gen/models/PlaceOrder.ts b/examples/react-query-v5/src/gen/models/PlaceOrder.ts index 14fbc8144..1f75e0fda 100644 --- a/examples/react-query-v5/src/gen/models/PlaceOrder.ts +++ b/examples/react-query-v5/src/gen/models/PlaceOrder.ts @@ -1,23 +1,23 @@ -import type { Order } from "./Order"; +import type { Order } from './Order' - /** +/** * @description Invalid input -*/ -export type PlaceOrder405 = any; + */ +export type PlaceOrder405 = any - /** +/** * @description successful operation -*/ -export type PlaceOrder200 = Order; + */ +export type PlaceOrder200 = Order - export type PlaceOrderMutationRequest = Order; +export type PlaceOrderMutationRequest = Order - /** +/** * @description successful operation -*/ -export type PlaceOrderMutationResponse = Order; + */ +export type PlaceOrderMutationResponse = Order export type PlaceOrderMutation = { - Response: PlaceOrderMutationResponse; - Request: PlaceOrderMutationRequest; - Errors: PlaceOrder405; -}; \ No newline at end of file + Response: PlaceOrderMutationResponse + Request: PlaceOrderMutationRequest + Errors: PlaceOrder405 +} diff --git a/examples/react-query-v5/src/gen/models/PlaceOrderPatch.ts b/examples/react-query-v5/src/gen/models/PlaceOrderPatch.ts index 1993b5591..c0080bc12 100644 --- a/examples/react-query-v5/src/gen/models/PlaceOrderPatch.ts +++ b/examples/react-query-v5/src/gen/models/PlaceOrderPatch.ts @@ -1,23 +1,23 @@ -import type { Order } from "./Order"; +import type { Order } from './Order' - /** +/** * @description Invalid input -*/ -export type PlaceOrderPatch405 = any; + */ +export type PlaceOrderPatch405 = any - /** +/** * @description successful operation -*/ -export type PlaceOrderPatch200 = Order; + */ +export type PlaceOrderPatch200 = Order - export type PlaceOrderPatchMutationRequest = Order; +export type PlaceOrderPatchMutationRequest = Order - /** +/** * @description successful operation -*/ -export type PlaceOrderPatchMutationResponse = Order; + */ +export type PlaceOrderPatchMutationResponse = Order export type PlaceOrderPatchMutation = { - Response: PlaceOrderPatchMutationResponse; - Request: PlaceOrderPatchMutationRequest; - Errors: PlaceOrderPatch405; -}; \ No newline at end of file + Response: PlaceOrderPatchMutationResponse + Request: PlaceOrderPatchMutationRequest + Errors: PlaceOrderPatch405 +} diff --git a/examples/react-query-v5/src/gen/models/Tag.ts b/examples/react-query-v5/src/gen/models/Tag.ts index 49a0b6cbf..5145ac12c 100644 --- a/examples/react-query-v5/src/gen/models/Tag.ts +++ b/examples/react-query-v5/src/gen/models/Tag.ts @@ -1,10 +1,10 @@ export type Tag = { - /** - * @type integer | undefined int64 - */ - id?: number; - /** - * @type string | undefined - */ - name?: string; -}; \ No newline at end of file + /** + * @type integer | undefined int64 + */ + id?: number + /** + * @type string | undefined + */ + name?: string +} diff --git a/examples/react-query-v5/src/gen/models/UpdatePet.ts b/examples/react-query-v5/src/gen/models/UpdatePet.ts index 351c8927d..3ea48359a 100644 --- a/examples/react-query-v5/src/gen/models/UpdatePet.ts +++ b/examples/react-query-v5/src/gen/models/UpdatePet.ts @@ -1,36 +1,36 @@ -import type { Pet } from "./Pet"; +import type { Pet } from './Pet' - /** +/** * @description Invalid ID supplied -*/ -export type UpdatePet400 = any; + */ +export type UpdatePet400 = any - /** +/** * @description Pet not found -*/ -export type UpdatePet404 = any; + */ +export type UpdatePet404 = any - /** +/** * @description Validation exception -*/ -export type UpdatePet405 = any; + */ +export type UpdatePet405 = any - /** +/** * @description Successful operation -*/ -export type UpdatePet200 = Pet; + */ +export type UpdatePet200 = Pet - /** +/** * @description Update an existent pet in the store -*/ -export type UpdatePetMutationRequest = Pet; + */ +export type UpdatePetMutationRequest = Pet - /** +/** * @description Successful operation -*/ -export type UpdatePetMutationResponse = Pet; + */ +export type UpdatePetMutationResponse = Pet export type UpdatePetMutation = { - Response: UpdatePetMutationResponse; - Request: UpdatePetMutationRequest; - Errors: UpdatePet400 | UpdatePet404 | UpdatePet405; -}; \ No newline at end of file + Response: UpdatePetMutationResponse + Request: UpdatePetMutationRequest + Errors: UpdatePet400 | UpdatePet404 | UpdatePet405 +} diff --git a/examples/react-query-v5/src/gen/models/UpdatePetWithForm.ts b/examples/react-query-v5/src/gen/models/UpdatePetWithForm.ts index 1ddb71dcd..8cbd16af3 100644 --- a/examples/react-query-v5/src/gen/models/UpdatePetWithForm.ts +++ b/examples/react-query-v5/src/gen/models/UpdatePetWithForm.ts @@ -1,33 +1,33 @@ /** * @description Invalid input -*/ -export type UpdatePetWithForm405 = any; + */ +export type UpdatePetWithForm405 = any - export type UpdatePetWithFormMutationResponse = any; +export type UpdatePetWithFormMutationResponse = any - export type UpdatePetWithFormPathParams = { - /** - * @description ID of pet that needs to be updated - * @type integer int64 - */ - petId: number; -}; +export type UpdatePetWithFormPathParams = { + /** + * @description ID of pet that needs to be updated + * @type integer int64 + */ + petId: number +} - export type UpdatePetWithFormQueryParams = { - /** - * @description Name of pet that needs to be updated - * @type string | undefined - */ - name?: string; - /** - * @description Status of pet that needs to be updated - * @type string | undefined - */ - status?: string; -} | undefined; +export type UpdatePetWithFormQueryParams = { + /** + * @description Name of pet that needs to be updated + * @type string | undefined + */ + name?: string + /** + * @description Status of pet that needs to be updated + * @type string | undefined + */ + status?: string +} | undefined export type UpdatePetWithFormMutation = { - Response: UpdatePetWithFormMutationResponse; - PathParams: UpdatePetWithFormPathParams; - QueryParams: UpdatePetWithFormQueryParams; - Errors: UpdatePetWithForm405; -}; \ No newline at end of file + Response: UpdatePetWithFormMutationResponse + PathParams: UpdatePetWithFormPathParams + QueryParams: UpdatePetWithFormQueryParams + Errors: UpdatePetWithForm405 +} diff --git a/examples/react-query-v5/src/gen/models/UpdateUser.ts b/examples/react-query-v5/src/gen/models/UpdateUser.ts index aa2eafc38..c0c8384f5 100644 --- a/examples/react-query-v5/src/gen/models/UpdateUser.ts +++ b/examples/react-query-v5/src/gen/models/UpdateUser.ts @@ -1,26 +1,26 @@ -import type { User } from "./User"; +import type { User } from './User' - /** +/** * @description successful operation -*/ -export type UpdateUserError = any; + */ +export type UpdateUserError = any - export type UpdateUserMutationResponse = any; +export type UpdateUserMutationResponse = any - export type UpdateUserPathParams = { - /** - * @description name that need to be deleted - * @type string - */ - username: string; -}; +export type UpdateUserPathParams = { + /** + * @description name that need to be deleted + * @type string + */ + username: string +} - /** +/** * @description Update an existent user in the store -*/ -export type UpdateUserMutationRequest = User; + */ +export type UpdateUserMutationRequest = User export type UpdateUserMutation = { - Response: UpdateUserMutationResponse; - Request: UpdateUserMutationRequest; - PathParams: UpdateUserPathParams; -}; \ No newline at end of file + Response: UpdateUserMutationResponse + Request: UpdateUserMutationRequest + PathParams: UpdateUserPathParams +} diff --git a/examples/react-query-v5/src/gen/models/UploadFile.ts b/examples/react-query-v5/src/gen/models/UploadFile.ts index 00c607a40..2819055f0 100644 --- a/examples/react-query-v5/src/gen/models/UploadFile.ts +++ b/examples/react-query-v5/src/gen/models/UploadFile.ts @@ -1,35 +1,35 @@ -import type { ApiResponse } from "./ApiResponse"; +import type { ApiResponse } from './ApiResponse' - export type UploadFileMutationRequest = string; +export type UploadFileMutationRequest = string - export type UploadFilePathParams = { - /** - * @description ID of pet to update - * @type integer int64 - */ - petId: number; -}; +export type UploadFilePathParams = { + /** + * @description ID of pet to update + * @type integer int64 + */ + petId: number +} - export type UploadFileQueryParams = { - /** - * @description Additional Metadata - * @type string | undefined - */ - additionalMetadata?: string; -} | undefined; +export type UploadFileQueryParams = { + /** + * @description Additional Metadata + * @type string | undefined + */ + additionalMetadata?: string +} | undefined - /** +/** * @description successful operation -*/ -export type UploadFile200 = ApiResponse; + */ +export type UploadFile200 = ApiResponse - /** +/** * @description successful operation -*/ -export type UploadFileMutationResponse = ApiResponse; + */ +export type UploadFileMutationResponse = ApiResponse export type UploadFileMutation = { - Response: UploadFileMutationResponse; - Request: UploadFileMutationRequest; - PathParams: UploadFilePathParams; - QueryParams: UploadFileQueryParams; -}; \ No newline at end of file + Response: UploadFileMutationResponse + Request: UploadFileMutationRequest + PathParams: UploadFilePathParams + QueryParams: UploadFileQueryParams +} diff --git a/examples/react-query-v5/src/gen/models/User.ts b/examples/react-query-v5/src/gen/models/User.ts index 366efa29b..7db228615 100644 --- a/examples/react-query-v5/src/gen/models/User.ts +++ b/examples/react-query-v5/src/gen/models/User.ts @@ -1,43 +1,43 @@ export type User = { - /** - * @type integer | undefined int64 - * @example 10 - */ - id?: number; - /** - * @type string | undefined - * @example theUser - */ - username?: string; - /** - * @type string | undefined - * @example John - */ - firstName?: string; - /** - * @type string | undefined - * @example James - */ - lastName?: string; - /** - * @type string | undefined - * @example john@email.com - */ - email?: string; - /** - * @type string | undefined - * @example 12345 - */ - password?: string; - /** - * @type string | undefined - * @example 12345 - */ - phone?: string; - /** - * @description User Status - * @type integer | undefined int32 - * @example 1 - */ - userStatus?: number; -}; \ No newline at end of file + /** + * @type integer | undefined int64 + * @example 10 + */ + id?: number + /** + * @type string | undefined + * @example theUser + */ + username?: string + /** + * @type string | undefined + * @example John + */ + firstName?: string + /** + * @type string | undefined + * @example James + */ + lastName?: string + /** + * @type string | undefined + * @example john@email.com + */ + email?: string + /** + * @type string | undefined + * @example 12345 + */ + password?: string + /** + * @type string | undefined + * @example 12345 + */ + phone?: string + /** + * @description User Status + * @type integer | undefined int32 + * @example 1 + */ + userStatus?: number +} diff --git a/examples/react-query-v5/src/gen/models/UserArray.ts b/examples/react-query-v5/src/gen/models/UserArray.ts index d17573215..effb23af2 100644 --- a/examples/react-query-v5/src/gen/models/UserArray.ts +++ b/examples/react-query-v5/src/gen/models/UserArray.ts @@ -1,3 +1,3 @@ -import type { User } from "./User"; +import type { User } from './User' - export type UserArray = User[]; \ No newline at end of file +export type UserArray = User[] diff --git a/examples/react-query-v5/src/gen/models/index.ts b/examples/react-query-v5/src/gen/models/index.ts index 6f9cc329b..dbeb82e28 100644 --- a/examples/react-query-v5/src/gen/models/index.ts +++ b/examples/react-query-v5/src/gen/models/index.ts @@ -1,31 +1,31 @@ -export * from "./AddPet"; -export * from "./AddPetRequest"; -export * from "./Address"; -export * from "./ApiResponse"; -export * from "./Category"; -export * from "./CreateUser"; -export * from "./CreateUsersWithListInput"; -export * from "./Customer"; -export * from "./DeleteOrder"; -export * from "./DeletePet"; -export * from "./DeleteUser"; -export * from "./FindPetsByStatus"; -export * from "./FindPetsByTags"; -export * from "./GetInventory"; -export * from "./GetOrderById"; -export * from "./GetPetById"; -export * from "./GetUserByName"; -export * from "./LoginUser"; -export * from "./LogoutUser"; -export * from "./Order"; -export * from "./Pet"; -export * from "./PetNotFound"; -export * from "./PlaceOrder"; -export * from "./PlaceOrderPatch"; -export * from "./Tag"; -export * from "./UpdatePet"; -export * from "./UpdatePetWithForm"; -export * from "./UpdateUser"; -export * from "./UploadFile"; -export * from "./User"; -export * from "./UserArray"; \ No newline at end of file +export * from './AddPet' +export * from './AddPetRequest' +export * from './Address' +export * from './ApiResponse' +export * from './Category' +export * from './CreateUser' +export * from './CreateUsersWithListInput' +export * from './Customer' +export * from './DeleteOrder' +export * from './DeletePet' +export * from './DeleteUser' +export * from './FindPetsByStatus' +export * from './FindPetsByTags' +export * from './GetInventory' +export * from './GetOrderById' +export * from './GetPetById' +export * from './GetUserByName' +export * from './LoginUser' +export * from './LogoutUser' +export * from './Order' +export * from './Pet' +export * from './PetNotFound' +export * from './PlaceOrder' +export * from './PlaceOrderPatch' +export * from './Tag' +export * from './UpdatePet' +export * from './UpdatePetWithForm' +export * from './UpdateUser' +export * from './UploadFile' +export * from './User' +export * from './UserArray' diff --git a/packages/swagger-ts/src/TypeGenerator.test.ts b/packages/swagger-ts/src/TypeGenerator.test.ts index 96a27bf35..eee44a93a 100644 --- a/packages/swagger-ts/src/TypeGenerator.test.ts +++ b/packages/swagger-ts/src/TypeGenerator.test.ts @@ -18,6 +18,7 @@ describe('TypeGenerator petStore', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: 'enum', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -42,6 +43,7 @@ describe('TypeGenerator petStore', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'undefined', transformers: {}, @@ -66,6 +68,7 @@ describe('TypeGenerator petStore', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionTokenAndUndefined', transformers: {}, @@ -90,6 +93,7 @@ describe('TypeGenerator petStore', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -119,6 +123,7 @@ describe('TypeGenerator petStore', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -147,6 +152,7 @@ describe('TypeGenerator petStoreRef', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -175,6 +181,7 @@ describe('TypeGenerator discriminator', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -198,6 +205,7 @@ describe('TypeGenerator discriminator', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -220,6 +228,7 @@ describe('TypeGenerator discriminator', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -242,6 +251,7 @@ describe('TypeGenerator discriminator', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -263,6 +273,7 @@ describe('TypeGenerator discriminator', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -285,6 +296,7 @@ describe('TypeGenerator discriminator', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -307,6 +319,7 @@ describe('TypeGenerator discriminator', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -333,6 +346,7 @@ describe('TypeGenerator enums', async () => { const defaultGenerator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -369,6 +383,7 @@ describe('TypeGenerator enums', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'enum', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -392,6 +407,7 @@ describe('TypeGenerator enums', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'asPascalConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -415,6 +431,7 @@ describe('TypeGenerator enums', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'constEnum', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, @@ -438,6 +455,7 @@ describe('TypeGenerator enums', async () => { const generator = new TypeGenerator({ usedEnumNames: {}, enumType: 'literal', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', transformers: {}, diff --git a/packages/swagger-ts/src/TypeGenerator.ts b/packages/swagger-ts/src/TypeGenerator.ts index 3f75d631f..5589347c3 100644 --- a/packages/swagger-ts/src/TypeGenerator.ts +++ b/packages/swagger-ts/src/TypeGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from '@kubb/core' -import transformers from '@kubb/core/transformers' +import transformers, { pascalCase } from '@kubb/core/transformers' import { getUniqueName } from '@kubb/core/utils' import * as factory from '@kubb/parser/factory' import { keywordTypeNodes } from '@kubb/parser/factory' @@ -283,7 +283,7 @@ export class TypeGenerator extends Generator [key, key]) diff --git a/packages/swagger-ts/src/plugin.ts b/packages/swagger-ts/src/plugin.ts index 3a0372dfd..dace6ed30 100644 --- a/packages/swagger-ts/src/plugin.ts +++ b/packages/swagger-ts/src/plugin.ts @@ -23,6 +23,7 @@ export const definePlugin = createPlugin((options) => { include, override = [], enumType = 'asConst', + enumSuffix = '', dateType = 'string', unknownType = 'any', optionalType = 'questionToken', @@ -37,6 +38,7 @@ export const definePlugin = createPlugin((options) => { transformers, dateType, enumType, + enumSuffix, optionalType, oasType, // keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey) diff --git a/packages/swagger-ts/src/types.ts b/packages/swagger-ts/src/types.ts index c78965fec..daddf1e77 100644 --- a/packages/swagger-ts/src/types.ts +++ b/packages/swagger-ts/src/types.ts @@ -57,6 +57,13 @@ export type Options = { * @default 'asConst' */ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' + /** + * Set a suffix for the generated enums. + * @default '' + * Default will be `'enum'` in version 3 of Kubb + */ + enumSuffix?: string + /** * Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`. * @default 'string' @@ -89,6 +96,7 @@ export type Options = { type ResolvedOptions = { enumType: NonNullable + enumSuffix: NonNullable dateType: NonNullable unknownType: NonNullable optionalType: NonNullable From 7a1b951bfcc8cfb47c1f771804960be134a1b3b6 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Sat, 9 Mar 2024 16:38:10 +0100 Subject: [PATCH 2/2] chore: fix ts --- .../advanced/src/gen/clients/axios/index.ts | 2 +- .../advanced/src/gen/clients/hooks/index.ts | 2 +- examples/advanced/src/gen/index.ts | 6 ++-- examples/advanced/src/gen/models/ts/index.ts | 6 ++-- examples/advanced/src/gen/msw/index.ts | 2 +- examples/advanced/src/gen/zod/index.ts | 6 ++-- .../faker/src/gen/customMocks/createUser.ts | 2 +- examples/faker/src/gen/index.ts | 2 +- .../src/OperationGenerator.test.tsx | 4 +++ packages/swagger-ts/src/TypeGenerator.ts | 32 +++++++++---------- packages/swagger/src/oas/index.ts | 4 +++ 11 files changed, 38 insertions(+), 30 deletions(-) diff --git a/examples/advanced/src/gen/clients/axios/index.ts b/examples/advanced/src/gen/clients/axios/index.ts index 1a19f613d..0b1ae337b 100644 --- a/examples/advanced/src/gen/clients/axios/index.ts +++ b/examples/advanced/src/gen/clients/axios/index.ts @@ -1,4 +1,4 @@ export * from './operations' -export * as petsService from './petsService/index' export * as petService from './petService/index' +export * as petsService from './petsService/index' export * as userService from './userService/index' diff --git a/examples/advanced/src/gen/clients/hooks/index.ts b/examples/advanced/src/gen/clients/hooks/index.ts index f810e25ca..06f51f5d9 100644 --- a/examples/advanced/src/gen/clients/hooks/index.ts +++ b/examples/advanced/src/gen/clients/hooks/index.ts @@ -1,3 +1,3 @@ -export * as petsHooks from './petsController/index' export * as petHooks from './petController/index' +export * as petsHooks from './petsController/index' export * as userHooks from './userController/index' diff --git a/examples/advanced/src/gen/index.ts b/examples/advanced/src/gen/index.ts index 7a102c087..4cf3b8513 100644 --- a/examples/advanced/src/gen/index.ts +++ b/examples/advanced/src/gen/index.ts @@ -1,7 +1,7 @@ -export * from './models/ts/index.js' +export * as clients from './clients/axios/index' export * as hooks from './clients/hooks/index' export * as swrHooks from './clients/swr/index' -export * as clients from './clients/axios/index' -export * as zod from './zod/index' export * as faker from './mocks/index' +export * from './models/ts/index.js' export * as msw from './msw/index' +export * as zod from './zod/index' diff --git a/examples/advanced/src/gen/models/ts/index.ts b/examples/advanced/src/gen/models/ts/index.ts index bc8cf77ae..1251cd573 100644 --- a/examples/advanced/src/gen/models/ts/index.ts +++ b/examples/advanced/src/gen/models/ts/index.ts @@ -5,11 +5,11 @@ export * from './Category.js' export * from './Customer.js' export * from './Order.js' export * from './Pet.js' -export * from './PetNotFound.js' -export * from './User.js' -export * from './UserArray.js' export * from './petController/index.js' +export * from './PetNotFound.js' export * from './petsController/index.js' export * from './storeController/index.js' export * from './tag/index.js' +export * from './User.js' +export * from './UserArray.js' export * from './userController/index.js' diff --git a/examples/advanced/src/gen/msw/index.ts b/examples/advanced/src/gen/msw/index.ts index dcedf908f..c14a7e57f 100644 --- a/examples/advanced/src/gen/msw/index.ts +++ b/examples/advanced/src/gen/msw/index.ts @@ -1,4 +1,4 @@ export * from './handlers' -export * as petsHandlers from './petsController/index' export * as petHandlers from './petController/index' +export * as petsHandlers from './petsController/index' export * as userHandlers from './userController/index' diff --git a/examples/advanced/src/gen/zod/index.ts b/examples/advanced/src/gen/zod/index.ts index b28c65a55..f09682b9d 100644 --- a/examples/advanced/src/gen/zod/index.ts +++ b/examples/advanced/src/gen/zod/index.ts @@ -4,11 +4,11 @@ export * from './apiResponseSchema' export * from './categorySchema' export * from './customerSchema' export * from './orderSchema' +export * as petSchemas from './petController/index' export * from './petNotFoundSchema' export * from './petSchema' +export * as petsSchemas from './petsController/index' export * from './tag/index' export * from './userArraySchema' -export * from './userSchema' -export * as petsSchemas from './petsController/index' -export * as petSchemas from './petController/index' export * as userSchemas from './userController/index' +export * from './userSchema' diff --git a/examples/faker/src/gen/customMocks/createUser.ts b/examples/faker/src/gen/customMocks/createUser.ts index 297dd91d7..9bca49272 100644 --- a/examples/faker/src/gen/customMocks/createUser.ts +++ b/examples/faker/src/gen/customMocks/createUser.ts @@ -12,7 +12,7 @@ export function createUser(override: NonNullable> = {}): NonNullab 'password': faker.internet.password(), 'phone': faker.phone.number(), 'userStatus': faker.number.float({}), - 'nationalityCode': faker.helpers.fromRegExp(/^[A-Z]{2}$/), + 'nationalityCode': faker.helpers.fromRegExp(/\/^[A-Z]{2}$\//), }, ...override, } diff --git a/examples/faker/src/gen/index.ts b/examples/faker/src/gen/index.ts index bc16ba481..b2ee2d10d 100644 --- a/examples/faker/src/gen/index.ts +++ b/examples/faker/src/gen/index.ts @@ -1,2 +1,2 @@ -export * from './models/index' export * from './customMocks/index' +export * from './models/index' diff --git a/packages/swagger-ts/src/OperationGenerator.test.tsx b/packages/swagger-ts/src/OperationGenerator.test.tsx index 038b8e890..51eb412b3 100644 --- a/packages/swagger-ts/src/OperationGenerator.test.tsx +++ b/packages/swagger-ts/src/OperationGenerator.test.tsx @@ -18,6 +18,7 @@ describe('OperationGenerator', async () => { test('[GET] /pets with optionalType `questionToken`', async () => { const options: GetOperationGeneratorOptions = { enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', usedEnumNames: {}, @@ -56,6 +57,7 @@ describe('OperationGenerator', async () => { test('[POST] /pets 201', async () => { const options: GetOperationGeneratorOptions = { enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', usedEnumNames: {}, @@ -87,6 +89,7 @@ describe('OperationGenerator', async () => { test('[DELETE] /pet/{petId} with unknownType `any`', async () => { const options: GetOperationGeneratorOptions = { enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', usedEnumNames: {}, @@ -117,6 +120,7 @@ describe('OperationGenerator', async () => { test('[DELETE] /pet/{petId} with unknownType `unknown`', async () => { const options: GetOperationGeneratorOptions = { enumType: 'asConst', + enumSuffix: '', dateType: 'string', optionalType: 'questionToken', usedEnumNames: {}, diff --git a/packages/swagger-ts/src/TypeGenerator.ts b/packages/swagger-ts/src/TypeGenerator.ts index 5589347c3..a049ab288 100644 --- a/packages/swagger-ts/src/TypeGenerator.ts +++ b/packages/swagger-ts/src/TypeGenerator.ts @@ -10,7 +10,7 @@ import { pluginKey } from './plugin.ts' import type { PluginManager } from '@kubb/core' import type { ts } from '@kubb/parser' import type { ImportMeta, Refs } from '@kubb/swagger' -import type { Oas, OasTypes, OpenAPIV3, OpenAPIV3_1 } from '@kubb/swagger/oas' +import type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/swagger/oas' import type { PluginOptions } from './types.ts' // based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398 @@ -38,7 +38,7 @@ export class TypeGenerator extends Generator = Object.keys(properties).map((name) => { - const schema = properties[name] as OasTypes.SchemaObject + const schema = properties[name] as SchemaObject const isRequired = Array.isArray(required) ? required.includes(name) : !!required let type = this.getTypeFromSchema(schema, this.context.pluginManager.resolveName({ name: `${baseName || ''} ${name}`, pluginKey, type: 'type' })) @@ -146,7 +146,7 @@ export class TypeGenerator extends Generator { - return item && this.getTypeFromSchema(item as OasTypes.SchemaObject) + return item && this.getTypeFromSchema(item as SchemaObject) }) .filter((item) => { return item && item !== this.#unknownReturn @@ -234,13 +234,13 @@ export class TypeGenerator extends Generator { - return item && this.getTypeFromSchema(item as OasTypes.SchemaObject) + return item && this.getTypeFromSchema(item as SchemaObject) }) .filter((item) => { return item && item !== this.#unknownReturn @@ -257,13 +257,13 @@ export class TypeGenerator extends Generator { - return item && this.getTypeFromSchema(item as OasTypes.SchemaObject) + return item && this.getTypeFromSchema(item as SchemaObject) }) .filter((item) => { return item && item !== this.#unknownReturn @@ -318,7 +318,7 @@ export class TypeGenerator extends Generator array - const node = this.getTypeFromSchema(schema.items as OasTypes.SchemaObject, baseName) + const node = this.getTypeFromSchema(schema.items as SchemaObject, baseName) if (node) { return factory.createArrayTypeNode(node) } @@ -330,7 +330,7 @@ export class TypeGenerator extends Generator { diff --git a/packages/swagger/src/oas/index.ts b/packages/swagger/src/oas/index.ts index 1b6e8a054..a1bd1af63 100644 --- a/packages/swagger/src/oas/index.ts +++ b/packages/swagger/src/oas/index.ts @@ -1,6 +1,10 @@ +import type * as OasTypes from 'oas/types' + // external packages export type { default as Oas } from 'oas' export type { Operation } from 'oas/operation' export type { HttpMethods as HttpMethod } from 'oas/types' export type * as OasTypes from 'oas/types' export type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types' + +export type SchemaObject = OasTypes.SchemaObject & { 'x-nullable'?: boolean }