From 939909354c4413a4ac7ba9b68963e31230992006 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Sat, 14 Dec 2024 15:41:48 +0100 Subject: [PATCH] fix: Use of `toZod` util to create schema based on a type --- .changeset/big-buttons-check.md | 5 + docs/changelog.md | 6 +- docs/plugins/plugin-zod/index.md | 4 + e2e/tsconfig.json | 1 + examples/advanced/configs/kubb.config.ts | 3 +- examples/advanced/src/gen/models/ts/Order.ts | 2 +- .../src/gen/zod/addPetRequestSchema.ts | 6 +- .../advanced/src/gen/zod/addressSchema.ts | 6 +- .../advanced/src/gen/zod/apiResponseSchema.ts | 6 +- .../advanced/src/gen/zod/categorySchema.ts | 6 +- .../advanced/src/gen/zod/customerSchema.ts | 6 +- examples/advanced/src/gen/zod/orderSchema.ts | 6 +- .../src/gen/zod/petController/addPetSchema.ts | 12 +- .../gen/zod/petController/deletePetSchema.ts | 14 +- .../petController/findPetsByStatusSchema.ts | 17 +- .../zod/petController/findPetsByTagsSchema.ts | 22 +- .../gen/zod/petController/getPetByIdSchema.ts | 14 +- .../gen/zod/petController/updatePetSchema.ts | 26 +- .../petController/updatePetWithFormSchema.ts | 19 +- .../gen/zod/petController/uploadFileSchema.ts | 22 +- .../advanced/src/gen/zod/petNotFoundSchema.ts | 6 +- examples/advanced/src/gen/zod/petSchema.ts | 6 +- .../zod/petsController/createPetsSchema.ts | 32 ++- .../advanced/src/gen/zod/tag/tagSchema.ts | 6 +- .../advanced/src/gen/zod/userArraySchema.ts | 3 +- .../zod/userController/createUserSchema.ts | 7 +- .../createUsersWithListInputSchema.ts | 14 +- .../zod/userController/deleteUserSchema.ts | 12 +- .../zod/userController/getUserByNameSchema.ts | 20 +- .../gen/zod/userController/loginUserSchema.ts | 12 +- .../zod/userController/logoutUserSchema.ts | 5 +- .../zod/userController/updateUserSchema.ts | 12 +- examples/advanced/src/gen/zod/userSchema.ts | 6 +- packages/core/package.json | 2 +- packages/fs/package.json | 2 +- packages/oas/package.json | 10 +- packages/oas/src/Oas.test.ts | 2 +- packages/oas/src/index.ts | 2 +- packages/oas/src/parser/index.ts | 35 --- packages/oas/src/utils.ts | 33 ++- packages/oas/tsup.config.ts | 2 - .../src/generators/clientGenerator.test.tsx | 2 +- .../groupedClientGenerator.test.tsx | 2 +- .../generators/operationsGenerator.test.tsx | 2 +- .../parser.test.ts.snap} | 0 .../plugin-faker/src/components/Faker.tsx | 2 +- .../src/generators/fakerGenerator.test.tsx | 2 +- .../{parser/index.test.ts => parser.test.ts} | 4 +- .../src/{parser/index.ts => parser.ts} | 0 .../src/generators/handlersGenerator.test.tsx | 2 +- .../src/generators/mswGenerator.test.tsx | 2 +- .../plugin-oas/src/SchemaGenerator.test.ts | 2 +- .../src/utils/parseFromConfig.test.ts | 2 +- .../plugin-oas/src/utils/parseFromConfig.ts | 2 +- .../infiniteQueryGenerator.test.tsx | 2 +- .../src/generators/mutationGenerator.test.tsx | 2 +- .../src/generators/queryGenerator.test.tsx | 2 +- .../suspenseQueryGenerator.test.tsx | 2 +- .../src/generators/queryGenerator.test.tsx | 2 +- .../src/generators/mutationGenerator.test.tsx | 2 +- .../src/generators/queryGenerator.test.tsx | 2 +- .../src/generators/mutationGenerator.test.tsx | 2 +- .../src/generators/queryGenerator.test.tsx | 2 +- .../parser.test.ts.snap} | 0 packages/plugin-ts/src/components/Type.tsx | 2 +- .../src/generators/typeGenerator.test.tsx | 2 +- .../{parser/index.test.ts => parser.test.ts} | 4 +- .../src/{parser/index.ts => parser.ts} | 0 .../infiniteQueryGenerator.test.tsx | 2 +- .../src/generators/mutationGenerator.test.tsx | 2 +- .../src/generators/queryGenerator.test.tsx | 2 +- packages/plugin-zod/package.json | 9 + .../parser.test.ts.snap} | 0 packages/plugin-zod/src/components/Zod.tsx | 23 +- .../__snapshots__/optionalPetTyped.ts | 3 +- .../src/generators/__snapshots__/pets.ts | 5 +- .../generators/operationsGenerator.test.tsx | 2 +- .../src/generators/zodGenerator.test.tsx | 2 +- .../src/generators/zodGenerator.tsx | 2 + .../{parser/index.test.ts => parser.test.ts} | 4 +- .../src/{parser/index.ts => parser.ts} | 16 +- packages/plugin-zod/src/utils/ToZod.ts | 69 ++++++ packages/plugin-zod/src/utils/index.ts | 1 + packages/plugin-zod/tsup.config.ts | 2 + packages/react/src/components/Const.tsx | 19 +- packages/unplugin-kubb/CHANGELOG.md | 2 +- pnpm-lock.yaml | 228 +++--------------- tsconfig.json | 2 +- 88 files changed, 466 insertions(+), 411 deletions(-) create mode 100644 .changeset/big-buttons-check.md delete mode 100644 packages/oas/src/parser/index.ts rename packages/plugin-faker/src/{parser/__snapshots__/index.test.ts.snap => __snapshots__/parser.test.ts.snap} (100%) rename packages/plugin-faker/src/{parser/index.test.ts => parser.test.ts} (69%) rename packages/plugin-faker/src/{parser/index.ts => parser.ts} (100%) rename packages/plugin-ts/src/{parser/__snapshots__/index.test.ts.snap => __snapshots__/parser.test.ts.snap} (100%) rename packages/plugin-ts/src/{parser/index.test.ts => parser.test.ts} (76%) rename packages/plugin-ts/src/{parser/index.ts => parser.ts} (100%) rename packages/plugin-zod/src/{parser/__snapshots__/index.test.ts.snap => __snapshots__/parser.test.ts.snap} (100%) rename packages/plugin-zod/src/{parser/index.test.ts => parser.test.ts} (69%) rename packages/plugin-zod/src/{parser/index.ts => parser.ts} (97%) create mode 100644 packages/plugin-zod/src/utils/ToZod.ts create mode 100644 packages/plugin-zod/src/utils/index.ts diff --git a/.changeset/big-buttons-check.md b/.changeset/big-buttons-check.md new file mode 100644 index 000000000..8ba23918f --- /dev/null +++ b/.changeset/big-buttons-check.md @@ -0,0 +1,5 @@ +--- +"@kubb/plugin-zod": patch +--- + +Use of `toZod` util to create schema based on a type diff --git a/docs/changelog.md b/docs/changelog.md index b68f5b5cd..5c6c04287 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,9 +4,13 @@ title: Changelog # Changelog +## 3.3.1 +- [`plugin-zod`](/plugins/plugin-zod): Use of `tozod` util to create schema based on a type + + ## 3.3.0 - [`plugin-client`](/plugins/plugin-client): `client` to use `fetch` or `axios` as HTTP client -- [`plugin-zod`](/plugins/plugin-zod): use Regular expression literal instead of RegExp-contructor +- [`plugin-zod`](/plugins/plugin-zod): Use Regular expression literal instead of RegExp-contructor - [`plugin-ts`](/plugins/plugin-ts): Switch between the use of type or interface when creating types ## 3.2.0 diff --git a/docs/plugins/plugin-zod/index.md b/docs/plugins/plugin-zod/index.md index 75e06b93a..3b6691971 100644 --- a/docs/plugins/plugin-zod/index.md +++ b/docs/plugins/plugin-zod/index.md @@ -113,6 +113,10 @@ Return the name of a group based on the group name, this will be used for the fi Use TypeScript(`@kubb/plugin-ts`) to add type annotation. +> [!IMPORTANT] +> We rely on [`tozod`](https://github.com/colinhacks/tozod) from the creator of Zod to create a schema based on a type. +> Kubb contains its own version to those kind of conversions. + | | | |----------:|:----------| | Type: | `boolean` | diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json index 634323646..e3b20d5af 100644 --- a/e2e/tsconfig.json +++ b/e2e/tsconfig.json @@ -30,6 +30,7 @@ "@kubb/plugin-msw": ["../packages/plugin-msw/src/index.ts"], "@kubb/plugin-react-query": ["../packages/plugin-react-query/src/index.ts"], "@kubb/plugin-ts": ["../packages/plugin-ts/src/index.ts"], + "@kubb/plugin-zod/utils": ["../packages/plugin-zod/src/utils/index.ts"], "@kubb/plugin-zod": ["../packages/plugin-zod/src/index.ts"], "@kubb/parser-ts": ["../packages/parser-ts/src/index.ts"] } diff --git a/examples/advanced/configs/kubb.config.ts b/examples/advanced/configs/kubb.config.ts index f6c7a8d4a..d1792c61e 100644 --- a/examples/advanced/configs/kubb.config.ts +++ b/examples/advanced/configs/kubb.config.ts @@ -43,7 +43,7 @@ export default defineConfig(() => { }, enumType: 'asConst', enumSuffix: 'enum', - dateType: 'date', + dateType: 'string', override: [ { type: 'operationId', @@ -148,6 +148,7 @@ export default defineConfig(() => { group: { type: 'tag' }, dateType: 'stringOffset', inferred: true, + typed: true, operations: false, }), pluginFaker({ diff --git a/examples/advanced/src/gen/models/ts/Order.ts b/examples/advanced/src/gen/models/ts/Order.ts index 1cfddab64..0ab5189c0 100644 --- a/examples/advanced/src/gen/models/ts/Order.ts +++ b/examples/advanced/src/gen/models/ts/Order.ts @@ -45,7 +45,7 @@ export type Order = { /** * @type string | undefined, date-time */ - shipDate?: Date + shipDate?: string /** * @description Order Status * @type string | undefined diff --git a/examples/advanced/src/gen/zod/addPetRequestSchema.ts b/examples/advanced/src/gen/zod/addPetRequestSchema.ts index bfe573cf1..7aa97a69a 100644 --- a/examples/advanced/src/gen/zod/addPetRequestSchema.ts +++ b/examples/advanced/src/gen/zod/addPetRequestSchema.ts @@ -1,3 +1,5 @@ +import type { AddPetRequest } from '../models/ts/AddPetRequest.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { categorySchema } from './categorySchema.ts' import { tagTagSchema } from './tag/tagSchema.ts' import { z } from 'zod' @@ -9,6 +11,6 @@ export const addPetRequestSchema = z.object({ photoUrls: z.array(z.string()), tags: z.array(z.lazy(() => tagTagSchema)).optional(), status: z.enum(['available', 'pending', 'sold']).describe('pet status in the store').optional(), -}) +} satisfies ToZod) -export type AddPetRequestSchema = z.infer +export type AddPetRequestSchema = AddPetRequest diff --git a/examples/advanced/src/gen/zod/addressSchema.ts b/examples/advanced/src/gen/zod/addressSchema.ts index 627f0f5ad..979b20246 100644 --- a/examples/advanced/src/gen/zod/addressSchema.ts +++ b/examples/advanced/src/gen/zod/addressSchema.ts @@ -1,3 +1,5 @@ +import type { Address } from '../models/ts/Address.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const addressSchema = z.object({ @@ -5,6 +7,6 @@ export const addressSchema = z.object({ city: z.string().optional(), state: z.string().optional(), zip: z.string().optional(), -}) +} satisfies ToZod
) -export type AddressSchema = z.infer +export type AddressSchema = Address diff --git a/examples/advanced/src/gen/zod/apiResponseSchema.ts b/examples/advanced/src/gen/zod/apiResponseSchema.ts index 9aae9f7f5..a66285c1d 100644 --- a/examples/advanced/src/gen/zod/apiResponseSchema.ts +++ b/examples/advanced/src/gen/zod/apiResponseSchema.ts @@ -1,9 +1,11 @@ +import type { ApiResponse } from '../models/ts/ApiResponse.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const apiResponseSchema = z.object({ code: z.number().int().optional(), type: z.string().optional(), message: z.string().optional(), -}) +} satisfies ToZod) -export type ApiResponseSchema = z.infer +export type ApiResponseSchema = ApiResponse diff --git a/examples/advanced/src/gen/zod/categorySchema.ts b/examples/advanced/src/gen/zod/categorySchema.ts index 6f1d08e14..a146f55a3 100644 --- a/examples/advanced/src/gen/zod/categorySchema.ts +++ b/examples/advanced/src/gen/zod/categorySchema.ts @@ -1,8 +1,10 @@ +import type { Category } from '../models/ts/Category.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const categorySchema = z.object({ id: z.number().int().optional(), name: z.string().optional(), -}) +} satisfies ToZod) -export type CategorySchema = z.infer +export type CategorySchema = Category diff --git a/examples/advanced/src/gen/zod/customerSchema.ts b/examples/advanced/src/gen/zod/customerSchema.ts index 205785586..31b482b7b 100644 --- a/examples/advanced/src/gen/zod/customerSchema.ts +++ b/examples/advanced/src/gen/zod/customerSchema.ts @@ -1,3 +1,5 @@ +import type { Customer } from '../models/ts/Customer.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { addressSchema } from './addressSchema.ts' import { z } from 'zod' @@ -5,6 +7,6 @@ export const customerSchema = z.object({ id: z.number().int().optional(), username: z.string().optional(), address: z.array(z.lazy(() => addressSchema)).optional(), -}) +} satisfies ToZod) -export type CustomerSchema = z.infer +export type CustomerSchema = Customer diff --git a/examples/advanced/src/gen/zod/orderSchema.ts b/examples/advanced/src/gen/zod/orderSchema.ts index 7d34e5336..2f7b6bdf6 100644 --- a/examples/advanced/src/gen/zod/orderSchema.ts +++ b/examples/advanced/src/gen/zod/orderSchema.ts @@ -1,3 +1,5 @@ +import type { Order } from '../models/ts/Order.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const orderSchema = z.object({ @@ -13,6 +15,6 @@ export const orderSchema = z.object({ .describe('HTTP Status') .optional(), complete: z.boolean().optional(), -}) +} satisfies ToZod) -export type OrderSchema = z.infer +export type OrderSchema = Order diff --git a/examples/advanced/src/gen/zod/petController/addPetSchema.ts b/examples/advanced/src/gen/zod/petController/addPetSchema.ts index 039650157..01c67dae4 100644 --- a/examples/advanced/src/gen/zod/petController/addPetSchema.ts +++ b/examples/advanced/src/gen/zod/petController/addPetSchema.ts @@ -1,3 +1,5 @@ +import type { AddPet200, AddPet405, AddPetMutationRequest, AddPetMutationResponse } from '../../models/ts/petController/AddPet.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { addPetRequestSchema } from '../addPetRequestSchema.ts' import { petSchema } from '../petSchema.ts' import { z } from 'zod' @@ -7,7 +9,7 @@ import { z } from 'zod' */ export const addPet200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) -export type AddPet200Schema = z.infer +export type AddPet200Schema = AddPet200 /** * @description Pet not found @@ -15,17 +17,17 @@ export type AddPet200Schema = z.infer export const addPet405Schema = z.object({ code: z.number().int().optional(), message: z.string().optional(), -}) +} satisfies ToZod) -export type AddPet405Schema = z.infer +export type AddPet405Schema = AddPet405 /** * @description Create a new pet in the store */ export const addPetMutationRequestSchema = z.lazy(() => addPetRequestSchema) -export type AddPetMutationRequestSchema = z.infer +export type AddPetMutationRequestSchema = AddPetMutationRequest export const addPetMutationResponseSchema = z.lazy(() => addPet200Schema) -export type AddPetMutationResponseSchema = z.infer +export type AddPetMutationResponseSchema = AddPetMutationResponse diff --git a/examples/advanced/src/gen/zod/petController/deletePetSchema.ts b/examples/advanced/src/gen/zod/petController/deletePetSchema.ts index 8f5b74d38..55c5bf10c 100644 --- a/examples/advanced/src/gen/zod/petController/deletePetSchema.ts +++ b/examples/advanced/src/gen/zod/petController/deletePetSchema.ts @@ -1,26 +1,28 @@ +import type { DeletePetPathParams, DeletePetHeaderParams, DeletePet400, DeletePetMutationResponse } from '../../models/ts/petController/DeletePet.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const deletePetPathParamsSchema = z.object({ petId: z.number().int().describe('Pet id to delete'), -}) +} satisfies ToZod) -export type DeletePetPathParamsSchema = z.infer +export type DeletePetPathParamsSchema = DeletePetPathParams export const deletePetHeaderParamsSchema = z .object({ api_key: z.string().optional(), - }) + } satisfies ToZod) .optional() -export type DeletePetHeaderParamsSchema = z.infer +export type DeletePetHeaderParamsSchema = DeletePetHeaderParams /** * @description Invalid pet value */ export const deletePet400Schema = z.any() -export type DeletePet400Schema = z.infer +export type DeletePet400Schema = DeletePet400 export const deletePetMutationResponseSchema = z.any() -export type DeletePetMutationResponseSchema = z.infer +export type DeletePetMutationResponseSchema = DeletePetMutationResponse diff --git a/examples/advanced/src/gen/zod/petController/findPetsByStatusSchema.ts b/examples/advanced/src/gen/zod/petController/findPetsByStatusSchema.ts index a6c52c1d7..e849bfe37 100644 --- a/examples/advanced/src/gen/zod/petController/findPetsByStatusSchema.ts +++ b/examples/advanced/src/gen/zod/petController/findPetsByStatusSchema.ts @@ -1,11 +1,18 @@ +import type { + FindPetsByStatusPathParams, + FindPetsByStatus200, + FindPetsByStatus400, + FindPetsByStatusQueryResponse, +} from '../../models/ts/petController/FindPetsByStatus.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { petSchema } from '../petSchema.ts' import { z } from 'zod' export const findPetsByStatusPathParamsSchema = z.object({ step_id: z.string(), -}) +} satisfies ToZod) -export type FindPetsByStatusPathParamsSchema = z.infer +export type FindPetsByStatusPathParamsSchema = FindPetsByStatusPathParams /** * @description successful operation @@ -15,15 +22,15 @@ export const findPetsByStatus200Schema = z .min(1) .max(3) -export type FindPetsByStatus200Schema = z.infer +export type FindPetsByStatus200Schema = FindPetsByStatus200 /** * @description Invalid status value */ export const findPetsByStatus400Schema = z.any() -export type FindPetsByStatus400Schema = z.infer +export type FindPetsByStatus400Schema = FindPetsByStatus400 export const findPetsByStatusQueryResponseSchema = z.lazy(() => findPetsByStatus200Schema) -export type FindPetsByStatusQueryResponseSchema = z.infer +export type FindPetsByStatusQueryResponseSchema = FindPetsByStatusQueryResponse diff --git a/examples/advanced/src/gen/zod/petController/findPetsByTagsSchema.ts b/examples/advanced/src/gen/zod/petController/findPetsByTagsSchema.ts index 0d65d0098..fe08a2b3d 100644 --- a/examples/advanced/src/gen/zod/petController/findPetsByTagsSchema.ts +++ b/examples/advanced/src/gen/zod/petController/findPetsByTagsSchema.ts @@ -1,3 +1,11 @@ +import type { + FindPetsByTagsQueryParams, + FindPetsByTagsHeaderParams, + FindPetsByTags200, + FindPetsByTags400, + FindPetsByTagsQueryResponse, +} from '../../models/ts/petController/FindPetsByTags.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { petSchema } from '../petSchema.ts' import { z } from 'zod' @@ -6,31 +14,31 @@ export const findPetsByTagsQueryParamsSchema = z tags: z.array(z.string()).describe('Tags to filter by').optional(), page: z.string().describe('to request with required page number or pagination').optional(), pageSize: z.string().describe('to request with required page size').optional(), - }) + } satisfies ToZod) .optional() -export type FindPetsByTagsQueryParamsSchema = z.infer +export type FindPetsByTagsQueryParamsSchema = FindPetsByTagsQueryParams export const findPetsByTagsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters'), -}) +} satisfies ToZod) -export type FindPetsByTagsHeaderParamsSchema = z.infer +export type FindPetsByTagsHeaderParamsSchema = FindPetsByTagsHeaderParams /** * @description successful operation */ export const findPetsByTags200Schema = z.array(z.lazy(() => petSchema)) -export type FindPetsByTags200Schema = z.infer +export type FindPetsByTags200Schema = FindPetsByTags200 /** * @description Invalid tag value */ export const findPetsByTags400Schema = z.any() -export type FindPetsByTags400Schema = z.infer +export type FindPetsByTags400Schema = FindPetsByTags400 export const findPetsByTagsQueryResponseSchema = z.lazy(() => findPetsByTags200Schema) -export type FindPetsByTagsQueryResponseSchema = z.infer +export type FindPetsByTagsQueryResponseSchema = FindPetsByTagsQueryResponse diff --git a/examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts b/examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts index 16e74ae03..1766159eb 100644 --- a/examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts +++ b/examples/advanced/src/gen/zod/petController/getPetByIdSchema.ts @@ -1,33 +1,35 @@ +import type { GetPetByIdPathParams, GetPetById200, GetPetById400, GetPetById404, GetPetByIdQueryResponse } from '../../models/ts/petController/GetPetById.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { petSchema } from '../petSchema.ts' import { z } from 'zod' export const getPetByIdPathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet to return'), -}) +} satisfies ToZod) -export type GetPetByIdPathParamsSchema = z.infer +export type GetPetByIdPathParamsSchema = GetPetByIdPathParams /** * @description successful operation */ export const getPetById200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) -export type GetPetById200Schema = z.infer +export type GetPetById200Schema = GetPetById200 /** * @description Invalid ID supplied */ export const getPetById400Schema = z.any() -export type GetPetById400Schema = z.infer +export type GetPetById400Schema = GetPetById400 /** * @description Pet not found */ export const getPetById404Schema = z.any() -export type GetPetById404Schema = z.infer +export type GetPetById404Schema = GetPetById404 export const getPetByIdQueryResponseSchema = z.lazy(() => getPetById200Schema) -export type GetPetByIdQueryResponseSchema = z.infer +export type GetPetByIdQueryResponseSchema = GetPetByIdQueryResponse diff --git a/examples/advanced/src/gen/zod/petController/updatePetSchema.ts b/examples/advanced/src/gen/zod/petController/updatePetSchema.ts index 43e5dfde6..cdf0d6bb9 100644 --- a/examples/advanced/src/gen/zod/petController/updatePetSchema.ts +++ b/examples/advanced/src/gen/zod/petController/updatePetSchema.ts @@ -1,3 +1,13 @@ +import type { + UpdatePet200, + UpdatePet202, + UpdatePet400, + UpdatePet404, + UpdatePet405, + UpdatePetMutationRequest, + UpdatePetMutationResponse, +} from '../../models/ts/petController/UpdatePet.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { petSchema } from '../petSchema.ts' import { z } from 'zod' @@ -6,45 +16,45 @@ import { z } from 'zod' */ export const updatePet200Schema = z.lazy(() => petSchema).and(z.object({ name: z.never() })) -export type UpdatePet200Schema = z.infer +export type UpdatePet200Schema = UpdatePet200 /** * @description accepted operation */ export const updatePet202Schema = z.object({ id: z.number().int().optional(), -}) +} satisfies ToZod) -export type UpdatePet202Schema = z.infer +export type UpdatePet202Schema = UpdatePet202 /** * @description Invalid ID supplied */ export const updatePet400Schema = z.any() -export type UpdatePet400Schema = z.infer +export type UpdatePet400Schema = UpdatePet400 /** * @description Pet not found */ export const updatePet404Schema = z.any() -export type UpdatePet404Schema = z.infer +export type UpdatePet404Schema = UpdatePet404 /** * @description Validation exception */ export const updatePet405Schema = z.any() -export type UpdatePet405Schema = z.infer +export type UpdatePet405Schema = UpdatePet405 /** * @description Update an existent pet in the store */ export const updatePetMutationRequestSchema = z.lazy(() => petSchema).and(z.object({ id: z.never() })) -export type UpdatePetMutationRequestSchema = z.infer +export type UpdatePetMutationRequestSchema = UpdatePetMutationRequest export const updatePetMutationResponseSchema = z.union([z.lazy(() => updatePet200Schema), z.lazy(() => updatePet202Schema)]) -export type UpdatePetMutationResponseSchema = z.infer +export type UpdatePetMutationResponseSchema = UpdatePetMutationResponse diff --git a/examples/advanced/src/gen/zod/petController/updatePetWithFormSchema.ts b/examples/advanced/src/gen/zod/petController/updatePetWithFormSchema.ts index 4ca081731..09a402fa9 100644 --- a/examples/advanced/src/gen/zod/petController/updatePetWithFormSchema.ts +++ b/examples/advanced/src/gen/zod/petController/updatePetWithFormSchema.ts @@ -1,27 +1,34 @@ +import type { + UpdatePetWithFormPathParams, + UpdatePetWithFormQueryParams, + UpdatePetWithForm405, + UpdatePetWithFormMutationResponse, +} from '../../models/ts/petController/UpdatePetWithForm.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const updatePetWithFormPathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet that needs to be updated'), -}) +} satisfies ToZod) -export type UpdatePetWithFormPathParamsSchema = z.infer +export type UpdatePetWithFormPathParamsSchema = UpdatePetWithFormPathParams export const updatePetWithFormQueryParamsSchema = z .object({ name: z.string().describe('Name of pet that needs to be updated').optional(), status: z.string().describe('Status of pet that needs to be updated').optional(), - }) + } satisfies ToZod) .optional() -export type UpdatePetWithFormQueryParamsSchema = z.infer +export type UpdatePetWithFormQueryParamsSchema = UpdatePetWithFormQueryParams /** * @description Invalid input */ export const updatePetWithForm405Schema = z.any() -export type UpdatePetWithForm405Schema = z.infer +export type UpdatePetWithForm405Schema = UpdatePetWithForm405 export const updatePetWithFormMutationResponseSchema = z.any() -export type UpdatePetWithFormMutationResponseSchema = z.infer +export type UpdatePetWithFormMutationResponseSchema = UpdatePetWithFormMutationResponse diff --git a/examples/advanced/src/gen/zod/petController/uploadFileSchema.ts b/examples/advanced/src/gen/zod/petController/uploadFileSchema.ts index c4087df79..81946a477 100644 --- a/examples/advanced/src/gen/zod/petController/uploadFileSchema.ts +++ b/examples/advanced/src/gen/zod/petController/uploadFileSchema.ts @@ -1,31 +1,39 @@ +import type { + UploadFilePathParams, + UploadFileQueryParams, + UploadFile200, + UploadFileMutationRequest, + UploadFileMutationResponse, +} from '../../models/ts/petController/UploadFile.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { apiResponseSchema } from '../apiResponseSchema.ts' import { z } from 'zod' export const uploadFilePathParamsSchema = z.object({ petId: z.number().int().describe('ID of pet to update'), -}) +} satisfies ToZod) -export type UploadFilePathParamsSchema = z.infer +export type UploadFilePathParamsSchema = UploadFilePathParams export const uploadFileQueryParamsSchema = z .object({ additionalMetadata: z.string().describe('Additional Metadata').optional(), - }) + } satisfies ToZod) .optional() -export type UploadFileQueryParamsSchema = z.infer +export type UploadFileQueryParamsSchema = UploadFileQueryParams /** * @description successful operation */ export const uploadFile200Schema = z.lazy(() => apiResponseSchema) -export type UploadFile200Schema = z.infer +export type UploadFile200Schema = UploadFile200 export const uploadFileMutationRequestSchema = z.instanceof(File) -export type UploadFileMutationRequestSchema = z.infer +export type UploadFileMutationRequestSchema = UploadFileMutationRequest export const uploadFileMutationResponseSchema = z.lazy(() => uploadFile200Schema) -export type UploadFileMutationResponseSchema = z.infer +export type UploadFileMutationResponseSchema = UploadFileMutationResponse diff --git a/examples/advanced/src/gen/zod/petNotFoundSchema.ts b/examples/advanced/src/gen/zod/petNotFoundSchema.ts index 272034d4c..501bdc2f2 100644 --- a/examples/advanced/src/gen/zod/petNotFoundSchema.ts +++ b/examples/advanced/src/gen/zod/petNotFoundSchema.ts @@ -1,8 +1,10 @@ +import type { PetNotFound } from '../models/ts/PetNotFound.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const petNotFoundSchema = z.object({ code: z.number().int().optional(), message: z.string().optional(), -}) +} satisfies ToZod) -export type PetNotFoundSchema = z.infer +export type PetNotFoundSchema = PetNotFound diff --git a/examples/advanced/src/gen/zod/petSchema.ts b/examples/advanced/src/gen/zod/petSchema.ts index e32b344fe..cb65579d7 100644 --- a/examples/advanced/src/gen/zod/petSchema.ts +++ b/examples/advanced/src/gen/zod/petSchema.ts @@ -1,3 +1,5 @@ +import type { Pet } from '../models/ts/Pet.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { categorySchema } from './categorySchema.ts' import { tagTagSchema } from './tag/tagSchema.ts' import { z } from 'zod' @@ -9,6 +11,6 @@ export const petSchema = z.object({ photoUrls: z.array(z.string()), tags: z.array(z.lazy(() => tagTagSchema)).optional(), status: z.enum(['available', 'pending', 'sold']).describe('pet status in the store').optional(), -}) +} satisfies ToZod) -export type PetSchema = z.infer +export type PetSchema = Pet diff --git a/examples/advanced/src/gen/zod/petsController/createPetsSchema.ts b/examples/advanced/src/gen/zod/petsController/createPetsSchema.ts index e19b529ef..7564e65be 100644 --- a/examples/advanced/src/gen/zod/petsController/createPetsSchema.ts +++ b/examples/advanced/src/gen/zod/petsController/createPetsSchema.ts @@ -1,47 +1,57 @@ +import type { + CreatePetsPathParams, + CreatePetsQueryParams, + CreatePetsHeaderParams, + CreatePets201, + CreatePetsError, + CreatePetsMutationRequest, + CreatePetsMutationResponse, +} from '../../models/ts/petsController/CreatePets.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { petNotFoundSchema } from '../petNotFoundSchema.ts' import { z } from 'zod' export const createPetsPathParamsSchema = z.object({ uuid: z.string().describe('UUID'), -}) +} satisfies ToZod) -export type CreatePetsPathParamsSchema = z.infer +export type CreatePetsPathParamsSchema = CreatePetsPathParams export const createPetsQueryParamsSchema = z .object({ offset: z.number().int().describe('Offset */').optional(), - }) + } satisfies ToZod) .optional() -export type CreatePetsQueryParamsSchema = z.infer +export type CreatePetsQueryParamsSchema = CreatePetsQueryParams export const createPetsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters'), -}) +} satisfies ToZod) -export type CreatePetsHeaderParamsSchema = z.infer +export type CreatePetsHeaderParamsSchema = CreatePetsHeaderParams /** * @description Null response */ export const createPets201Schema = z.any() -export type CreatePets201Schema = z.infer +export type CreatePets201Schema = CreatePets201 /** * @description unexpected error */ export const createPetsErrorSchema = z.lazy(() => petNotFoundSchema) -export type CreatePetsErrorSchema = z.infer +export type CreatePetsErrorSchema = CreatePetsError export const createPetsMutationRequestSchema = z.object({ name: z.string(), tag: z.string(), -}) +} satisfies ToZod) -export type CreatePetsMutationRequestSchema = z.infer +export type CreatePetsMutationRequestSchema = CreatePetsMutationRequest export const createPetsMutationResponseSchema = z.lazy(() => createPets201Schema) -export type CreatePetsMutationResponseSchema = z.infer +export type CreatePetsMutationResponseSchema = CreatePetsMutationResponse diff --git a/examples/advanced/src/gen/zod/tag/tagSchema.ts b/examples/advanced/src/gen/zod/tag/tagSchema.ts index 1d9a5dd76..72e603b68 100644 --- a/examples/advanced/src/gen/zod/tag/tagSchema.ts +++ b/examples/advanced/src/gen/zod/tag/tagSchema.ts @@ -1,8 +1,10 @@ +import type { TagTag } from '../../models/ts/tag/Tag.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const tagTagSchema = z.object({ id: z.number().int().optional(), name: z.string().optional(), -}) +} satisfies ToZod) -export type TagTagSchema = z.infer +export type TagTagSchema = TagTag diff --git a/examples/advanced/src/gen/zod/userArraySchema.ts b/examples/advanced/src/gen/zod/userArraySchema.ts index 4db4d3a5c..99a5203b2 100644 --- a/examples/advanced/src/gen/zod/userArraySchema.ts +++ b/examples/advanced/src/gen/zod/userArraySchema.ts @@ -1,6 +1,7 @@ +import type { UserArray } from '../models/ts/UserArray.ts' import { userSchema } from './userSchema.ts' import { z } from 'zod' export const userArraySchema = z.array(z.lazy(() => userSchema)) -export type UserArraySchema = z.infer +export type UserArraySchema = UserArray diff --git a/examples/advanced/src/gen/zod/userController/createUserSchema.ts b/examples/advanced/src/gen/zod/userController/createUserSchema.ts index f368457be..de3ad8a37 100644 --- a/examples/advanced/src/gen/zod/userController/createUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/createUserSchema.ts @@ -1,3 +1,4 @@ +import type { CreateUserError, CreateUserMutationRequest, CreateUserMutationResponse } from '../../models/ts/userController/CreateUser.ts' import { userSchema } from '../userSchema.ts' import { z } from 'zod' @@ -6,15 +7,15 @@ import { z } from 'zod' */ export const createUserErrorSchema = z.lazy(() => userSchema) -export type CreateUserErrorSchema = z.infer +export type CreateUserErrorSchema = CreateUserError /** * @description Created user object */ export const createUserMutationRequestSchema = z.lazy(() => userSchema) -export type CreateUserMutationRequestSchema = z.infer +export type CreateUserMutationRequestSchema = CreateUserMutationRequest export const createUserMutationResponseSchema = z.any() -export type CreateUserMutationResponseSchema = z.infer +export type CreateUserMutationResponseSchema = CreateUserMutationResponse diff --git a/examples/advanced/src/gen/zod/userController/createUsersWithListInputSchema.ts b/examples/advanced/src/gen/zod/userController/createUsersWithListInputSchema.ts index fbcaa4184..69a5d4d69 100644 --- a/examples/advanced/src/gen/zod/userController/createUsersWithListInputSchema.ts +++ b/examples/advanced/src/gen/zod/userController/createUsersWithListInputSchema.ts @@ -1,3 +1,9 @@ +import type { + CreateUsersWithListInput200, + CreateUsersWithListInputError, + CreateUsersWithListInputMutationRequest, + CreateUsersWithListInputMutationResponse, +} from '../../models/ts/userController/CreateUsersWithListInput.ts' import { userSchema } from '../userSchema.ts' import { z } from 'zod' @@ -6,19 +12,19 @@ import { z } from 'zod' */ export const createUsersWithListInput200Schema = z.lazy(() => userSchema) -export type CreateUsersWithListInput200Schema = z.infer +export type CreateUsersWithListInput200Schema = CreateUsersWithListInput200 /** * @description successful operation */ export const createUsersWithListInputErrorSchema = z.any() -export type CreateUsersWithListInputErrorSchema = z.infer +export type CreateUsersWithListInputErrorSchema = CreateUsersWithListInputError export const createUsersWithListInputMutationRequestSchema = z.array(z.lazy(() => userSchema)) -export type CreateUsersWithListInputMutationRequestSchema = z.infer +export type CreateUsersWithListInputMutationRequestSchema = CreateUsersWithListInputMutationRequest export const createUsersWithListInputMutationResponseSchema = z.lazy(() => createUsersWithListInput200Schema) -export type CreateUsersWithListInputMutationResponseSchema = z.infer +export type CreateUsersWithListInputMutationResponseSchema = CreateUsersWithListInputMutationResponse diff --git a/examples/advanced/src/gen/zod/userController/deleteUserSchema.ts b/examples/advanced/src/gen/zod/userController/deleteUserSchema.ts index facc0321b..b702a4480 100644 --- a/examples/advanced/src/gen/zod/userController/deleteUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/deleteUserSchema.ts @@ -1,25 +1,27 @@ +import type { DeleteUserPathParams, DeleteUser400, DeleteUser404, DeleteUserMutationResponse } from '../../models/ts/userController/DeleteUser.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const deleteUserPathParamsSchema = z.object({ username: z.string().describe('The name that needs to be deleted'), -}) +} satisfies ToZod) -export type DeleteUserPathParamsSchema = z.infer +export type DeleteUserPathParamsSchema = DeleteUserPathParams /** * @description Invalid username supplied */ export const deleteUser400Schema = z.any() -export type DeleteUser400Schema = z.infer +export type DeleteUser400Schema = DeleteUser400 /** * @description User not found */ export const deleteUser404Schema = z.any() -export type DeleteUser404Schema = z.infer +export type DeleteUser404Schema = DeleteUser404 export const deleteUserMutationResponseSchema = z.any() -export type DeleteUserMutationResponseSchema = z.infer +export type DeleteUserMutationResponseSchema = DeleteUserMutationResponse diff --git a/examples/advanced/src/gen/zod/userController/getUserByNameSchema.ts b/examples/advanced/src/gen/zod/userController/getUserByNameSchema.ts index 85f3e01a7..32bbc6ba7 100644 --- a/examples/advanced/src/gen/zod/userController/getUserByNameSchema.ts +++ b/examples/advanced/src/gen/zod/userController/getUserByNameSchema.ts @@ -1,33 +1,41 @@ +import type { + GetUserByNamePathParams, + GetUserByName200, + GetUserByName400, + GetUserByName404, + GetUserByNameQueryResponse, +} from '../../models/ts/userController/GetUserByName.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { userSchema } from '../userSchema.ts' import { z } from 'zod' export const getUserByNamePathParamsSchema = z.object({ username: z.string().describe('The name that needs to be fetched. Use user1 for testing. '), -}) +} satisfies ToZod) -export type GetUserByNamePathParamsSchema = z.infer +export type GetUserByNamePathParamsSchema = GetUserByNamePathParams /** * @description successful operation */ export const getUserByName200Schema = z.lazy(() => userSchema) -export type GetUserByName200Schema = z.infer +export type GetUserByName200Schema = GetUserByName200 /** * @description Invalid username supplied */ export const getUserByName400Schema = z.any() -export type GetUserByName400Schema = z.infer +export type GetUserByName400Schema = GetUserByName400 /** * @description User not found */ export const getUserByName404Schema = z.any() -export type GetUserByName404Schema = z.infer +export type GetUserByName404Schema = GetUserByName404 export const getUserByNameQueryResponseSchema = z.lazy(() => getUserByName200Schema) -export type GetUserByNameQueryResponseSchema = z.infer +export type GetUserByNameQueryResponseSchema = GetUserByNameQueryResponse diff --git a/examples/advanced/src/gen/zod/userController/loginUserSchema.ts b/examples/advanced/src/gen/zod/userController/loginUserSchema.ts index 3d057fa59..b989c9d21 100644 --- a/examples/advanced/src/gen/zod/userController/loginUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/loginUserSchema.ts @@ -1,28 +1,30 @@ +import type { LoginUserQueryParams, LoginUser200, LoginUser400, LoginUserQueryResponse } from '../../models/ts/userController/LoginUser.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const loginUserQueryParamsSchema = z .object({ username: z.string().describe('The user name for login').optional(), password: z.string().describe('The password for login in clear text').optional(), - }) + } satisfies ToZod) .optional() -export type LoginUserQueryParamsSchema = z.infer +export type LoginUserQueryParamsSchema = LoginUserQueryParams /** * @description successful operation */ export const loginUser200Schema = z.string() -export type LoginUser200Schema = z.infer +export type LoginUser200Schema = LoginUser200 /** * @description Invalid username/password supplied */ export const loginUser400Schema = z.any() -export type LoginUser400Schema = z.infer +export type LoginUser400Schema = LoginUser400 export const loginUserQueryResponseSchema = z.lazy(() => loginUser200Schema) -export type LoginUserQueryResponseSchema = z.infer +export type LoginUserQueryResponseSchema = LoginUserQueryResponse diff --git a/examples/advanced/src/gen/zod/userController/logoutUserSchema.ts b/examples/advanced/src/gen/zod/userController/logoutUserSchema.ts index 3fc55d038..e0da31fe4 100644 --- a/examples/advanced/src/gen/zod/userController/logoutUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/logoutUserSchema.ts @@ -1,3 +1,4 @@ +import type { LogoutUserError, LogoutUserQueryResponse } from '../../models/ts/userController/LogoutUser.ts' import { z } from 'zod' /** @@ -5,8 +6,8 @@ import { z } from 'zod' */ export const logoutUserErrorSchema = z.any() -export type LogoutUserErrorSchema = z.infer +export type LogoutUserErrorSchema = LogoutUserError export const logoutUserQueryResponseSchema = z.any() -export type LogoutUserQueryResponseSchema = z.infer +export type LogoutUserQueryResponseSchema = LogoutUserQueryResponse diff --git a/examples/advanced/src/gen/zod/userController/updateUserSchema.ts b/examples/advanced/src/gen/zod/userController/updateUserSchema.ts index b43d3e20f..cdeb7d0b4 100644 --- a/examples/advanced/src/gen/zod/userController/updateUserSchema.ts +++ b/examples/advanced/src/gen/zod/userController/updateUserSchema.ts @@ -1,26 +1,28 @@ +import type { UpdateUserPathParams, UpdateUserError, UpdateUserMutationRequest, UpdateUserMutationResponse } from '../../models/ts/userController/UpdateUser.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { userSchema } from '../userSchema.ts' import { z } from 'zod' export const updateUserPathParamsSchema = z.object({ username: z.string().describe('name that need to be deleted'), -}) +} satisfies ToZod) -export type UpdateUserPathParamsSchema = z.infer +export type UpdateUserPathParamsSchema = UpdateUserPathParams /** * @description successful operation */ export const updateUserErrorSchema = z.any() -export type UpdateUserErrorSchema = z.infer +export type UpdateUserErrorSchema = UpdateUserError /** * @description Update an existent user in the store */ export const updateUserMutationRequestSchema = z.lazy(() => userSchema) -export type UpdateUserMutationRequestSchema = z.infer +export type UpdateUserMutationRequestSchema = UpdateUserMutationRequest export const updateUserMutationResponseSchema = z.any() -export type UpdateUserMutationResponseSchema = z.infer +export type UpdateUserMutationResponseSchema = UpdateUserMutationResponse diff --git a/examples/advanced/src/gen/zod/userSchema.ts b/examples/advanced/src/gen/zod/userSchema.ts index 4953e52c3..48d86b92f 100644 --- a/examples/advanced/src/gen/zod/userSchema.ts +++ b/examples/advanced/src/gen/zod/userSchema.ts @@ -1,3 +1,5 @@ +import type { User } from '../models/ts/User.ts' +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const userSchema = z.object({ @@ -10,6 +12,6 @@ export const userSchema = z.object({ password: z.string().optional(), phone: z.string().optional(), userStatus: z.number().int().describe('User Status').optional(), -}) +} satisfies ToZod) -export type UserSchema = z.infer +export type UserSchema = User diff --git a/packages/core/package.json b/packages/core/package.json index d3665c060..b3cd5efec 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -91,7 +91,7 @@ "@kubb/types": "workspace:*", "change-case": "^5.4.4", "find-up": "^7.0.0", - "natural-orderby": "^4.0.0", + "natural-orderby": "^5.0.0", "object-hash": "^3.0.0", "p-queue": "^8.0.1", "remeda": "^2.17.4", diff --git a/packages/fs/package.json b/packages/fs/package.json index d39494b42..95da71900 100644 --- a/packages/fs/package.json +++ b/packages/fs/package.json @@ -64,7 +64,7 @@ "@kubb/config-ts": "workspace:*", "@kubb/config-tsup": "workspace:*", "@types/fs-extra": "^11.0.4", - "tsup": "^8.3.5" + "tsup": "catalog:" }, "engines": { "node": ">=20" diff --git a/packages/oas/package.json b/packages/oas/package.json index b555c61c1..8dd9c4e8a 100644 --- a/packages/oas/package.json +++ b/packages/oas/package.json @@ -23,11 +23,6 @@ "require": "./dist/index.cjs", "default": "./dist/index.cjs" }, - "./parser": { - "import": "./dist/parser.js", - "require": "./dist/parser.cjs", - "default": "./dist/parser.cjs" - }, "./infer": { "import": "./dist/infer.js", "require": "./dist/infer.cjs", @@ -41,9 +36,6 @@ "types": "./dist/index.d.cts", "typesVersions": { "*": { - "parser": [ - "./dist/parser.d.ts" - ], "infer": [ "./dist/infer.d.ts" ] @@ -83,7 +75,7 @@ "@kubb/config-tsup": "workspace:*", "@stoplight/yaml": "^4.3.0", "@types/swagger2openapi": "^7.0.4", - "expect-type": "^0.20.0", + "expect-type": "^1.1.0", "tsup": "catalog:", "typescript": "catalog:" }, diff --git a/packages/oas/src/Oas.test.ts b/packages/oas/src/Oas.test.ts index 9ee42f586..a0b5db50d 100644 --- a/packages/oas/src/Oas.test.ts +++ b/packages/oas/src/Oas.test.ts @@ -7,7 +7,7 @@ import { petStore } from '../mocks/petStore.ts' import { Oas } from './Oas.ts' import type { Infer, MethodMap, Model, PathMap, RequestParams, Response } from './infer/index.ts' -import { parse } from './parser/index.ts' +import { parse } from './utils.ts' describe('swagger Infer', () => { const oas = new Oas({ oas: petStore }) diff --git a/packages/oas/src/index.ts b/packages/oas/src/index.ts index 88e9de25a..56a7279a5 100644 --- a/packages/oas/src/index.ts +++ b/packages/oas/src/index.ts @@ -1,5 +1,5 @@ export * from './types.ts' export { findSchemaDefinition, matchesMimeType } from 'oas/utils' -export { isRequired, isOptional, isReference, isParameterObject, isOpenApiV3_1Document } from './utils.ts' +export { isRequired, isOptional, isReference, isParameterObject, isOpenApiV3_1Document, parse } from './utils.ts' export { Oas } from './Oas.ts' export type { Infer, Model, RequestParams, Response } from './infer/index.ts' diff --git a/packages/oas/src/parser/index.ts b/packages/oas/src/parser/index.ts deleted file mode 100644 index b7b3629e3..000000000 --- a/packages/oas/src/parser/index.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { bundle, loadConfig } from '@redocly/openapi-core' -import OASNormalize from 'oas-normalize' -import swagger2openapi from 'swagger2openapi' - -import { Oas } from '../Oas.ts' -import { isOpenApiV2Document } from '../utils.ts' - -import type { OASDocument } from 'oas/types' -import type { OpenAPI } from 'openapi-types' - -export async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise { - if (typeof pathOrApi === 'string') { - // resolve external refs - const config = await loadConfig() - const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi }) - - return parse(bundleResults.bundle.parsed) - } - - const oasNormalize = new OASNormalize(pathOrApi, { - enablePaths: true, - colorizeErrors: true, - }) - const document = (await oasNormalize.load()) as OpenAPI.Document - - if (isOpenApiV2Document(document)) { - const { openapi } = await swagger2openapi.convertObj(document, { - anchors: true, - }) - - return new oasClass({ oas: openapi as OASDocument }) - } - - return new oasClass({ oas: document }) -} diff --git a/packages/oas/src/utils.ts b/packages/oas/src/utils.ts index 69f8becf3..0236a4d18 100644 --- a/packages/oas/src/utils.ts +++ b/packages/oas/src/utils.ts @@ -1,8 +1,13 @@ import { isRef, isSchema } from 'oas/types' import { isPlainObject } from 'remeda' +import { bundle, loadConfig } from '@redocly/openapi-core' +import OASNormalize from 'oas-normalize' +import type { OASDocument } from 'oas/types' import type { ParameterObject, SchemaObject } from 'oas/types' -import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types' +import type { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types' +import swagger2openapi from 'swagger2openapi' +import { Oas } from './Oas.ts' export function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document { return doc && isPlainObject(doc) && !('openapi' in doc) @@ -38,3 +43,29 @@ export function isRequired(schema?: SchemaObject): boolean { export function isOptional(schema?: SchemaObject): boolean { return !isRequired(schema) } + +export async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise { + if (typeof pathOrApi === 'string') { + // resolve external refs + const config = await loadConfig() + const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi }) + + return parse(bundleResults.bundle.parsed) + } + + const oasNormalize = new OASNormalize(pathOrApi, { + enablePaths: true, + colorizeErrors: true, + }) + const document = (await oasNormalize.load()) as OpenAPI.Document + + if (isOpenApiV2Document(document)) { + const { openapi } = await swagger2openapi.convertObj(document, { + anchors: true, + }) + + return new oasClass({ oas: openapi as OASDocument }) + } + + return new oasClass({ oas: document }) +} diff --git a/packages/oas/tsup.config.ts b/packages/oas/tsup.config.ts index 31558415b..cf0d09d30 100644 --- a/packages/oas/tsup.config.ts +++ b/packages/oas/tsup.config.ts @@ -7,7 +7,6 @@ export default defineConfig([ ...optionsCJS, entry: { index: 'src/index.ts', - parser: 'src/parser/index.ts', infer: 'src/infer/index.ts', }, noExternal: [/whatwg-url/], @@ -16,7 +15,6 @@ export default defineConfig([ ...optionsESM, entry: { index: 'src/index.ts', - parser: 'src/parser/index.ts', infer: 'src/infer/index.ts', }, noExternal: [/whatwg-url/], diff --git a/packages/plugin-client/src/generators/clientGenerator.test.tsx b/packages/plugin-client/src/generators/clientGenerator.test.tsx index d4365912d..051093745 100644 --- a/packages/plugin-client/src/generators/clientGenerator.test.tsx +++ b/packages/plugin-client/src/generators/clientGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import type { PluginClient } from '../types.ts' import { clientGenerator } from './clientGenerator.tsx' diff --git a/packages/plugin-client/src/generators/groupedClientGenerator.test.tsx b/packages/plugin-client/src/generators/groupedClientGenerator.test.tsx index ce700ac44..b5a5103d5 100644 --- a/packages/plugin-client/src/generators/groupedClientGenerator.test.tsx +++ b/packages/plugin-client/src/generators/groupedClientGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import type { PluginClient } from '../types.ts' import { groupedClientGenerator } from './groupedClientGenerator.tsx' diff --git a/packages/plugin-client/src/generators/operationsGenerator.test.tsx b/packages/plugin-client/src/generators/operationsGenerator.test.tsx index a34f16832..056326afb 100644 --- a/packages/plugin-client/src/generators/operationsGenerator.test.tsx +++ b/packages/plugin-client/src/generators/operationsGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import type { PluginClient } from '../types.ts' import { operationsGenerator } from './operationsGenerator.tsx' diff --git a/packages/plugin-faker/src/parser/__snapshots__/index.test.ts.snap b/packages/plugin-faker/src/__snapshots__/parser.test.ts.snap similarity index 100% rename from packages/plugin-faker/src/parser/__snapshots__/index.test.ts.snap rename to packages/plugin-faker/src/__snapshots__/parser.test.ts.snap diff --git a/packages/plugin-faker/src/components/Faker.tsx b/packages/plugin-faker/src/components/Faker.tsx index 44e609e6d..931a02445 100644 --- a/packages/plugin-faker/src/components/Faker.tsx +++ b/packages/plugin-faker/src/components/Faker.tsx @@ -3,7 +3,7 @@ import { File, Function, FunctionParams } from '@kubb/react' import transformers from '@kubb/core/transformers' import type { Schema } from '@kubb/plugin-oas' import type { KubbNode } from '@kubb/react/types' -import * as parserFaker from '../parser/index.ts' +import * as parserFaker from '../parser.ts' import type { PluginFaker } from '../types.ts' type Props = { diff --git a/packages/plugin-faker/src/generators/fakerGenerator.test.tsx b/packages/plugin-faker/src/generators/fakerGenerator.test.tsx index ba6266f83..e566f1f01 100644 --- a/packages/plugin-faker/src/generators/fakerGenerator.test.tsx +++ b/packages/plugin-faker/src/generators/fakerGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles, mockedPluginManager } from '@kub import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator, SchemaGenerator } from '@kubb/plugin-oas' import { getSchemas } from '@kubb/plugin-oas/utils' import type { PluginFaker } from '../types.ts' diff --git a/packages/plugin-faker/src/parser/index.test.ts b/packages/plugin-faker/src/parser.test.ts similarity index 69% rename from packages/plugin-faker/src/parser/index.test.ts rename to packages/plugin-faker/src/parser.test.ts index 4031184cc..a4285d28f 100644 --- a/packages/plugin-faker/src/parser/index.test.ts +++ b/packages/plugin-faker/src/parser.test.ts @@ -1,6 +1,6 @@ -import { schemas } from '../../../plugin-oas/mocks/schemas.ts' +import { schemas } from '../../plugin-oas/mocks/schemas.ts' -import * as parserFaker from './index.ts' +import * as parserFaker from './parser.ts' describe('faker parse', () => { test.each(schemas.basic)('$name', ({ name, schema }) => { diff --git a/packages/plugin-faker/src/parser/index.ts b/packages/plugin-faker/src/parser.ts similarity index 100% rename from packages/plugin-faker/src/parser/index.ts rename to packages/plugin-faker/src/parser.ts diff --git a/packages/plugin-msw/src/generators/handlersGenerator.test.tsx b/packages/plugin-msw/src/generators/handlersGenerator.test.tsx index 0fc1e8132..100eb3dde 100644 --- a/packages/plugin-msw/src/generators/handlersGenerator.test.tsx +++ b/packages/plugin-msw/src/generators/handlersGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import type { PluginMsw } from '../types.ts' import { handlersGenerator } from './handlersGenerator.tsx' diff --git a/packages/plugin-msw/src/generators/mswGenerator.test.tsx b/packages/plugin-msw/src/generators/mswGenerator.test.tsx index 5d976a0e9..d015c479a 100644 --- a/packages/plugin-msw/src/generators/mswGenerator.test.tsx +++ b/packages/plugin-msw/src/generators/mswGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles, mockedPluginManager } from '@kub import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import type { PluginMsw } from '../types.ts' import { mswGenerator } from './mswGenerator.tsx' diff --git a/packages/plugin-oas/src/SchemaGenerator.test.ts b/packages/plugin-oas/src/SchemaGenerator.test.ts index 62c9b09c9..6f878fa2b 100644 --- a/packages/plugin-oas/src/SchemaGenerator.test.ts +++ b/packages/plugin-oas/src/SchemaGenerator.test.ts @@ -1,7 +1,7 @@ import path from 'node:path' import type { Plugin } from '@kubb/core' import { mockedPluginManager } from '@kubb/core/mocks' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { type GetSchemaGeneratorOptions, SchemaGenerator } from './SchemaGenerator.ts' describe('SchemaGenerator core', async () => { diff --git a/packages/plugin-oas/src/utils/parseFromConfig.test.ts b/packages/plugin-oas/src/utils/parseFromConfig.test.ts index f2fe859bf..7e3f498bc 100644 --- a/packages/plugin-oas/src/utils/parseFromConfig.test.ts +++ b/packages/plugin-oas/src/utils/parseFromConfig.test.ts @@ -2,7 +2,7 @@ import path from 'node:path' import yaml from '@stoplight/yaml' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import type { Config } from '@kubb/core' import { parseFromConfig } from './parseFromConfig.ts' diff --git a/packages/plugin-oas/src/utils/parseFromConfig.ts b/packages/plugin-oas/src/utils/parseFromConfig.ts index bcd52d98b..a9b48b2fd 100644 --- a/packages/plugin-oas/src/utils/parseFromConfig.ts +++ b/packages/plugin-oas/src/utils/parseFromConfig.ts @@ -2,7 +2,7 @@ import { resolve } from 'node:path' import { URLPath } from '@kubb/core/utils' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import type { Config } from '@kubb/core' import { Oas, type OasTypes } from '@kubb/oas' diff --git a/packages/plugin-react-query/src/generators/infiniteQueryGenerator.test.tsx b/packages/plugin-react-query/src/generators/infiniteQueryGenerator.test.tsx index 7e0e11ed8..f492e03b3 100644 --- a/packages/plugin-react-query/src/generators/infiniteQueryGenerator.test.tsx +++ b/packages/plugin-react-query/src/generators/infiniteQueryGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginReactQuery } from '../types.ts' diff --git a/packages/plugin-react-query/src/generators/mutationGenerator.test.tsx b/packages/plugin-react-query/src/generators/mutationGenerator.test.tsx index aa6191890..494001c3f 100644 --- a/packages/plugin-react-query/src/generators/mutationGenerator.test.tsx +++ b/packages/plugin-react-query/src/generators/mutationGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginReactQuery } from '../types.ts' diff --git a/packages/plugin-react-query/src/generators/queryGenerator.test.tsx b/packages/plugin-react-query/src/generators/queryGenerator.test.tsx index 39e4f641b..61d2a1be5 100644 --- a/packages/plugin-react-query/src/generators/queryGenerator.test.tsx +++ b/packages/plugin-react-query/src/generators/queryGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginReactQuery } from '../types.ts' diff --git a/packages/plugin-react-query/src/generators/suspenseQueryGenerator.test.tsx b/packages/plugin-react-query/src/generators/suspenseQueryGenerator.test.tsx index 1c0301854..badd87232 100644 --- a/packages/plugin-react-query/src/generators/suspenseQueryGenerator.test.tsx +++ b/packages/plugin-react-query/src/generators/suspenseQueryGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginReactQuery } from '../types.ts' diff --git a/packages/plugin-solid-query/src/generators/queryGenerator.test.tsx b/packages/plugin-solid-query/src/generators/queryGenerator.test.tsx index ed8f07f4f..2cdaab702 100644 --- a/packages/plugin-solid-query/src/generators/queryGenerator.test.tsx +++ b/packages/plugin-solid-query/src/generators/queryGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { QueryKey } from '../components' import type { PluginSolidQuery } from '../types.ts' diff --git a/packages/plugin-svelte-query/src/generators/mutationGenerator.test.tsx b/packages/plugin-svelte-query/src/generators/mutationGenerator.test.tsx index 171e45c10..e96f9758a 100644 --- a/packages/plugin-svelte-query/src/generators/mutationGenerator.test.tsx +++ b/packages/plugin-svelte-query/src/generators/mutationGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginSvelteQuery } from '../types.ts' diff --git a/packages/plugin-svelte-query/src/generators/queryGenerator.test.tsx b/packages/plugin-svelte-query/src/generators/queryGenerator.test.tsx index cd09296f3..a4b746f1d 100644 --- a/packages/plugin-svelte-query/src/generators/queryGenerator.test.tsx +++ b/packages/plugin-svelte-query/src/generators/queryGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginSvelteQuery } from '../types.ts' diff --git a/packages/plugin-swr/src/generators/mutationGenerator.test.tsx b/packages/plugin-swr/src/generators/mutationGenerator.test.tsx index db74d54b6..673660677 100644 --- a/packages/plugin-swr/src/generators/mutationGenerator.test.tsx +++ b/packages/plugin-swr/src/generators/mutationGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginSwr } from '../types.ts' diff --git a/packages/plugin-swr/src/generators/queryGenerator.test.tsx b/packages/plugin-swr/src/generators/queryGenerator.test.tsx index bf7dc235b..c994c774e 100644 --- a/packages/plugin-swr/src/generators/queryGenerator.test.tsx +++ b/packages/plugin-swr/src/generators/queryGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginSwr } from '../types.ts' diff --git a/packages/plugin-ts/src/parser/__snapshots__/index.test.ts.snap b/packages/plugin-ts/src/__snapshots__/parser.test.ts.snap similarity index 100% rename from packages/plugin-ts/src/parser/__snapshots__/index.test.ts.snap rename to packages/plugin-ts/src/__snapshots__/parser.test.ts.snap diff --git a/packages/plugin-ts/src/components/Type.tsx b/packages/plugin-ts/src/components/Type.tsx index 55bfe30cb..7e579f3d0 100644 --- a/packages/plugin-ts/src/components/Type.tsx +++ b/packages/plugin-ts/src/components/Type.tsx @@ -7,7 +7,7 @@ import { createTypeDeclaration } from '@kubb/parser-ts/factory' import { type Schema, SchemaGenerator, isKeyword, schemaKeywords } from '@kubb/plugin-oas' import { Fragment, type ReactNode } from 'react' import type ts from 'typescript' -import { parse, typeKeywordMapper } from '../parser/index.ts' +import { parse, typeKeywordMapper } from '../parser.ts' import type { PluginTs } from '../types.ts' type Props = { diff --git a/packages/plugin-ts/src/generators/typeGenerator.test.tsx b/packages/plugin-ts/src/generators/typeGenerator.test.tsx index dbe00bc82..9a09fcc10 100644 --- a/packages/plugin-ts/src/generators/typeGenerator.test.tsx +++ b/packages/plugin-ts/src/generators/typeGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator, SchemaGenerator } from '@kubb/plugin-oas' import { getSchemas } from '@kubb/plugin-oas/utils' import ts, { factory } from 'typescript' diff --git a/packages/plugin-ts/src/parser/index.test.ts b/packages/plugin-ts/src/parser.test.ts similarity index 76% rename from packages/plugin-ts/src/parser/index.test.ts rename to packages/plugin-ts/src/parser.test.ts index 1ace8cdea..a81917200 100644 --- a/packages/plugin-ts/src/parser/index.test.ts +++ b/packages/plugin-ts/src/parser.test.ts @@ -1,6 +1,6 @@ -import { schemas } from '../../../plugin-oas/mocks/schemas.ts' +import { schemas } from '../../plugin-oas/mocks/schemas.ts' -import * as parserType from './index.ts' +import * as parserType from './parser.ts' describe('type parse', () => { test.each(schemas.basic)('$name', ({ name, schema }) => { diff --git a/packages/plugin-ts/src/parser/index.ts b/packages/plugin-ts/src/parser.ts similarity index 100% rename from packages/plugin-ts/src/parser/index.ts rename to packages/plugin-ts/src/parser.ts diff --git a/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.test.tsx b/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.test.tsx index 635478962..9102d877c 100644 --- a/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.test.tsx +++ b/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginVueQuery } from '../types.ts' diff --git a/packages/plugin-vue-query/src/generators/mutationGenerator.test.tsx b/packages/plugin-vue-query/src/generators/mutationGenerator.test.tsx index aa0e1858b..61fb041cb 100644 --- a/packages/plugin-vue-query/src/generators/mutationGenerator.test.tsx +++ b/packages/plugin-vue-query/src/generators/mutationGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginVueQuery } from '../types.ts' diff --git a/packages/plugin-vue-query/src/generators/queryGenerator.test.tsx b/packages/plugin-vue-query/src/generators/queryGenerator.test.tsx index 87c9f759e..3acfda36f 100644 --- a/packages/plugin-vue-query/src/generators/queryGenerator.test.tsx +++ b/packages/plugin-vue-query/src/generators/queryGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles } from '@kubb/core/mocks' import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import { MutationKey, QueryKey } from '../components' import type { PluginVueQuery } from '../types.ts' diff --git a/packages/plugin-zod/package.json b/packages/plugin-zod/package.json index 43775405d..f43ebd337 100644 --- a/packages/plugin-zod/package.json +++ b/packages/plugin-zod/package.json @@ -35,6 +35,11 @@ "require": "./dist/components.cjs", "default": "./dist/components.cjs" }, + "./utils": { + "import": "./dist/utils.js", + "require": "./dist/utils.cjs", + "default": "./dist/utils.cjs" + }, "./package.json": "./package.json", "./*": "./*" }, @@ -48,6 +53,9 @@ ], "generators": [ "./dist/generators.d.ts" + ], + "utils": [ + "./dist/utils.d.ts" ] } }, @@ -80,6 +88,7 @@ "devDependencies": { "@kubb/config-ts": "workspace:*", "@kubb/config-tsup": "workspace:*", + "zod": "~3.24.1", "tsup": "^8.3.5" }, "peerDependencies": { diff --git a/packages/plugin-zod/src/parser/__snapshots__/index.test.ts.snap b/packages/plugin-zod/src/__snapshots__/parser.test.ts.snap similarity index 100% rename from packages/plugin-zod/src/parser/__snapshots__/index.test.ts.snap rename to packages/plugin-zod/src/__snapshots__/parser.test.ts.snap diff --git a/packages/plugin-zod/src/components/Zod.tsx b/packages/plugin-zod/src/components/Zod.tsx index b9c7e15c0..798f9d6e4 100644 --- a/packages/plugin-zod/src/components/Zod.tsx +++ b/packages/plugin-zod/src/components/Zod.tsx @@ -3,7 +3,7 @@ import { type Schema, schemaKeywords } from '@kubb/plugin-oas' import { isKeyword } from '@kubb/plugin-oas' import { Const, File, Type } from '@kubb/react' import type { KubbNode } from '@kubb/react/types' -import * as parserZod from '../parser/index.ts' +import * as parserZod from '../parser.ts' import type { PluginZod } from '../types.ts' type Props = { @@ -30,7 +30,7 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key return true }) .map((schema, _index, siblings) => - parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName: typeName, description, mapper, coercion }), + parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName, description, mapper, coercion }), ) .filter(Boolean) .join('') @@ -47,20 +47,23 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean), }} > - {[ - output, - keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined, - typeName ? ` as z.ZodType<${typeName}>` : '', - ] + {[output, keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined] .filter(Boolean) .join('') || 'z.undefined()'} {inferTypeName && ( - - {`z.infer`} - + {typeName && ( + + {typeName} + + )} + {!typeName && ( + + {`z.infer`} + + )} )} diff --git a/packages/plugin-zod/src/generators/__snapshots__/optionalPetTyped.ts b/packages/plugin-zod/src/generators/__snapshots__/optionalPetTyped.ts index 080aef09d..6877cf862 100644 --- a/packages/plugin-zod/src/generators/__snapshots__/optionalPetTyped.ts +++ b/packages/plugin-zod/src/generators/__snapshots__/optionalPetTyped.ts @@ -1,7 +1,8 @@ +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const optionalPet = z.object({ id: z.number().int().optional(), name: z.string().optional(), tag: z.string().optional(), -}) as z.ZodType +} satisfies ToZod) diff --git a/packages/plugin-zod/src/generators/__snapshots__/pets.ts b/packages/plugin-zod/src/generators/__snapshots__/pets.ts index 69fbc55c7..bdbd7a01e 100644 --- a/packages/plugin-zod/src/generators/__snapshots__/pets.ts +++ b/packages/plugin-zod/src/generators/__snapshots__/pets.ts @@ -1,3 +1,4 @@ +import type { ToZod } from '@kubb/plugin-zod/utils' import { z } from 'zod' export const pets = z.array( @@ -5,5 +6,5 @@ export const pets = z.array( id: z.number().int(), name: z.string(), tag: z.string().optional(), - }), -) as z.ZodType + } satisfies ToZod), +) diff --git a/packages/plugin-zod/src/generators/operationsGenerator.test.tsx b/packages/plugin-zod/src/generators/operationsGenerator.test.tsx index 72259091e..60b6c0bfb 100644 --- a/packages/plugin-zod/src/generators/operationsGenerator.test.tsx +++ b/packages/plugin-zod/src/generators/operationsGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles, mockedPluginManager } from '@kub import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator } from '@kubb/plugin-oas' import type { PluginZod } from '../types.ts' import { operationsGenerator } from './operationsGenerator.tsx' diff --git a/packages/plugin-zod/src/generators/zodGenerator.test.tsx b/packages/plugin-zod/src/generators/zodGenerator.test.tsx index 88bed4abd..57afc9d05 100644 --- a/packages/plugin-zod/src/generators/zodGenerator.test.tsx +++ b/packages/plugin-zod/src/generators/zodGenerator.test.tsx @@ -3,7 +3,7 @@ import { createMockedPluginManager, matchFiles, mockedPluginManager } from '@kub import path from 'node:path' import type { Plugin } from '@kubb/core' import type { HttpMethod } from '@kubb/oas' -import { parse } from '@kubb/oas/parser' +import { parse } from '@kubb/oas' import { OperationGenerator, SchemaGenerator } from '@kubb/plugin-oas' import { getSchemas } from '@kubb/plugin-oas/utils' import type { PluginZod } from '../types.ts' diff --git a/packages/plugin-zod/src/generators/zodGenerator.tsx b/packages/plugin-zod/src/generators/zodGenerator.tsx index 426d52eed..d7e8567dc 100644 --- a/packages/plugin-zod/src/generators/zodGenerator.tsx +++ b/packages/plugin-zod/src/generators/zodGenerator.tsx @@ -52,6 +52,7 @@ export const zodGenerator = createReactGenerator({ return ( {typed && } + {typed && } {imports.map((imp, index) => ( ))} @@ -103,6 +104,7 @@ export const zodGenerator = createReactGenerator({ {typed && } + {typed && } {imports.map((imp, index) => ( ))} diff --git a/packages/plugin-zod/src/parser/index.test.ts b/packages/plugin-zod/src/parser.test.ts similarity index 69% rename from packages/plugin-zod/src/parser/index.test.ts rename to packages/plugin-zod/src/parser.test.ts index 399051c37..c07bf73fa 100644 --- a/packages/plugin-zod/src/parser/index.test.ts +++ b/packages/plugin-zod/src/parser.test.ts @@ -1,6 +1,6 @@ -import { schemas } from '../../../plugin-oas/mocks/schemas.ts' +import { schemas } from '../../plugin-oas/mocks/schemas.ts' -import * as parserZod from './index.ts' +import * as parserZod from './parser.ts' describe('zod parse', () => { test.each(schemas.basic)('$name', ({ name, schema }) => { diff --git a/packages/plugin-zod/src/parser/index.ts b/packages/plugin-zod/src/parser.ts similarity index 97% rename from packages/plugin-zod/src/parser/index.ts rename to packages/plugin-zod/src/parser.ts index fd3dd929d..ea264706f 100644 --- a/packages/plugin-zod/src/parser/index.ts +++ b/packages/plugin-zod/src/parser.ts @@ -20,7 +20,12 @@ const zodKeywordMapper = { .filter(Boolean) .join('') }, - object: (value?: string) => { + object: (value?: string, typeName?: string) => { + if (typeName) { + return `z.object({ + ${value} + } satisfies ToZod<${typeName}>)` + } return `z.object({ ${value} })` @@ -93,7 +98,12 @@ const zodKeywordMapper = { uuid: (coercion?: boolean) => (coercion ? 'z.coerce.string().uuid()' : 'z.string().uuid()'), url: (coercion?: boolean) => (coercion ? 'z.coerce.string().url()' : 'z.string().url()'), strict: () => '.strict()', - default: (value?: string | number | true) => `.default(${value ?? ''})`, + default: (value?: string | number | true | object) => { + if (typeof value === 'object') { + return '.default({})' + } + return `.default(${value ?? ''})` + }, and: (items: string[] = []) => items?.map((item) => `.and(${item})`).join(''), describe: (value = '') => `.describe(${value})`, min: (value?: number) => `.min(${value ?? ''})`, @@ -289,7 +299,7 @@ export function parse({ parent, current, siblings }: SchemaTree, options: Parser : undefined const text = [ - zodKeywordMapper.object(properties), + zodKeywordMapper.object(properties, options.typeName), current.args?.strict ? zodKeywordMapper.strict() : undefined, additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : undefined, ].filter(Boolean) diff --git a/packages/plugin-zod/src/utils/ToZod.ts b/packages/plugin-zod/src/utils/ToZod.ts new file mode 100644 index 000000000..ffa9743d5 --- /dev/null +++ b/packages/plugin-zod/src/utils/ToZod.ts @@ -0,0 +1,69 @@ +import type { ZodArray, ZodDefault, ZodEffects, ZodNullable, ZodOptional, ZodType } from 'zod' + +type IsNullable = Extract extends never ? false : true +type IsOptional = Extract extends never ? false : true + +type ZodWithEffects = T | ZodType | ZodDefault> | ZodEffects, any, any> + +export type ToZod = T extends any[] + ? ZodArray> + : T extends Record // object + ? { + [K in keyof T]-?: T[K] extends any[] ? ZodArray> : ToZodSchemaPrimitive + } + : ZodWithEffects + +type ToZodSchemaPrimitive = IsNullable extends true + ? IsOptional extends true + ? + | ZodWithEffects, undefined>>>>> + | ZodWithEffects, undefined>>>>> + : ZodWithEffects>>> + : IsOptional extends true + ? ZodWithEffects>>> | ZodWithEffects>>> + : ZodWithEffects + +// type isAny = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false +// type nonoptional = T extends undefined ? never : T +// type nonnullable = T extends null ? never : T +// type equals = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false +// +// /** +// * See https://github.com/colinhacks/tozod/blob/master/src/index.ts +// * Adapted based on https://github.com/colinhacks/zod/issues/372 +// */ +// export type toZod = { +// any: z.ZodAny +// optional: z.ZodUnion<[toZod>, z.ZodUndefined]> +// nullable: z.ZodUnion<[toZod>, z.ZodNull]> +// array: T extends Array ? z.ZodArray> : never +// string: z.ZodString +// bigint: z.ZodBigInt +// number: z.ZodNumber +// boolean: z.ZodBoolean +// date: z.ZodDate +// object: z.ZodObject<{ [k in keyof T]: toZod }, 'strict', Extract> +// rest: never +// }[zodKey] +// +// type zodKey = isAny extends true +// ? 'any' +// : equals extends true //[T] extends [booleanUtil.Type] +// ? 'boolean' +// : [undefined] extends [T] +// ? 'optional' +// : [null] extends [T] +// ? 'nullable' +// : T extends any[] +// ? 'array' +// : equals extends true +// ? 'string' +// : equals extends true //[T] extends [bigintUtil.Type] +// ? 'bigint' +// : equals extends true //[T] extends [numberUtil.Type] +// ? 'number' +// : equals extends true //[T] extends [dateUtil.Type] +// ? 'date' +// : T extends { [k: string]: any } //[T] extends [structUtil.Type] +// ? 'object' +// : 'rest' diff --git a/packages/plugin-zod/src/utils/index.ts b/packages/plugin-zod/src/utils/index.ts new file mode 100644 index 000000000..e7d850960 --- /dev/null +++ b/packages/plugin-zod/src/utils/index.ts @@ -0,0 +1 @@ +export type { ToZod } from './ToZod.ts' diff --git a/packages/plugin-zod/tsup.config.ts b/packages/plugin-zod/tsup.config.ts index a2f128536..8a688a8e2 100644 --- a/packages/plugin-zod/tsup.config.ts +++ b/packages/plugin-zod/tsup.config.ts @@ -8,6 +8,7 @@ export default defineConfig([ entry: { index: 'src/index.ts', components: 'src/components/index.ts', + utils: 'src/utils/index.ts', generators: 'src/generators/index.ts', }, }, @@ -16,6 +17,7 @@ export default defineConfig([ entry: { index: 'src/index.ts', components: 'src/components/index.ts', + utils: 'src/utils/index.ts', generators: 'src/generators/index.ts', }, }, diff --git a/packages/react/src/components/Const.tsx b/packages/react/src/components/Const.tsx index a9a1376f2..e851e9129 100644 --- a/packages/react/src/components/Const.tsx +++ b/packages/react/src/components/Const.tsx @@ -13,6 +13,10 @@ type Props = { * Does this type need to be exported. */ export?: boolean + /** + * Type to make the const being typed + */ + type?: string /** * Options for JSdocs. */ @@ -24,7 +28,7 @@ type Props = { children?: KubbNode } -export function Const({ name, export: canExport, JSDoc, asConst, children }: Props): KubbNode { +export function Const({ name, export: canExport, type, JSDoc, asConst, children }: Props): KubbNode { return ( <> {JSDoc?.comments && ( @@ -40,7 +44,18 @@ export function Const({ name, export: canExport, JSDoc, asConst, children }: Pro )} - const {name} = + const {name} + + + {type && ( + <> + {':'} + {type} + + + )} + + = {children} diff --git a/packages/unplugin-kubb/CHANGELOG.md b/packages/unplugin-kubb/CHANGELOG.md index 70378c84c..7336dc74e 100644 --- a/packages/unplugin-kubb/CHANGELOG.md +++ b/packages/unplugin-kubb/CHANGELOG.md @@ -4,7 +4,7 @@ ### Major Changes -- [`c0563e3`](https://github.com/kubb-labs/kubb/commit/c0563e37cee434579546bd1293e8f1eb2be802cd) Thanks [@stijnvanhulle](https://github.com/stijnvanhulle)! - Support for Vite 6 and drop support for Webpack 4 +- [`c0563e3`](https://github.com/kubb-labs/kubb/commit/c0563e37cee434579546bd1293e8f1eb2be802cd) Thanks [@stijnvanhulle](https://github.com/stijnvanhulle)! - Support for Vite 6 and drop support for webpack 4 ## 1.0.6 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0310fb265..2b73c7dfa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -224,6 +224,9 @@ importers: swr: specifier: ^2.2.5 version: 2.2.5(react@18.3.1) + tozod: + specifier: ^3.0.0 + version: 3.0.0(zod@3.24.1) tsup: specifier: 'catalog:' version: 8.3.5(@microsoft/api-extractor@7.48.0(@types/node@20.17.10))(@swc/core@1.7.22)(jiti@2.4.1)(postcss@8.4.49)(typescript@5.7.2)(yaml@2.5.1) @@ -318,6 +321,9 @@ importers: swr: specifier: ^2.2.5 version: 2.2.5(react@18.3.1) + tozod: + specifier: ^3.0.0 + version: 3.0.0(zod@3.24.1) vue: specifier: ^3.5.13 version: 3.5.13(typescript@5.7.2) @@ -659,6 +665,9 @@ importers: react: specifier: ^18.3.1 version: 18.3.1 + tozod: + specifier: ^3.0.0 + version: 3.0.0(zod@3.24.1) tsup: specifier: ^8.3.5 version: 8.3.5(@microsoft/api-extractor@7.48.0(@types/node@20.17.10))(@swc/core@1.7.22)(jiti@2.4.1)(postcss@8.4.49)(typescript@5.7.2)(yaml@2.5.1) @@ -1014,8 +1023,8 @@ importers: specifier: ^7.0.0 version: 7.0.0 natural-orderby: - specifier: ^4.0.0 - version: 4.0.0 + specifier: ^5.0.0 + version: 5.0.0 object-hash: specifier: ^3.0.0 version: 3.0.0 @@ -1082,7 +1091,7 @@ importers: specifier: ^11.0.4 version: 11.0.4 tsup: - specifier: ^8.3.5 + specifier: 'catalog:' version: 8.3.5(@microsoft/api-extractor@7.48.0(@types/node@20.17.10))(@swc/core@1.7.22)(jiti@2.4.1)(postcss@8.4.49)(typescript@5.7.2)(yaml@2.5.1) packages/kubb: @@ -1156,8 +1165,8 @@ importers: specifier: ^7.0.4 version: 7.0.4 expect-type: - specifier: ^0.20.0 - version: 0.20.0 + specifier: ^1.1.0 + version: 1.1.0 tsup: specifier: 'catalog:' version: 8.3.5(@microsoft/api-extractor@7.48.0(@types/node@20.17.10))(@swc/core@1.7.22)(jiti@2.4.1)(postcss@8.4.49)(typescript@5.7.2)(yaml@2.5.1) @@ -1702,6 +1711,9 @@ importers: tsup: specifier: ^8.3.5 version: 8.3.5(@microsoft/api-extractor@7.48.0(@types/node@20.17.10))(@swc/core@1.7.22)(jiti@2.4.1)(postcss@8.4.49)(typescript@5.7.2)(yaml@2.5.1) + zod: + specifier: ~3.24.1 + version: 3.24.1 packages/react: dependencies: @@ -2921,11 +2933,6 @@ packages: rollup: optional: true - '@rollup/rollup-android-arm-eabi@4.24.2': - resolution: {integrity: sha512-ufoveNTKDg9t/b7nqI3lwbCG/9IJMhADBNjjz/Jn6LxIZxD7T5L8l2uO/wD99945F1Oo8FvgbbZJRguyk/BdzA==} - cpu: [arm] - os: [android] - '@rollup/rollup-android-arm-eabi@4.25.0': resolution: {integrity: sha512-CC/ZqFZwlAIbU1wUPisHyV/XRc5RydFrNLtgl3dGYskdwPZdt4HERtKm50a/+DtTlKeCq9IXFEWR+P6blwjqBA==} cpu: [arm] @@ -2936,11 +2943,6 @@ packages: cpu: [arm] os: [android] - '@rollup/rollup-android-arm64@4.24.2': - resolution: {integrity: sha512-iZoYCiJz3Uek4NI0J06/ZxUgwAfNzqltK0MptPDO4OR0a88R4h0DSELMsflS6ibMCJ4PnLvq8f7O1d7WexUvIA==} - cpu: [arm64] - os: [android] - '@rollup/rollup-android-arm64@4.25.0': resolution: {integrity: sha512-/Y76tmLGUJqVBXXCfVS8Q8FJqYGhgH4wl4qTA24E9v/IJM0XvJCGQVSW1QZ4J+VURO9h8YCa28sTFacZXwK7Rg==} cpu: [arm64] @@ -2951,11 +2953,6 @@ packages: cpu: [arm64] os: [android] - '@rollup/rollup-darwin-arm64@4.24.2': - resolution: {integrity: sha512-/UhrIxobHYCBfhi5paTkUDQ0w+jckjRZDZ1kcBL132WeHZQ6+S5v9jQPVGLVrLbNUebdIRpIt00lQ+4Z7ys4Rg==} - cpu: [arm64] - os: [darwin] - '@rollup/rollup-darwin-arm64@4.25.0': resolution: {integrity: sha512-YVT6L3UrKTlC0FpCZd0MGA7NVdp7YNaEqkENbWQ7AOVOqd/7VzyHpgIpc1mIaxRAo1ZsJRH45fq8j4N63I/vvg==} cpu: [arm64] @@ -2966,11 +2963,6 @@ packages: cpu: [arm64] os: [darwin] - '@rollup/rollup-darwin-x64@4.24.2': - resolution: {integrity: sha512-1F/jrfhxJtWILusgx63WeTvGTwE4vmsT9+e/z7cZLKU8sBMddwqw3UV5ERfOV+H1FuRK3YREZ46J4Gy0aP3qDA==} - cpu: [x64] - os: [darwin] - '@rollup/rollup-darwin-x64@4.25.0': resolution: {integrity: sha512-ZRL+gexs3+ZmmWmGKEU43Bdn67kWnMeWXLFhcVv5Un8FQcx38yulHBA7XR2+KQdYIOtD0yZDWBCudmfj6lQJoA==} cpu: [x64] @@ -2981,11 +2973,6 @@ packages: cpu: [x64] os: [darwin] - '@rollup/rollup-freebsd-arm64@4.24.2': - resolution: {integrity: sha512-1YWOpFcGuC6iGAS4EI+o3BV2/6S0H+m9kFOIlyFtp4xIX5rjSnL3AwbTBxROX0c8yWtiWM7ZI6mEPTI7VkSpZw==} - cpu: [arm64] - os: [freebsd] - '@rollup/rollup-freebsd-arm64@4.25.0': resolution: {integrity: sha512-xpEIXhiP27EAylEpreCozozsxWQ2TJbOLSivGfXhU4G1TBVEYtUPi2pOZBnvGXHyOdLAUUhPnJzH3ah5cqF01g==} cpu: [arm64] @@ -2996,11 +2983,6 @@ packages: cpu: [arm64] os: [freebsd] - '@rollup/rollup-freebsd-x64@4.24.2': - resolution: {integrity: sha512-3qAqTewYrCdnOD9Gl9yvPoAoFAVmPJsBvleabvx4bnu1Kt6DrB2OALeRVag7BdWGWLhP1yooeMLEi6r2nYSOjg==} - cpu: [x64] - os: [freebsd] - '@rollup/rollup-freebsd-x64@4.25.0': resolution: {integrity: sha512-sC5FsmZGlJv5dOcURrsnIK7ngc3Kirnx3as2XU9uER+zjfyqIjdcMVgzy4cOawhsssqzoAX19qmxgJ8a14Qrqw==} cpu: [x64] @@ -3011,11 +2993,6 @@ packages: cpu: [x64] os: [freebsd] - '@rollup/rollup-linux-arm-gnueabihf@4.24.2': - resolution: {integrity: sha512-ArdGtPHjLqWkqQuoVQ6a5UC5ebdX8INPuJuJNWRe0RGa/YNhVvxeWmCTFQ7LdmNCSUzVZzxAvUznKaYx645Rig==} - cpu: [arm] - os: [linux] - '@rollup/rollup-linux-arm-gnueabihf@4.25.0': resolution: {integrity: sha512-uD/dbLSs1BEPzg564TpRAQ/YvTnCds2XxyOndAO8nJhaQcqQGFgv/DAVko/ZHap3boCvxnzYMa3mTkV/B/3SWA==} cpu: [arm] @@ -3026,11 +3003,6 @@ packages: cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm-musleabihf@4.24.2': - resolution: {integrity: sha512-B6UHHeNnnih8xH6wRKB0mOcJGvjZTww1FV59HqJoTJ5da9LCG6R4SEBt6uPqzlawv1LoEXSS0d4fBlHNWl6iYw==} - cpu: [arm] - os: [linux] - '@rollup/rollup-linux-arm-musleabihf@4.25.0': resolution: {integrity: sha512-ZVt/XkrDlQWegDWrwyC3l0OfAF7yeJUF4fq5RMS07YM72BlSfn2fQQ6lPyBNjt+YbczMguPiJoCfaQC2dnflpQ==} cpu: [arm] @@ -3041,11 +3013,6 @@ packages: cpu: [arm] os: [linux] - '@rollup/rollup-linux-arm64-gnu@4.24.2': - resolution: {integrity: sha512-kr3gqzczJjSAncwOS6i7fpb4dlqcvLidqrX5hpGBIM1wtt0QEVtf4wFaAwVv8QygFU8iWUMYEoJZWuWxyua4GQ==} - cpu: [arm64] - os: [linux] - '@rollup/rollup-linux-arm64-gnu@4.25.0': resolution: {integrity: sha512-qboZ+T0gHAW2kkSDPHxu7quaFaaBlynODXpBVnPxUgvWYaE84xgCKAPEYE+fSMd3Zv5PyFZR+L0tCdYCMAtG0A==} cpu: [arm64] @@ -3056,11 +3023,6 @@ packages: cpu: [arm64] os: [linux] - '@rollup/rollup-linux-arm64-musl@4.24.2': - resolution: {integrity: sha512-TDdHLKCWgPuq9vQcmyLrhg/bgbOvIQ8rtWQK7MRxJ9nvaxKx38NvY7/Lo6cYuEnNHqf6rMqnivOIPIQt6H2AoA==} - cpu: [arm64] - os: [linux] - '@rollup/rollup-linux-arm64-musl@4.25.0': resolution: {integrity: sha512-ndWTSEmAaKr88dBuogGH2NZaxe7u2rDoArsejNslugHZ+r44NfWiwjzizVS1nUOHo+n1Z6qV3X60rqE/HlISgw==} cpu: [arm64] @@ -3076,11 +3038,6 @@ packages: cpu: [loong64] os: [linux] - '@rollup/rollup-linux-powerpc64le-gnu@4.24.2': - resolution: {integrity: sha512-xv9vS648T3X4AxFFZGWeB5Dou8ilsv4VVqJ0+loOIgDO20zIhYfDLkk5xoQiej2RiSQkld9ijF/fhLeonrz2mw==} - cpu: [ppc64] - os: [linux] - '@rollup/rollup-linux-powerpc64le-gnu@4.25.0': resolution: {integrity: sha512-BVSQvVa2v5hKwJSy6X7W1fjDex6yZnNKy3Kx1JGimccHft6HV0THTwNtC2zawtNXKUu+S5CjXslilYdKBAadzA==} cpu: [ppc64] @@ -3091,11 +3048,6 @@ packages: cpu: [ppc64] os: [linux] - '@rollup/rollup-linux-riscv64-gnu@4.24.2': - resolution: {integrity: sha512-tbtXwnofRoTt223WUZYiUnbxhGAOVul/3StZ947U4A5NNjnQJV5irKMm76G0LGItWs6y+SCjUn/Q0WaMLkEskg==} - cpu: [riscv64] - os: [linux] - '@rollup/rollup-linux-riscv64-gnu@4.25.0': resolution: {integrity: sha512-G4hTREQrIdeV0PE2JruzI+vXdRnaK1pg64hemHq2v5fhv8C7WjVaeXc9P5i4Q5UC06d/L+zA0mszYIKl+wY8oA==} cpu: [riscv64] @@ -3106,11 +3058,6 @@ packages: cpu: [riscv64] os: [linux] - '@rollup/rollup-linux-s390x-gnu@4.24.2': - resolution: {integrity: sha512-gc97UebApwdsSNT3q79glOSPdfwgwj5ELuiyuiMY3pEWMxeVqLGKfpDFoum4ujivzxn6veUPzkGuSYoh5deQ2Q==} - cpu: [s390x] - os: [linux] - '@rollup/rollup-linux-s390x-gnu@4.25.0': resolution: {integrity: sha512-9T/w0kQ+upxdkFL9zPVB6zy9vWW1deA3g8IauJxojN4bnz5FwSsUAD034KpXIVX5j5p/rn6XqumBMxfRkcHapQ==} cpu: [s390x] @@ -3121,11 +3068,6 @@ packages: cpu: [s390x] os: [linux] - '@rollup/rollup-linux-x64-gnu@4.24.2': - resolution: {integrity: sha512-jOG/0nXb3z+EM6SioY8RofqqmZ+9NKYvJ6QQaa9Mvd3RQxlH68/jcB/lpyVt4lCiqr04IyaC34NzhUqcXbB5FQ==} - cpu: [x64] - os: [linux] - '@rollup/rollup-linux-x64-gnu@4.25.0': resolution: {integrity: sha512-ThcnU0EcMDn+J4B9LD++OgBYxZusuA7iemIIiz5yzEcFg04VZFzdFjuwPdlURmYPZw+fgVrFzj4CA64jSTG4Ig==} cpu: [x64] @@ -3136,11 +3078,6 @@ packages: cpu: [x64] os: [linux] - '@rollup/rollup-linux-x64-musl@4.24.2': - resolution: {integrity: sha512-XAo7cJec80NWx9LlZFEJQxqKOMz/lX3geWs2iNT5CHIERLFfd90f3RYLLjiCBm1IMaQ4VOX/lTC9lWfzzQm14Q==} - cpu: [x64] - os: [linux] - '@rollup/rollup-linux-x64-musl@4.25.0': resolution: {integrity: sha512-zx71aY2oQxGxAT1JShfhNG79PnjYhMC6voAjzpu/xmMjDnKNf6Nl/xv7YaB/9SIa9jDYf8RBPWEnjcdlhlv1rQ==} cpu: [x64] @@ -3151,11 +3088,6 @@ packages: cpu: [x64] os: [linux] - '@rollup/rollup-win32-arm64-msvc@4.24.2': - resolution: {integrity: sha512-A+JAs4+EhsTjnPQvo9XY/DC0ztaws3vfqzrMNMKlwQXuniBKOIIvAAI8M0fBYiTCxQnElYu7mLk7JrhlQ+HeOw==} - cpu: [arm64] - os: [win32] - '@rollup/rollup-win32-arm64-msvc@4.25.0': resolution: {integrity: sha512-JT8tcjNocMs4CylWY/CxVLnv8e1lE7ff1fi6kbGocWwxDq9pj30IJ28Peb+Y8yiPNSF28oad42ApJB8oUkwGww==} cpu: [arm64] @@ -3166,11 +3098,6 @@ packages: cpu: [arm64] os: [win32] - '@rollup/rollup-win32-ia32-msvc@4.24.2': - resolution: {integrity: sha512-ZhcrakbqA1SCiJRMKSU64AZcYzlZ/9M5LaYil9QWxx9vLnkQ9Vnkve17Qn4SjlipqIIBFKjBES6Zxhnvh0EAEw==} - cpu: [ia32] - os: [win32] - '@rollup/rollup-win32-ia32-msvc@4.25.0': resolution: {integrity: sha512-dRLjLsO3dNOfSN6tjyVlG+Msm4IiZnGkuZ7G5NmpzwF9oOc582FZG05+UdfTbz5Jd4buK/wMb6UeHFhG18+OEg==} cpu: [ia32] @@ -3181,11 +3108,6 @@ packages: cpu: [ia32] os: [win32] - '@rollup/rollup-win32-x64-msvc@4.24.2': - resolution: {integrity: sha512-2mLH46K1u3r6uwc95hU+OR9q/ggYMpnS7pSp83Ece1HUQgF9Nh/QwTK5rcgbFnV9j+08yBrU5sA/P0RK2MSBNA==} - cpu: [x64] - os: [win32] - '@rollup/rollup-win32-x64-msvc@4.25.0': resolution: {integrity: sha512-/RqrIFtLB926frMhZD0a5oDa4eFIbyNEwLLloMTEjmqfwZWXywwVVOVmwTsuyhC9HKkVEZcOOi+KV4U9wmOdlg==} cpu: [x64] @@ -5029,10 +4951,6 @@ packages: resolution: {integrity: sha512-EHlpxMCpHWSAh1dgS6bVeoLAXGnJNdR93aabr4QCGbzOM73o5XmRfM/e5FUqsw3aagP8S8XEWUWFAxnRBnAF0Q==} engines: {node: ^18.19.0 || >=20.5.0} - expect-type@0.20.0: - resolution: {integrity: sha512-uHaC9LYNv6BcW+8SvXcwUUDCrrUxt3GSa61DFvTHj8JC+M0hekMFBwMlCarLQDk5bbpZ2vStpnQPIwRuV98YMw==} - engines: {node: '>=12.0.0'} - expect-type@1.1.0: resolution: {integrity: sha512-bFi65yM+xZgk+u/KRIpekdSYkTB5W1pEf0Lt8Q8Msh7b+eQ7LXVtIB1Bkm4fvclDEL1b2CZkMhv2mOeF8tMdkA==} engines: {node: '>=12.0.0'} @@ -5768,10 +5686,6 @@ packages: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} engines: {node: '>=6'} - lilconfig@3.1.2: - resolution: {integrity: sha512-eop+wDAvpItUys0FWkHIKeC9ybYrTGbU41U5K7+bttZZeohvnY7M9dZ5kB21GNWiFT2q1OoPTvncPCgSOVO5ow==} - engines: {node: '>=14'} - lilconfig@3.1.3: resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==} engines: {node: '>=14'} @@ -6194,6 +6108,10 @@ packages: resolution: {integrity: sha512-IKbGiBbsEis4F0JuAoERsLwVwVwExW20e7vwo0G4n00cWOIuHRwjv7dONoXKW1PfxRnWxwywmg1FA5ivyv170g==} engines: {node: '>=18'} + natural-orderby@5.0.0: + resolution: {integrity: sha512-kKHJhxwpR/Okycz4HhQKKlhWe4ASEfPgkSWNmKFHd7+ezuQlxkA5cM3+XkBPvm1gmHen3w53qsYAv+8GwRrBlg==} + engines: {node: '>=18'} + nearley@2.20.1: resolution: {integrity: sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==} hasBin: true @@ -6923,11 +6841,6 @@ packages: robust-predicates@3.0.2: resolution: {integrity: sha512-IXgzBWvWQwE6PrDI05OvmXUIruQTcoMDzRsOd5CDvHCVLcLHMTSYvOK5Cm46kWqlV3yAbuSpBZdJ5oP5OUoStg==} - rollup@4.24.2: - resolution: {integrity: sha512-do/DFGq5g6rdDhdpPq5qb2ecoczeK6y+2UAjdJ5trjQJj5f1AiVdLRWRc9A9/fFukfvJRgM0UXzxBIYMovm5ww==} - engines: {node: '>=18.0.0', npm: '>=8.0.0'} - hasBin: true - rollup@4.25.0: resolution: {integrity: sha512-uVbClXmR6wvx5R1M3Od4utyLUxrmOcEm3pAtMphn73Apq19PDtHpgZoEvqH2YnnaNUuvKmg2DgRd2Sqv+odyqg==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} @@ -7421,6 +7334,11 @@ packages: resolution: {integrity: sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag==} engines: {node: '>=6'} + tozod@3.0.0: + resolution: {integrity: sha512-R03/moNPEGgWKoTdCsEJuyEoP6NtXyhWg9L9lJhF2XyCR2Ce9XE+yXaswaVmqyBpHsRPC2Pk38mK8Ex7iHaXcg==} + peerDependencies: + zod: ^3.0.0-alpha.2 + tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} @@ -9331,90 +9249,60 @@ snapshots: optionalDependencies: rollup: 4.28.1 - '@rollup/rollup-android-arm-eabi@4.24.2': - optional: true - '@rollup/rollup-android-arm-eabi@4.25.0': optional: true '@rollup/rollup-android-arm-eabi@4.28.1': optional: true - '@rollup/rollup-android-arm64@4.24.2': - optional: true - '@rollup/rollup-android-arm64@4.25.0': optional: true '@rollup/rollup-android-arm64@4.28.1': optional: true - '@rollup/rollup-darwin-arm64@4.24.2': - optional: true - '@rollup/rollup-darwin-arm64@4.25.0': optional: true '@rollup/rollup-darwin-arm64@4.28.1': optional: true - '@rollup/rollup-darwin-x64@4.24.2': - optional: true - '@rollup/rollup-darwin-x64@4.25.0': optional: true '@rollup/rollup-darwin-x64@4.28.1': optional: true - '@rollup/rollup-freebsd-arm64@4.24.2': - optional: true - '@rollup/rollup-freebsd-arm64@4.25.0': optional: true '@rollup/rollup-freebsd-arm64@4.28.1': optional: true - '@rollup/rollup-freebsd-x64@4.24.2': - optional: true - '@rollup/rollup-freebsd-x64@4.25.0': optional: true '@rollup/rollup-freebsd-x64@4.28.1': optional: true - '@rollup/rollup-linux-arm-gnueabihf@4.24.2': - optional: true - '@rollup/rollup-linux-arm-gnueabihf@4.25.0': optional: true '@rollup/rollup-linux-arm-gnueabihf@4.28.1': optional: true - '@rollup/rollup-linux-arm-musleabihf@4.24.2': - optional: true - '@rollup/rollup-linux-arm-musleabihf@4.25.0': optional: true '@rollup/rollup-linux-arm-musleabihf@4.28.1': optional: true - '@rollup/rollup-linux-arm64-gnu@4.24.2': - optional: true - '@rollup/rollup-linux-arm64-gnu@4.25.0': optional: true '@rollup/rollup-linux-arm64-gnu@4.28.1': optional: true - '@rollup/rollup-linux-arm64-musl@4.24.2': - optional: true - '@rollup/rollup-linux-arm64-musl@4.25.0': optional: true @@ -9424,72 +9312,48 @@ snapshots: '@rollup/rollup-linux-loongarch64-gnu@4.28.1': optional: true - '@rollup/rollup-linux-powerpc64le-gnu@4.24.2': - optional: true - '@rollup/rollup-linux-powerpc64le-gnu@4.25.0': optional: true '@rollup/rollup-linux-powerpc64le-gnu@4.28.1': optional: true - '@rollup/rollup-linux-riscv64-gnu@4.24.2': - optional: true - '@rollup/rollup-linux-riscv64-gnu@4.25.0': optional: true '@rollup/rollup-linux-riscv64-gnu@4.28.1': optional: true - '@rollup/rollup-linux-s390x-gnu@4.24.2': - optional: true - '@rollup/rollup-linux-s390x-gnu@4.25.0': optional: true '@rollup/rollup-linux-s390x-gnu@4.28.1': optional: true - '@rollup/rollup-linux-x64-gnu@4.24.2': - optional: true - '@rollup/rollup-linux-x64-gnu@4.25.0': optional: true '@rollup/rollup-linux-x64-gnu@4.28.1': optional: true - '@rollup/rollup-linux-x64-musl@4.24.2': - optional: true - '@rollup/rollup-linux-x64-musl@4.25.0': optional: true '@rollup/rollup-linux-x64-musl@4.28.1': optional: true - '@rollup/rollup-win32-arm64-msvc@4.24.2': - optional: true - '@rollup/rollup-win32-arm64-msvc@4.25.0': optional: true '@rollup/rollup-win32-arm64-msvc@4.28.1': optional: true - '@rollup/rollup-win32-ia32-msvc@4.24.2': - optional: true - '@rollup/rollup-win32-ia32-msvc@4.25.0': optional: true '@rollup/rollup-win32-ia32-msvc@4.28.1': optional: true - '@rollup/rollup-win32-x64-msvc@4.24.2': - optional: true - '@rollup/rollup-win32-x64-msvc@4.25.0': optional: true @@ -11698,8 +11562,6 @@ snapshots: strip-final-newline: 4.0.0 yoctocolors: 2.1.1 - expect-type@0.20.0: {} - expect-type@1.1.0: {} express@4.19.2: @@ -12465,8 +12327,6 @@ snapshots: leven@3.1.0: {} - lilconfig@3.1.2: {} - lilconfig@3.1.3: {} lines-and-columns@1.2.4: {} @@ -13058,6 +12918,8 @@ snapshots: natural-orderby@4.0.0: {} + natural-orderby@5.0.0: {} + nearley@2.20.1: dependencies: commander: 2.20.3 @@ -13472,7 +13334,7 @@ snapshots: postcss-load-config@6.0.1(jiti@2.4.1)(postcss@8.4.49)(yaml@2.5.1): dependencies: - lilconfig: 3.1.2 + lilconfig: 3.1.3 optionalDependencies: jiti: 2.4.1 postcss: 8.4.49 @@ -13832,30 +13694,6 @@ snapshots: robust-predicates@3.0.2: {} - rollup@4.24.2: - dependencies: - '@types/estree': 1.0.6 - optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.24.2 - '@rollup/rollup-android-arm64': 4.24.2 - '@rollup/rollup-darwin-arm64': 4.24.2 - '@rollup/rollup-darwin-x64': 4.24.2 - '@rollup/rollup-freebsd-arm64': 4.24.2 - '@rollup/rollup-freebsd-x64': 4.24.2 - '@rollup/rollup-linux-arm-gnueabihf': 4.24.2 - '@rollup/rollup-linux-arm-musleabihf': 4.24.2 - '@rollup/rollup-linux-arm64-gnu': 4.24.2 - '@rollup/rollup-linux-arm64-musl': 4.24.2 - '@rollup/rollup-linux-powerpc64le-gnu': 4.24.2 - '@rollup/rollup-linux-riscv64-gnu': 4.24.2 - '@rollup/rollup-linux-s390x-gnu': 4.24.2 - '@rollup/rollup-linux-x64-gnu': 4.24.2 - '@rollup/rollup-linux-x64-musl': 4.24.2 - '@rollup/rollup-win32-arm64-msvc': 4.24.2 - '@rollup/rollup-win32-ia32-msvc': 4.24.2 - '@rollup/rollup-win32-x64-msvc': 4.24.2 - fsevents: 2.3.3 - rollup@4.25.0: dependencies: '@types/estree': 1.0.6 @@ -14470,6 +14308,10 @@ snapshots: universalify: 0.2.0 url-parse: 1.5.10 + tozod@3.0.0(zod@3.24.1): + dependencies: + zod: 3.24.1 + tr46@0.0.3: {} tr46@1.0.1: @@ -14530,7 +14372,7 @@ snapshots: picocolors: 1.1.1 postcss-load-config: 6.0.1(jiti@2.4.1)(postcss@8.4.49)(yaml@2.5.1) resolve-from: 5.0.0 - rollup: 4.24.2 + rollup: 4.28.1 source-map: 0.8.0-beta.0 sucrase: 3.35.0 tinyexec: 0.3.1 @@ -14559,7 +14401,7 @@ snapshots: picocolors: 1.1.1 postcss-load-config: 6.0.1(jiti@2.4.1)(postcss@8.4.49)(yaml@2.5.1) resolve-from: 5.0.0 - rollup: 4.24.2 + rollup: 4.28.1 source-map: 0.8.0-beta.0 sucrase: 3.35.0 tinyexec: 0.3.1 diff --git a/tsconfig.json b/tsconfig.json index f97aee6a3..9ecc82305 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,6 +28,7 @@ "@kubb/plugin-vue-query": ["packages/plugin-vue-query/src/index.ts"], "@kubb/plugin-redoc": ["packages/plugin-redoc/src/index.ts"], "@kubb/plugin-faker": ["packages/plugin-faker/src/index.ts"], + "@kubb/plugin-zod/utils": ["packages/plugin-zod/src/utils/index.ts"], "@kubb/plugin-zod": ["packages/plugin-zod/src/index.ts"], "@kubb/react": ["packages/react/src/index.ts"], "@kubb/react/types": ["packages/react/src/types.ts"], @@ -35,7 +36,6 @@ "@kubb/parser-ts/factory": ["packages/parser-ts/src/factory.ts"], "@kubb/parser-ts": ["packages/parser-ts/src/index.ts"], "@kubb/oas": ["packages/oas/src/index.ts"], - "@kubb/oas/parser": ["packages/oas/src/parser/index.ts"], "@kubb/config-tsup": ["packages/config-tsup/src/index.ts"], "unplugin-kubb": ["packages/unplugin/src/index.ts"] }