From f20ce50b8338deef6ed0a577e1dcf1630556ee00 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Sun, 21 Jan 2024 18:50:20 +0100 Subject: [PATCH 1/4] feat: Allow to use unknown instead of any --- .changeset/short-fireants-collect.md | 7 + docs/plugins/swagger-faker/index.md | 82 ++++++- docs/plugins/swagger-ts/index.md | 74 ++++++ docs/plugins/swagger-zod/index.md | 71 ++++++ packages/parser/src/factory.ts | 1 + .../swagger-faker/src/FakerGenerator.test.ts | 1 + packages/swagger-faker/src/FakerGenerator.ts | 20 +- .../src/OperationGenerator.test.tsx | 30 +++ .../OperationGenerator.test.tsx.snap | 40 ++++ .../__snapshots__/Mutation.test.tsx.snap | 4 +- packages/swagger-faker/src/fakerParser.ts | 5 +- packages/swagger-faker/src/plugin.ts | 14 +- packages/swagger-faker/src/types.ts | 6 + .../src/OperationGenerator.test.tsx | 59 +++++ packages/swagger-ts/src/TypeGenerator.test.ts | 18 ++ packages/swagger-ts/src/TypeGenerator.ts | 22 +- .../OperationGenerator.test.tsx.snap | 68 +++++- packages/swagger-ts/src/plugin.ts | 2 + packages/swagger-ts/src/types.ts | 6 + .../src/OperationGenerator.test.tsx | 135 +++++++++++ packages/swagger-zod/src/ZodGenerator.test.ts | 8 + packages/swagger-zod/src/ZodGenerator.ts | 19 +- .../OperationGenerator.test.tsx.snap | 221 ++++++++++++++++++ .../__snapshots__/Mutation.test.tsx.snap | 4 +- packages/swagger-zod/src/plugin.ts | 4 +- packages/swagger-zod/src/types.ts | 6 + packages/swagger-zod/src/zodParser.ts | 5 +- 27 files changed, 892 insertions(+), 40 deletions(-) create mode 100644 .changeset/short-fireants-collect.md create mode 100644 packages/swagger-zod/src/OperationGenerator.test.tsx create mode 100644 packages/swagger-zod/src/__snapshots__/OperationGenerator.test.tsx.snap diff --git a/.changeset/short-fireants-collect.md b/.changeset/short-fireants-collect.md new file mode 100644 index 000000000..1e0d63d3a --- /dev/null +++ b/.changeset/short-fireants-collect.md @@ -0,0 +1,7 @@ +--- +"@kubb/swagger-faker": minor +"@kubb/swagger-zod": minor +"@kubb/swagger-ts": minor +--- + +Allow to use unknown instead of any diff --git a/docs/plugins/swagger-faker/index.md b/docs/plugins/swagger-faker/index.md index 67b5d4241..e9b5a8a5c 100644 --- a/docs/plugins/swagger-faker/index.md +++ b/docs/plugins/swagger-faker/index.md @@ -448,11 +448,11 @@ Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`. ::: code-group ```typescript ['string'] -date: string +faker.string.alpha ``` ```typescript ['date'] -date: Date +faker.date.anytime() ``` ::: @@ -517,6 +517,84 @@ export default defineConfig({ ::: +### unknownType + +Which type to use when the Swagger/OpenAPI file is not providing more information. + +::: info type + +::: code-group + +```typescript ['any'] +any +``` + +```typescript ['unknown'] +unknown +``` + +::: + +::: info +Type: `'any' | 'unknown'`
+Default: `'any'` + +::: + +::: code-group + +```typescript ['any'] +import { defineConfig } from '@kubb/core' +import createSwagger from '@kubb/swagger' +import createSwaggerFaker from '@kubb/swagger-faker' +import createSwaggerTS from '@kubb/swagger-ts' + +export default defineConfig({ + input: { + path: './petStore.yaml', + }, + output: { + path: './src/gen', + }, + plugins: [ + createSwagger({ output: false }), + createSwaggerTS({}), + createSwaggerFaker( + { + unknownType: 'any', + }, + ), + ], +}) +``` + +```typescript ['unknown'] +import { defineConfig } from '@kubb/core' +import createSwagger from '@kubb/swagger' +import createSwaggerFaker from '@kubb/swagger-faker' +import createSwaggerTS from '@kubb/swagger-ts' + +export default defineConfig({ + input: { + path: './petStore.yaml', + }, + output: { + path: './src/gen', + }, + plugins: [ + createSwagger({ output: false }), + createSwaggerTS({}), + createSwaggerFaker( + { + unknownType: 'unknown', + }, + ), + ], +}) +``` + +::: + ### seed The use of Seed is intended to allow for consistent values in a test. diff --git a/docs/plugins/swagger-ts/index.md b/docs/plugins/swagger-ts/index.md index 5555e6f8a..fa2d95640 100644 --- a/docs/plugins/swagger-ts/index.md +++ b/docs/plugins/swagger-ts/index.md @@ -383,6 +383,10 @@ date: Date Type: `'string' | 'date'`
Default: `'string'` +::: + +::: code-group + ```typescript ['string'] import { defineConfig } from '@kubb/core' import createSwagger from '@kubb/swagger' @@ -427,6 +431,76 @@ export default defineConfig({ ::: +### unknownType + +Which type to use when the Swagger/OpenAPI file is not providing more information. + +::: info type + +::: code-group + +```typescript ['any'] +any +``` + +```typescript ['unknown'] +unknown +``` + +::: + +::: info +Type: `'any' | 'unknown'`
+Default: `'any'` + +::: + +::: code-group + +```typescript ['any'] +import { defineConfig } from '@kubb/core' +import createSwagger from '@kubb/swagger' +import createSwaggerTS from '@kubb/swagger-ts' + +export default defineConfig({ + input: { + path: './petStore.yaml', + }, + output: { + path: './src/gen', + }, + plugins: [ + createSwagger({ output: false }), + createSwaggerTS({ + unknownType: 'any', + }), + ], +}) +``` + +```typescript ['unknown'] +import { defineConfig } from '@kubb/core' +import createSwagger from '@kubb/swagger' +import createSwaggerTS from '@kubb/swagger-ts' + +export default defineConfig({ + input: { + path: './petStore.yaml', + }, + output: { + path: './src/gen', + }, + plugins: [ + createSwagger({ output: false }), + createSwaggerTS({ + unknownType: 'unknown', + }), + ], +}) +``` + +::: + ### optionalType Choose what to use as mode for an optional value.
diff --git a/docs/plugins/swagger-zod/index.md b/docs/plugins/swagger-zod/index.md index 97e4c59aa..113989930 100644 --- a/docs/plugins/swagger-zod/index.md +++ b/docs/plugins/swagger-zod/index.md @@ -360,6 +360,8 @@ date: Date Type: `'string' | 'date'`
Default: `'string'` +::: code-group + ```typescript ['string'] import { defineConfig } from '@kubb/core' import createSwagger from '@kubb/swagger' @@ -402,6 +404,75 @@ export default defineConfig({ }) ``` +::: + +### unknownType + +Which type to use when the Swagger/OpenAPI file is not providing more information. + +::: info type + +::: code-group + +```typescript ['any'] +any +``` + +```typescript ['unknown'] +unknown +``` + +::: + +::: info +Type: `'any' | 'unknown'`
+Default: `'any'` + +::: + +::: code-group + +```typescript ['any'] +import { defineConfig } from '@kubb/core' +import createSwagger from '@kubb/swagger' +import createSwaggerZod from '@kubb/swagger-zod' + +export default defineConfig({ + input: { + path: './petStore.yaml', + }, + output: { + path: './src/gen', + }, + plugins: [ + createSwagger({ output: false }), + createSwaggerZod({ + unknownType: 'any', + }), + ], +}) +``` + +```typescript ['unknown'] +import { defineConfig } from '@kubb/core' +import createSwagger from '@kubb/swagger' +import createSwaggerZod from '@kubb/swagger-zod' + +export default defineConfig({ + input: { + path: './petStore.yaml', + }, + output: { + path: './src/gen', + }, + plugins: [ + createSwagger({ output: false }), + createSwaggerZod({ + unknownType: 'unknown', + }), + ], +}) +``` ::: diff --git a/packages/parser/src/factory.ts b/packages/parser/src/factory.ts index e95c5e990..af50ff199 100644 --- a/packages/parser/src/factory.ts +++ b/packages/parser/src/factory.ts @@ -455,6 +455,7 @@ export function createOmitDeclaration({ keys, type, nonNullable }: { keys: Array export const keywordTypeNodes = { any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), + unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword), number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword), diff --git a/packages/swagger-faker/src/FakerGenerator.test.ts b/packages/swagger-faker/src/FakerGenerator.test.ts index 3aeb1cffa..6c4c650cd 100644 --- a/packages/swagger-faker/src/FakerGenerator.test.ts +++ b/packages/swagger-faker/src/FakerGenerator.test.ts @@ -15,6 +15,7 @@ describe('FakeGenerator enums', async () => { mapper: {}, seed: 1, transformers: {}, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, diff --git a/packages/swagger-faker/src/FakerGenerator.ts b/packages/swagger-faker/src/FakerGenerator.ts index 3c73f7570..84b7e6267 100644 --- a/packages/swagger-faker/src/FakerGenerator.ts +++ b/packages/swagger-faker/src/FakerGenerator.ts @@ -118,7 +118,7 @@ export class FakerGenerator extends Generator { - return item && item.keyword !== fakerKeywords.any + return item && item.keyword !== this.#unknownReturn }), } if (schemaWithoutOneOf.properties && union.args) { @@ -211,7 +211,7 @@ export class FakerGenerator extends Generator { - return item && item.keyword !== fakerKeywords.any + return item && item.keyword !== this.#unknownReturn }), } if (schemaWithouAnyOf.properties && union.args) { @@ -232,7 +232,7 @@ export class FakerGenerator extends Generator { - return item && item.keyword !== fakerKeywords.any + return item && item.keyword !== this.#unknownReturn }), } @@ -371,6 +371,14 @@ export class FakerGenerator extends Generator { mapper: {}, seed: undefined, transformers: {}, + unknownType: 'any', } const og = await new OperationGenerator( @@ -49,6 +50,7 @@ describe('OperationGenerator', async () => { mapper: {}, seed: [222], transformers: {}, + unknownType: 'any', } const og = await new OperationGenerator( @@ -79,6 +81,7 @@ describe('OperationGenerator', async () => { mapper: {}, seed: undefined, transformers: {}, + unknownType: 'any', } const og = await new OperationGenerator( @@ -98,4 +101,31 @@ describe('OperationGenerator', async () => { expect(files).toMatchSnapshot() }) + + test('[DELETE] should generate with unknownType `any`', async () => { + const options: GetOperationGeneratorOptions = { + dateType: 'date', + mapper: {}, + seed: undefined, + transformers: {}, + unknownType: 'any', + } + + const og = await new OperationGenerator( + options, + { + oas, + exclude: [], + include: undefined, + pluginManager: mockedPluginManager, + plugin: {} as KubbPlugin, + contentType: undefined, + override: undefined, + }, + ) + const operation = oas.operation('/pet/{petId}', 'delete') + const files = await og.post(operation, og.getSchemas(operation), options) + + expect(files).toMatchSnapshot() + }) }) diff --git a/packages/swagger-faker/src/__snapshots__/OperationGenerator.test.tsx.snap b/packages/swagger-faker/src/__snapshots__/OperationGenerator.test.tsx.snap index 5ccde9026..154e1c65d 100644 --- a/packages/swagger-faker/src/__snapshots__/OperationGenerator.test.tsx.snap +++ b/packages/swagger-faker/src/__snapshots__/OperationGenerator.test.tsx.snap @@ -1,5 +1,45 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`OperationGenerator > [DELETE] should generate with unknownType \`any\` 1`] = ` +[ + { + "baseName": "delete_pet-petid.ts", + "env": undefined, + "exports": [], + "id": undefined, + "imports": [ + { + "isTypeOnly": undefined, + "name": [ + "faker", + ], + "path": "@faker-js/faker", + "root": undefined, + }, + { + "isTypeOnly": true, + "name": [ + "DeletePetPetidMutationResponse", + ], + "path": "DeletePetPetid", + "root": "delete_pet-petid.ts", + }, + ], + "meta": { + "name": "delete_pet-petid", + "pluginKey": undefined, + "tag": undefined, + }, + "override": undefined, + "path": "delete_pet-petid.ts", + "source": "export function DeletePetPetidMutationResponse(): NonNullable { + return undefined; +} +", + }, +] +`; + exports[`OperationGenerator > [GET] should generate 1`] = ` [ { diff --git a/packages/swagger-faker/src/components/__snapshots__/Mutation.test.tsx.snap b/packages/swagger-faker/src/components/__snapshots__/Mutation.test.tsx.snap index 33cbc4408..d5b68401a 100644 --- a/packages/swagger-faker/src/components/__snapshots__/Mutation.test.tsx.snap +++ b/packages/swagger-faker/src/components/__snapshots__/Mutation.test.tsx.snap @@ -6,7 +6,7 @@ exports[` > pets 1`] = ` */ export function createCreatePets201(): NonNullable { - return undefined + return unknown() } export function createCreatePetsMutationRequest(): NonNullable { @@ -14,7 +14,7 @@ export function createCreatePetsMutationRequest(): NonNullable { - return undefined + return unknown() } /** diff --git a/packages/swagger-faker/src/fakerParser.ts b/packages/swagger-faker/src/fakerParser.ts index 62aa91881..6456b0c7e 100644 --- a/packages/swagger-faker/src/fakerParser.ts +++ b/packages/swagger-faker/src/fakerParser.ts @@ -1,5 +1,6 @@ export const fakerKeywords = { any: 'any', + unknown: 'unknown', number: 'number', integer: 'integer', string: 'string', @@ -32,6 +33,7 @@ export type FakerKeyword = keyof typeof fakerKeywords export const fakerKeywordMapper: Record = { any: 'undefined', + unknown: 'unknown', number: 'faker.number.float', integer: 'faker.number.int', string: 'faker.string.alpha', @@ -65,7 +67,7 @@ type FakerMetaBase = { args: T } -type FakerMetaUnknown = { keyword: string } +type FakerMetaUnknown = { keyword: typeof fakerKeywords.unknown } type FakerMetaAny = { keyword: typeof fakerKeywords.any } type FakerMetaNull = { keyword: typeof fakerKeywords.null } @@ -111,6 +113,7 @@ type FakerMetaUuid = { keyword: typeof fakerKeywords.uuid } type FakerMetaUrl = { keyword: typeof fakerKeywords.url } export type FakerMeta = + | { keyword: string } | FakerMetaUnknown | FakerMetaAny | FakerMetaNull diff --git a/packages/swagger-faker/src/plugin.ts b/packages/swagger-faker/src/plugin.ts index 8672dccd7..c49584551 100644 --- a/packages/swagger-faker/src/plugin.ts +++ b/packages/swagger-faker/src/plugin.ts @@ -19,7 +19,18 @@ export const pluginName = 'swagger-faker' satisfies PluginOptions['name'] export const pluginKey: PluginOptions['key'] = [pluginName] satisfies PluginOptions['key'] export const definePlugin = createPlugin((options) => { - const { output = { path: 'mocks' }, seed, group, exclude = [], include, override = [], transformers = {}, mapper = {}, dateType = 'string' } = options + const { + output = { path: 'mocks' }, + seed, + group, + exclude = [], + include, + override = [], + transformers = {}, + mapper = {}, + dateType = 'string', + unknownType = 'any', + } = options const template = group?.output ? group.output : `${output.path}/{{tag}}Controller` return { @@ -29,6 +40,7 @@ export const definePlugin = createPlugin((options) => { mapper, dateType, seed, + unknownType, }, pre: [swaggerPluginName, swaggerTypeScriptPluginName], resolvePath(baseName, directory, options) { diff --git a/packages/swagger-faker/src/types.ts b/packages/swagger-faker/src/types.ts index b847553ca..4c28261ed 100644 --- a/packages/swagger-faker/src/types.ts +++ b/packages/swagger-faker/src/types.ts @@ -65,6 +65,11 @@ export type Options = { * @default 'string' */ dateType?: 'string' | 'date' + /** + * Which type to use when the Swagger/OpenAPI file is not providing more information + * @default 'any' + */ + unknownType?: 'any' | 'unknown' transformers?: { /** * Customize the names based on the type that is provided by the plugin. @@ -91,6 +96,7 @@ export type Options = { type ResolvedOptions = { dateType: NonNullable + unknownType: NonNullable mapper: NonNullable transformers: NonNullable seed: NonNullable | undefined diff --git a/packages/swagger-ts/src/OperationGenerator.test.tsx b/packages/swagger-ts/src/OperationGenerator.test.tsx index 2f2a15002..88857a141 100644 --- a/packages/swagger-ts/src/OperationGenerator.test.tsx +++ b/packages/swagger-ts/src/OperationGenerator.test.tsx @@ -21,6 +21,7 @@ describe('OperationGenerator', async () => { usedEnumNames: {}, transformers: {}, oasType: false, + unknownType: 'any', } const og = await new OperationGenerator( @@ -53,6 +54,7 @@ describe('OperationGenerator', async () => { usedEnumNames: {}, transformers: {}, oasType: false, + unknownType: 'any', } const og = await new OperationGenerator( @@ -72,4 +74,61 @@ describe('OperationGenerator', async () => { expect(files).toMatchSnapshot() }) + + test('[DELETE] should generate with unknownType `any`', async () => { + const options: GetOperationGeneratorOptions = { + enumType: 'asConst', + dateType: 'string', + optionalType: 'questionToken', + usedEnumNames: {}, + transformers: {}, + oasType: false, + unknownType: 'any', + } + + const og = await new OperationGenerator( + options, + { + oas, + exclude: [], + include: undefined, + pluginManager: mockedPluginManager, + plugin: {} as KubbPlugin, + contentType: undefined, + override: undefined, + }, + ) + const operation = oas.operation('/pet/{petId}', 'delete') + const files = await og.post(operation, og.getSchemas(operation), options) + + expect(files).toMatchSnapshot() + }) + test('[DELETE] should generate with unknownType `unknown`', async () => { + const options: GetOperationGeneratorOptions = { + enumType: 'asConst', + dateType: 'string', + optionalType: 'questionToken', + usedEnumNames: {}, + transformers: {}, + oasType: false, + unknownType: 'unknown', + } + + const og = await new OperationGenerator( + options, + { + oas, + exclude: [], + include: undefined, + pluginManager: mockedPluginManager, + plugin: {} as KubbPlugin, + contentType: undefined, + override: undefined, + }, + ) + const operation = oas.operation('/pet/{petId}', 'delete') + const files = await og.post(operation, og.getSchemas(operation), options) + + expect(files).toMatchSnapshot() + }) }) diff --git a/packages/swagger-ts/src/TypeGenerator.test.ts b/packages/swagger-ts/src/TypeGenerator.test.ts index 4cc68056b..96a27bf35 100644 --- a/packages/swagger-ts/src/TypeGenerator.test.ts +++ b/packages/swagger-ts/src/TypeGenerator.test.ts @@ -22,6 +22,7 @@ describe('TypeGenerator petStore', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -45,6 +46,7 @@ describe('TypeGenerator petStore', async () => { optionalType: 'undefined', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -68,6 +70,7 @@ describe('TypeGenerator petStore', async () => { optionalType: 'questionTokenAndUndefined', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -91,6 +94,7 @@ describe('TypeGenerator petStore', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas: {} as Oas, pluginManager: { resolveName: ({ name }) => name, resolvePath: ({ baseName }) => baseName } as PluginManager, @@ -119,6 +123,7 @@ describe('TypeGenerator petStore', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -146,6 +151,7 @@ describe('TypeGenerator petStoreRef', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -173,6 +179,7 @@ describe('TypeGenerator discriminator', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -195,6 +202,7 @@ describe('TypeGenerator discriminator', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -216,6 +224,7 @@ describe('TypeGenerator discriminator', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -237,6 +246,7 @@ describe('TypeGenerator discriminator', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -257,6 +267,7 @@ describe('TypeGenerator discriminator', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -278,6 +289,7 @@ describe('TypeGenerator discriminator', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -299,6 +311,7 @@ describe('TypeGenerator discriminator', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -324,6 +337,7 @@ describe('TypeGenerator enums', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -359,6 +373,7 @@ describe('TypeGenerator enums', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -381,6 +396,7 @@ describe('TypeGenerator enums', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -403,6 +419,7 @@ describe('TypeGenerator enums', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -425,6 +442,7 @@ describe('TypeGenerator enums', async () => { optionalType: 'questionToken', transformers: {}, oasType: false, + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, diff --git a/packages/swagger-ts/src/TypeGenerator.ts b/packages/swagger-ts/src/TypeGenerator.ts index 99ee96e1d..e01a88820 100644 --- a/packages/swagger-ts/src/TypeGenerator.ts +++ b/packages/swagger-ts/src/TypeGenerator.ts @@ -142,11 +142,9 @@ export class TypeGenerator extends Generator { - return item && item !== factory.keywordTypeNodes.any + return item && item !== this.#unknownReturn }) as Array, }) @@ -242,7 +240,7 @@ export class TypeGenerator extends Generator { - return item && item !== factory.keywordTypeNodes.any + return item && item !== this.#unknownReturn }) as Array, }) @@ -265,7 +263,7 @@ export class TypeGenerator extends Generator { - return item && item !== factory.keywordTypeNodes.any + return item && item !== this.#unknownReturn }) as Array, }) @@ -401,6 +399,14 @@ export class TypeGenerator extends Generator [DELETE] should generate with unknownType \`any\` 1`] = ` +[ + { + "baseName": "delete_pet-petid.ts", + "env": undefined, + "exports": [], + "id": undefined, + "imports": [], + "meta": { + "name": "delete_pet-petid", + "pluginKey": undefined, + "tag": undefined, + }, + "override": undefined, + "path": "delete_pet-petid.ts", + "source": "export type DeletePetPetidMutationResponse = any | null; +export namespace DeletePetPetidMutation { + export type Response = DeletePetPetidMutationResponse; +} +", + }, +] +`; + +exports[`OperationGenerator > [DELETE] should generate with unknownType \`unknown\` 1`] = ` +[ + { + "baseName": "delete_pet-petid.ts", + "env": undefined, + "exports": [], + "id": undefined, + "imports": [], + "meta": { + "name": "delete_pet-petid", + "pluginKey": undefined, + "tag": undefined, + }, + "override": undefined, + "path": "delete_pet-petid.ts", + "source": "export type DeletePetPetidMutationResponse = unknown | null; +export namespace DeletePetPetidMutation { + export type Response = DeletePetPetidMutationResponse; +} +", + }, +] +`; + exports[`OperationGenerator > [GET] should generate with optionalType \`questionToken\` 1`] = ` [ { @@ -49,11 +97,11 @@ export type ListPetsError = Error; * @description A paged array of pets */ export type ListPetsQueryResponse = Pets; -export namespace ListPetsQuery { - export type Response = ListPetsQueryResponse; - export type QueryParams = ListPetsQueryParams; - export type Errors = ListPetsError; -} +export type ListPetsQuery = { + Response: ListPetsQueryResponse; + QueryParams: ListPetsQueryParams; + Errors: ListPetsError; +}; ", }, ] @@ -113,11 +161,11 @@ export type ShowPetByIdError = Error; * @description Expected response to a valid request */ export type ShowPetByIdQueryResponse = Pet; -export namespace ShowPetByIdQuery { - export type Response = ShowPetByIdQueryResponse; - export type PathParams = ShowPetByIdPathParams; - export type Errors = ShowPetByIdError; -} +export type ShowPetByIdQuery = { + Response: ShowPetByIdQueryResponse; + PathParams: ShowPetByIdPathParams; + Errors: ShowPetByIdError; +}; ", }, ] diff --git a/packages/swagger-ts/src/plugin.ts b/packages/swagger-ts/src/plugin.ts index 083e7d79c..e29a32e9a 100644 --- a/packages/swagger-ts/src/plugin.ts +++ b/packages/swagger-ts/src/plugin.ts @@ -24,6 +24,7 @@ export const definePlugin = createPlugin((options) => { override = [], enumType = 'asConst', dateType = 'string', + unknownType = 'any', optionalType = 'questionToken', transformers = {}, oasType = false, @@ -40,6 +41,7 @@ export const definePlugin = createPlugin((options) => { oasType, // keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey) usedEnumNames: {}, + unknownType, }, pre: [swaggerPluginName], resolvePath(baseName, directory, options) { diff --git a/packages/swagger-ts/src/types.ts b/packages/swagger-ts/src/types.ts index 663be1833..4b9a3ee3a 100644 --- a/packages/swagger-ts/src/types.ts +++ b/packages/swagger-ts/src/types.ts @@ -62,6 +62,11 @@ export type Options = { * @default 'string' */ dateType?: 'string' | 'date' + /** + * Which type to use when the Swagger/OpenAPI file is not providing more information. + * @default 'any' + */ + unknownType?: 'any' | 'unknown' /** * Choose what to use as mode for an optional value. * @examples 'questionToken': type?: string @@ -85,6 +90,7 @@ export type Options = { type ResolvedOptions = { enumType: NonNullable dateType: NonNullable + unknownType: NonNullable optionalType: NonNullable transformers: NonNullable oasType: NonNullable diff --git a/packages/swagger-zod/src/OperationGenerator.test.tsx b/packages/swagger-zod/src/OperationGenerator.test.tsx new file mode 100644 index 000000000..b6fd86b03 --- /dev/null +++ b/packages/swagger-zod/src/OperationGenerator.test.tsx @@ -0,0 +1,135 @@ +import { mockedPluginManager } from '@kubb/core/mocks' +import { OasManager } from '@kubb/swagger' + +import { OperationGenerator } from './OperationGenerator.tsx' + +import type { KubbPlugin } from '@kubb/core' +import type { GetOperationGeneratorOptions } from '@kubb/swagger' +import type { PluginOptions } from './types.ts' + +describe('OperationGenerator', async () => { + const oas = await OasManager.parseFromConfig({ + root: './', + output: { path: 'test', clean: true }, + input: { path: 'packages/swagger-zod/mocks/petStore.yaml' }, + }) + test('[GET] should generate', async () => { + const options: GetOperationGeneratorOptions = { + dateType: 'date', + transformers: {}, + typed: false, + exclude: undefined, + include: undefined, + override: undefined, + unknownType: 'any', + } + + const og = await new OperationGenerator( + options, + { + oas, + exclude: [], + include: undefined, + pluginManager: mockedPluginManager, + plugin: {} as KubbPlugin, + contentType: undefined, + override: undefined, + }, + ) + const operation = oas.operation('/pets', 'get') + const operationShowById = oas.operation('/pets/{petId}', 'get') + + const files = await og.get(operation, og.getSchemas(operation), options) + const getShowByIdFiles = await og.get(operationShowById, og.getSchemas(operationShowById), options) + + expect(files).toMatchSnapshot() + expect(getShowByIdFiles).toMatchSnapshot() + }) + + test('[POST] should generate', async () => { + const options: GetOperationGeneratorOptions = { + dateType: 'date', + transformers: {}, + typed: false, + exclude: undefined, + include: undefined, + override: undefined, + unknownType: 'any', + } + + const og = await new OperationGenerator( + options, + { + oas, + exclude: [], + include: undefined, + pluginManager: mockedPluginManager, + plugin: {} as KubbPlugin, + contentType: undefined, + override: undefined, + }, + ) + const operation = oas.operation('/pets', 'post') + const files = await og.post(operation, og.getSchemas(operation), options) + + expect(files).toMatchSnapshot() + }) + + test('[DELETE] should generate with unknownType `any`', async () => { + const options: GetOperationGeneratorOptions = { + dateType: 'date', + transformers: {}, + typed: false, + exclude: undefined, + include: undefined, + override: undefined, + unknownType: 'any', + } + + const og = await new OperationGenerator( + options, + { + oas, + exclude: [], + include: undefined, + pluginManager: mockedPluginManager, + plugin: {} as KubbPlugin, + contentType: undefined, + override: undefined, + }, + ) + const operation = oas.operation('/pet/{petId}', 'delete') + const files = await og.post(operation, og.getSchemas(operation), options) + + expect(files).toMatchSnapshot() + }) + + test('[DELETE] should generate with unknownType `unknown`', async () => { + const options: GetOperationGeneratorOptions = { + dateType: 'date', + transformers: {}, + typed: false, + exclude: undefined, + include: undefined, + override: undefined, + unknownType: 'unknown', + } + + const og = await new OperationGenerator( + options, + { + oas, + exclude: [], + include: undefined, + pluginManager: mockedPluginManager, + plugin: {} as KubbPlugin, + contentType: undefined, + override: undefined, + }, + ) + const operation = oas.operation('/pet/{petId}', 'delete') + const files = await og.post(operation, og.getSchemas(operation), options) + + expect(files).toMatchSnapshot() + }) +}) diff --git a/packages/swagger-zod/src/ZodGenerator.test.ts b/packages/swagger-zod/src/ZodGenerator.test.ts index f2324be74..cc3995251 100644 --- a/packages/swagger-zod/src/ZodGenerator.test.ts +++ b/packages/swagger-zod/src/ZodGenerator.test.ts @@ -19,6 +19,7 @@ describe('ZodGenerator PetStore', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -38,6 +39,7 @@ describe('ZodGenerator PetStore', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -57,6 +59,7 @@ describe('ZodGenerator PetStore', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -76,6 +79,7 @@ describe('ZodGenerator PetStore', async () => { transformers: {}, typed: true, dateType: 'string', + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -98,6 +102,7 @@ describe('ZodGenerator constCases', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -174,6 +179,7 @@ describe('ZodGenerator lazy', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -196,6 +202,7 @@ describe('ZodGenerator enums', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, @@ -228,6 +235,7 @@ describe('ZodGenerator recursive', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', }, { oas, pluginManager: mockedPluginManager, diff --git a/packages/swagger-zod/src/ZodGenerator.ts b/packages/swagger-zod/src/ZodGenerator.ts index 6ea03a6a9..c961f0f77 100644 --- a/packages/swagger-zod/src/ZodGenerator.ts +++ b/packages/swagger-zod/src/ZodGenerator.ts @@ -143,7 +143,7 @@ export class ZodGenerator extends Generator { - return item && item.keyword !== zodKeywords.any + return item && item.keyword !== this.#unknownReturn }), } if (schemaWithoutOneOf.properties) { @@ -250,7 +250,7 @@ export class ZodGenerator extends Generator { - return item && item.keyword !== zodKeywords.any + return item && item.keyword !== this.#unknownReturn }), } if (schemaWithoutAnyOf.properties) { @@ -271,7 +271,7 @@ export class ZodGenerator extends Generator { - return item && item.keyword !== zodKeywords.any + return item && item.keyword !== this.#unknownReturn }), } @@ -452,6 +452,13 @@ export class ZodGenerator extends Generator [DELETE] should generate with unknownType \`any\` 1`] = ` +[ + { + "baseName": "delete_pet-petid.ts", + "env": undefined, + "exports": [], + "id": undefined, + "imports": [ + { + "isTypeOnly": undefined, + "name": [ + "z", + ], + "path": "zod", + "root": undefined, + }, + ], + "meta": { + "name": "delete_pet-petid", + "pluginKey": undefined, + "tag": undefined, + }, + "override": undefined, + "path": "delete_pet-petid.ts", + "source": "export const DeletePetPetidMutationResponse = z.any(); +", + }, +] +`; + +exports[`OperationGenerator > [DELETE] should generate with unknownType \`unknown\` 1`] = ` +[ + { + "baseName": "delete_pet-petid.ts", + "env": undefined, + "exports": [], + "id": undefined, + "imports": [ + { + "isTypeOnly": undefined, + "name": [ + "z", + ], + "path": "zod", + "root": undefined, + }, + ], + "meta": { + "name": "delete_pet-petid", + "pluginKey": undefined, + "tag": undefined, + }, + "override": undefined, + "path": "delete_pet-petid.ts", + "source": "export const DeletePetPetidMutationResponse = z.unknown(); +", + }, +] +`; + +exports[`OperationGenerator > [GET] should generate 1`] = ` +[ + { + "baseName": "listPets.ts", + "env": undefined, + "exports": [], + "id": undefined, + "imports": [ + { + "isTypeOnly": undefined, + "name": [ + "z", + ], + "path": "zod", + "root": undefined, + }, + { + "isTypeOnly": false, + "name": [ + "Error", + ], + "path": "Error", + "root": "listPets.ts", + }, + { + "isTypeOnly": false, + "name": [ + "Pets", + ], + "path": "Pets", + "root": "listPets.ts", + }, + ], + "meta": { + "name": "listPets", + "pluginKey": undefined, + "tag": "pets", + }, + "override": undefined, + "path": "listPets.ts", + "source": "export const ListPetsQueryParams = z.object({ "limit": z.string().describe(\`How many items to return at one time (max 100)\`).optional() }).optional(); + + /** + * @description unexpected error + */ +export const ListPetsError = z.lazy(() => Error); + + /** + * @description A paged array of pets + */ +export const ListPetsQueryResponse = z.lazy(() => Pets); +", + }, +] +`; + +exports[`OperationGenerator > [GET] should generate 2`] = ` +[ + { + "baseName": "showPetById.ts", + "env": undefined, + "exports": [], + "id": undefined, + "imports": [ + { + "isTypeOnly": undefined, + "name": [ + "z", + ], + "path": "zod", + "root": undefined, + }, + { + "isTypeOnly": false, + "name": [ + "Error", + ], + "path": "Error", + "root": "showPetById.ts", + }, + { + "isTypeOnly": false, + "name": [ + "Pet", + ], + "path": "Pet", + "root": "showPetById.ts", + }, + ], + "meta": { + "name": "showPetById", + "pluginKey": undefined, + "tag": "pets", + }, + "override": undefined, + "path": "showPetById.ts", + "source": "export const ShowPetByIdPathParams = z.object({ "petId": z.string().describe(\`The id of the pet to retrieve\`), "testId": z.string().describe(\`The id of the pet to retrieve\`) }); + + /** + * @description unexpected error + */ +export const ShowPetByIdError = z.lazy(() => Error); + + /** + * @description Expected response to a valid request + */ +export const ShowPetByIdQueryResponse = z.lazy(() => Pet); +", + }, +] +`; + +exports[`OperationGenerator > [POST] should generate 1`] = ` +[ + { + "baseName": "createPets.ts", + "env": undefined, + "exports": [], + "id": undefined, + "imports": [ + { + "isTypeOnly": undefined, + "name": [ + "z", + ], + "path": "zod", + "root": undefined, + }, + { + "isTypeOnly": false, + "name": [ + "Error", + ], + "path": "Error", + "root": "createPets.ts", + }, + ], + "meta": { + "name": "createPets", + "pluginKey": undefined, + "tag": "pets", + }, + "override": undefined, + "path": "createPets.ts", + "source": "/** + * @description Null response + */ +export const CreatePets201 = z.any(); +export const CreatePetsMutationRequest = z.object({ "name": z.string(), "tag": z.string() }); +export const CreatePetsMutationResponse = z.any(); + + /** + * @description unexpected error + */ +export const CreatePetsError = z.lazy(() => Error); +", + }, +] +`; diff --git a/packages/swagger-zod/src/components/__snapshots__/Mutation.test.tsx.snap b/packages/swagger-zod/src/components/__snapshots__/Mutation.test.tsx.snap index ee5cfc10f..42f14a69e 100644 --- a/packages/swagger-zod/src/components/__snapshots__/Mutation.test.tsx.snap +++ b/packages/swagger-zod/src/components/__snapshots__/Mutation.test.tsx.snap @@ -4,9 +4,9 @@ exports[` > pets 1`] = ` "/** * @description Null response */ -export const CreatePets201 = z.any() +export const CreatePets201 = z.unknown() export const CreatePetsMutationRequest = z.object({ name: z.string(), tag: z.string() }) -export const CreatePetsMutationResponse = z.any() +export const CreatePetsMutationResponse = z.unknown() /** * @description unexpected error diff --git a/packages/swagger-zod/src/plugin.ts b/packages/swagger-zod/src/plugin.ts index 7dc3a6814..818851713 100644 --- a/packages/swagger-zod/src/plugin.ts +++ b/packages/swagger-zod/src/plugin.ts @@ -19,7 +19,8 @@ export const pluginName = 'swagger-zod' satisfies PluginOptions['name'] export const pluginKey: PluginOptions['key'] = [pluginName] satisfies PluginOptions['key'] export const definePlugin = createPlugin((options) => { - const { output = { path: 'zod' }, group, exclude = [], include, override = [], transformers = {}, dateType = 'string', typed = false } = options + const { output = { path: 'zod' }, group, exclude = [], include, override = [], transformers = {}, dateType = 'string', unknownType = 'any', typed = false } = + options const template = group?.output ? group.output : `${output.path}/{{tag}}Controller` return { @@ -31,6 +32,7 @@ export const definePlugin = createPlugin((options) => { override, typed, dateType, + unknownType, }, pre: [swaggerPluginName, typed ? swaggerTypeScriptPluginName : undefined].filter(Boolean), resolvePath(baseName, directory, options) { diff --git a/packages/swagger-zod/src/types.ts b/packages/swagger-zod/src/types.ts index 1ec768555..fa6c1a89e 100644 --- a/packages/swagger-zod/src/types.ts +++ b/packages/swagger-zod/src/types.ts @@ -68,6 +68,11 @@ export type Options = { * @default 'string' */ dateType?: 'string' | 'date' + /** + * Which type to use when the Swagger/OpenAPI file is not providing more information + * @default 'any' + */ + unknownType?: 'any' | 'unknown' /** * Use TypeScript(`@kubb/swagger-ts`) to add type annotation. */ @@ -80,6 +85,7 @@ type ResolvedOptions = { include: Options['include'] override: Options['override'] dateType: NonNullable + unknownType: NonNullable typed: NonNullable } diff --git a/packages/swagger-zod/src/zodParser.ts b/packages/swagger-zod/src/zodParser.ts index 8daadcfac..16b3caa23 100644 --- a/packages/swagger-zod/src/zodParser.ts +++ b/packages/swagger-zod/src/zodParser.ts @@ -1,5 +1,6 @@ export const zodKeywords = { any: 'any', + unknown: 'unknown', number: 'number', integer: 'integer', object: 'object', @@ -39,6 +40,7 @@ export type ZodKeyword = keyof typeof zodKeywords export const zodKeywordMapper: Record = { any: 'z.any', + unknown: 'z.unknown', number: 'z.number', integer: 'z.number', object: 'z.object', @@ -79,7 +81,7 @@ type ZodMetaBase = { args: T } -type ZodMetaUnknown = { keyword: string } +type ZodMetaUnknown = { keyword: typeof zodKeywords.unknown } type ZodMetaAny = { keyword: typeof zodKeywords.any } type ZodMetaNull = { keyword: typeof zodKeywords.null } @@ -132,6 +134,7 @@ type ZodMetaUrl = { keyword: typeof zodKeywords.url } type ZodMetaReadOnly = { keyword: typeof zodKeywords.readOnly } export type ZodMeta = + | { keyword: string } | ZodMetaUnknown | ZodMetaAny | ZodMetaNull From 84dcf1a9cdc83b24487f2d50e6dc01f519e82712 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Sun, 21 Jan 2024 21:25:21 +0100 Subject: [PATCH 2/4] chore: linting --- packages/swagger-faker/src/components/Mutation.test.tsx | 1 + packages/swagger-faker/src/components/Query.test.tsx | 1 + packages/swagger-zod/src/components/Mutation.test.tsx | 1 + packages/swagger-zod/src/components/Query.test.tsx | 1 + 4 files changed, 4 insertions(+) diff --git a/packages/swagger-faker/src/components/Mutation.test.tsx b/packages/swagger-faker/src/components/Mutation.test.tsx index 3d8182ddb..3b3717d20 100644 --- a/packages/swagger-faker/src/components/Mutation.test.tsx +++ b/packages/swagger-faker/src/components/Mutation.test.tsx @@ -33,6 +33,7 @@ describe('', async () => { mapper: {}, seed: undefined, transformers: {}, + unknownType:"any" } const plugin = { options } as KubbPlugin diff --git a/packages/swagger-faker/src/components/Query.test.tsx b/packages/swagger-faker/src/components/Query.test.tsx index 32c86f6b7..55b33328c 100644 --- a/packages/swagger-faker/src/components/Query.test.tsx +++ b/packages/swagger-faker/src/components/Query.test.tsx @@ -33,6 +33,7 @@ describe('', async () => { mapper: {}, seed: undefined, transformers: {}, + unknownType: 'any', } const plugin = { options } as KubbPlugin diff --git a/packages/swagger-zod/src/components/Mutation.test.tsx b/packages/swagger-zod/src/components/Mutation.test.tsx index d7dd3ed53..8bb563f35 100644 --- a/packages/swagger-zod/src/components/Mutation.test.tsx +++ b/packages/swagger-zod/src/components/Mutation.test.tsx @@ -24,6 +24,7 @@ describe('', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', } const plugin = { options } as KubbPlugin diff --git a/packages/swagger-zod/src/components/Query.test.tsx b/packages/swagger-zod/src/components/Query.test.tsx index 617c7263c..7a8610289 100644 --- a/packages/swagger-zod/src/components/Query.test.tsx +++ b/packages/swagger-zod/src/components/Query.test.tsx @@ -24,6 +24,7 @@ describe('', async () => { transformers: {}, typed: false, dateType: 'string', + unknownType: 'any', } const plugin = { options } as KubbPlugin From d864ae3c474a9753f10c24b5f03fcefa7b49a0b1 Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Sun, 21 Jan 2024 21:31:25 +0100 Subject: [PATCH 3/4] chore: update snaps --- .../src/components/__snapshots__/Mutation.test.tsx.snap | 4 ++-- .../src/components/__snapshots__/Mutation.test.tsx.snap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/swagger-faker/src/components/__snapshots__/Mutation.test.tsx.snap b/packages/swagger-faker/src/components/__snapshots__/Mutation.test.tsx.snap index d5b68401a..33cbc4408 100644 --- a/packages/swagger-faker/src/components/__snapshots__/Mutation.test.tsx.snap +++ b/packages/swagger-faker/src/components/__snapshots__/Mutation.test.tsx.snap @@ -6,7 +6,7 @@ exports[` > pets 1`] = ` */ export function createCreatePets201(): NonNullable { - return unknown() + return undefined } export function createCreatePetsMutationRequest(): NonNullable { @@ -14,7 +14,7 @@ export function createCreatePetsMutationRequest(): NonNullable { - return unknown() + return undefined } /** diff --git a/packages/swagger-zod/src/components/__snapshots__/Mutation.test.tsx.snap b/packages/swagger-zod/src/components/__snapshots__/Mutation.test.tsx.snap index 42f14a69e..ee5cfc10f 100644 --- a/packages/swagger-zod/src/components/__snapshots__/Mutation.test.tsx.snap +++ b/packages/swagger-zod/src/components/__snapshots__/Mutation.test.tsx.snap @@ -4,9 +4,9 @@ exports[` > pets 1`] = ` "/** * @description Null response */ -export const CreatePets201 = z.unknown() +export const CreatePets201 = z.any() export const CreatePetsMutationRequest = z.object({ name: z.string(), tag: z.string() }) -export const CreatePetsMutationResponse = z.unknown() +export const CreatePetsMutationResponse = z.any() /** * @description unexpected error From bdf1c44bbc9f918e5e00284a9e6e46950c600a2b Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Sun, 21 Jan 2024 21:52:12 +0100 Subject: [PATCH 4/4] chore: fix ts --- e2e/package.json | 8 +- examples/react-query-v5/package.json | 6 +- examples/react-query/package.json | 2 +- examples/vue-query-v5/package.json | 4 +- examples/vue-query/package.json | 2 +- package.json | 4 +- .../src/OperationGenerator.test.tsx | 2 +- .../src/components/Mutation.test.tsx | 2 +- .../src/OperationGenerator.test.tsx | 4 +- .../src/OperationGenerator.test.tsx | 10 +- packages/unplugin/package.json | 2 +- pnpm-lock.yaml | 129 +++++++++--------- 12 files changed, 87 insertions(+), 88 deletions(-) diff --git a/e2e/package.json b/e2e/package.json index 72d7e33df..42a124a58 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -32,10 +32,10 @@ "@kubb/swagger-ts": "workspace:*", "@kubb/swagger-zod": "workspace:*", "@kubb/swagger-zodios": "workspace:*", - "@tanstack/react-query": "^5.17.15", - "@tanstack/solid-query": "^5.17.15", - "@tanstack/svelte-query": "^5.17.15", - "@tanstack/vue-query": "^5.17.15", + "@tanstack/react-query": "^5.17.19", + "@tanstack/solid-query": "^5.17.19", + "@tanstack/svelte-query": "^5.17.19", + "@tanstack/vue-query": "^5.17.19", "@zodios/core": "^10.9.6", "axios": "^1.6.5", "msw": "^1.3.2", diff --git a/examples/react-query-v5/package.json b/examples/react-query-v5/package.json index d99903324..7832fc26c 100644 --- a/examples/react-query-v5/package.json +++ b/examples/react-query-v5/package.json @@ -29,7 +29,7 @@ "@kubb/swagger-client": "workspace:*", "@kubb/swagger-tanstack-query": "workspace:*", "@kubb/swagger-ts": "workspace:*", - "@tanstack/react-query": "^5.17.15", + "@tanstack/react-query": "^5.17.19", "@tanstack/react-query-devtools": "5.0.0", "axios": "^1.6.5", "react": "^18.2.0", @@ -40,10 +40,10 @@ "@types/react": "^18.2.48", "@types/react-dom": "^18.2.18", "@vitejs/plugin-react": "^4.2.1", - "unplugin-kubb": "workspace:*", "msw": "^1.3.2", "typescript": "~5.2.2", - "vite": "^4.5.1" + "unplugin-kubb": "workspace:*", + "vite": "^4.5.2" }, "packageManager": "pnpm@8.3.0", "engines": { diff --git a/examples/react-query/package.json b/examples/react-query/package.json index b3e9a9414..cef63e099 100644 --- a/examples/react-query/package.json +++ b/examples/react-query/package.json @@ -41,7 +41,7 @@ "@vitejs/plugin-react": "^4.2.1", "msw": "^1.3.2", "typescript": "~5.2.2", - "vite": "^4.5.1" + "vite": "^4.5.2" }, "packageManager": "pnpm@8.3.0", "engines": { diff --git a/examples/vue-query-v5/package.json b/examples/vue-query-v5/package.json index 6968251cb..a052477e0 100644 --- a/examples/vue-query-v5/package.json +++ b/examples/vue-query-v5/package.json @@ -29,7 +29,7 @@ "@kubb/swagger-tanstack-query": "workspace:*", "@kubb/swagger-ts": "workspace:*", "@kubb/swagger-zod": "workspace:*", - "@tanstack/vue-query": "^5.17.15", + "@tanstack/vue-query": "^5.17.19", "axios": "^1.6.5", "vue": "^3.4.15" }, @@ -38,7 +38,7 @@ "msw": "^1.3.2", "tsup": "^8.0.1", "typescript": "~5.2.2", - "vite": "^4.5.1" + "vite": "^4.5.2" }, "packageManager": "pnpm@8.3.0", "engines": { diff --git a/examples/vue-query/package.json b/examples/vue-query/package.json index 02ec17c88..52e1d3460 100644 --- a/examples/vue-query/package.json +++ b/examples/vue-query/package.json @@ -38,7 +38,7 @@ "msw": "^1.3.2", "tsup": "^8.0.1", "typescript": "~5.2.2", - "vite": "^4.5.1" + "vite": "^4.5.2" }, "packageManager": "pnpm@8.3.0", "engines": { diff --git a/package.json b/package.json index 95320e693..6a1cd5ad3 100644 --- a/package.json +++ b/package.json @@ -63,10 +63,10 @@ "@types/node": "^20.11.5", "@vitest/coverage-v8": "^1.2.1", "@vitest/ui": "^1.2.1", - "bun-types": "^1.0.23", + "bun-types": "^1.0.25", "dprint": "^0.45.0", "prettier": "^3.2.4", - "prettier-eslint": "^16.2.0", + "prettier-eslint": "^16.3.0", "rimraf": "^5.0.5", "ts-node": "^10.9.2", "turbo": "^1.11.3", diff --git a/packages/swagger-faker/src/OperationGenerator.test.tsx b/packages/swagger-faker/src/OperationGenerator.test.tsx index 432c502ba..5e85e094f 100644 --- a/packages/swagger-faker/src/OperationGenerator.test.tsx +++ b/packages/swagger-faker/src/OperationGenerator.test.tsx @@ -118,7 +118,7 @@ describe('OperationGenerator', async () => { exclude: [], include: undefined, pluginManager: mockedPluginManager, - plugin: {} as KubbPlugin, + plugin: {} as Plugin, contentType: undefined, override: undefined, }, diff --git a/packages/swagger-faker/src/components/Mutation.test.tsx b/packages/swagger-faker/src/components/Mutation.test.tsx index c57460158..5bafbf1df 100644 --- a/packages/swagger-faker/src/components/Mutation.test.tsx +++ b/packages/swagger-faker/src/components/Mutation.test.tsx @@ -33,7 +33,7 @@ describe('', async () => { mapper: {}, seed: undefined, transformers: {}, - unknownType:"any" + unknownType: 'any', } const plugin = { options } as Plugin diff --git a/packages/swagger-ts/src/OperationGenerator.test.tsx b/packages/swagger-ts/src/OperationGenerator.test.tsx index 263e0d8ca..81237cfd7 100644 --- a/packages/swagger-ts/src/OperationGenerator.test.tsx +++ b/packages/swagger-ts/src/OperationGenerator.test.tsx @@ -93,7 +93,7 @@ describe('OperationGenerator', async () => { exclude: [], include: undefined, pluginManager: mockedPluginManager, - plugin: {} as KubbPlugin, + plugin: {} as Plugin, contentType: undefined, override: undefined, }, @@ -121,7 +121,7 @@ describe('OperationGenerator', async () => { exclude: [], include: undefined, pluginManager: mockedPluginManager, - plugin: {} as KubbPlugin, + plugin: {} as Plugin, contentType: undefined, override: undefined, }, diff --git a/packages/swagger-zod/src/OperationGenerator.test.tsx b/packages/swagger-zod/src/OperationGenerator.test.tsx index b6fd86b03..46e5ef0e7 100644 --- a/packages/swagger-zod/src/OperationGenerator.test.tsx +++ b/packages/swagger-zod/src/OperationGenerator.test.tsx @@ -3,7 +3,7 @@ import { OasManager } from '@kubb/swagger' import { OperationGenerator } from './OperationGenerator.tsx' -import type { KubbPlugin } from '@kubb/core' +import type { Plugin } from '@kubb/core' import type { GetOperationGeneratorOptions } from '@kubb/swagger' import type { PluginOptions } from './types.ts' @@ -31,7 +31,7 @@ describe('OperationGenerator', async () => { exclude: [], include: undefined, pluginManager: mockedPluginManager, - plugin: {} as KubbPlugin, + plugin: {} as Plugin, contentType: undefined, override: undefined, }, @@ -64,7 +64,7 @@ describe('OperationGenerator', async () => { exclude: [], include: undefined, pluginManager: mockedPluginManager, - plugin: {} as KubbPlugin, + plugin: {} as Plugin, contentType: undefined, override: undefined, }, @@ -93,7 +93,7 @@ describe('OperationGenerator', async () => { exclude: [], include: undefined, pluginManager: mockedPluginManager, - plugin: {} as KubbPlugin, + plugin: {} as Plugin, contentType: undefined, override: undefined, }, @@ -122,7 +122,7 @@ describe('OperationGenerator', async () => { exclude: [], include: undefined, pluginManager: mockedPluginManager, - plugin: {} as KubbPlugin, + plugin: {} as Plugin, contentType: undefined, override: undefined, }, diff --git a/packages/unplugin/package.json b/packages/unplugin/package.json index 09bb34993..bc7347bf9 100644 --- a/packages/unplugin/package.json +++ b/packages/unplugin/package.json @@ -135,9 +135,9 @@ "unplugin": "^1.6.0" }, "devDependencies": { + "@kubb/core": "workspace:*", "@kubb/eslint-config": "workspace:*", "@kubb/ts-config": "workspace:*", - "@kubb/core": "workspace:*", "@kubb/tsup-config": "workspace:*", "@nuxt/kit": "^3.9.3", "@nuxt/schema": "^3.9.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7be2559b9..757414095 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,8 +35,8 @@ importers: specifier: ^1.2.1 version: 1.2.1(vitest@1.2.1) bun-types: - specifier: ^1.0.23 - version: 1.0.23 + specifier: ^1.0.25 + version: 1.0.25 dprint: specifier: ^0.45.0 version: 0.45.0 @@ -44,8 +44,8 @@ importers: specifier: ^3.2.4 version: 3.2.4 prettier-eslint: - specifier: ^16.2.0 - version: 16.2.0 + specifier: ^16.3.0 + version: 16.3.0 rimraf: specifier: ^5.0.5 version: 5.0.5 @@ -123,17 +123,17 @@ importers: specifier: workspace:* version: link:../packages/swagger-zodios '@tanstack/react-query': - specifier: ^5.17.15 - version: 5.17.15(react@18.2.0) + specifier: ^5.17.19 + version: 5.17.19(react@18.2.0) '@tanstack/solid-query': - specifier: ^5.17.15 - version: 5.17.15(solid-js@1.8.11) + specifier: ^5.17.19 + version: 5.17.19(solid-js@1.8.11) '@tanstack/svelte-query': - specifier: ^5.17.15 - version: 5.17.15(svelte@3.59.2) + specifier: ^5.17.19 + version: 5.17.19(svelte@3.59.2) '@tanstack/vue-query': - specifier: ^5.17.15 - version: 5.17.15(vue@3.4.15) + specifier: ^5.17.19 + version: 5.17.19(vue@3.4.15) '@zodios/core': specifier: ^10.9.6 version: 10.9.6(axios@1.6.5)(zod@3.22.4) @@ -479,7 +479,7 @@ importers: version: 18.2.18 '@vitejs/plugin-react': specifier: ^4.2.1 - version: 4.2.1(vite@4.5.1) + version: 4.2.1(vite@4.5.2) msw: specifier: ^1.3.2 version: 1.3.2(typescript@5.2.2) @@ -487,8 +487,8 @@ importers: specifier: ~5.2.2 version: 5.2.2 vite: - specifier: ^4.5.1 - version: 4.5.1(@types/node@20.11.5) + specifier: ^4.5.2 + version: 4.5.2(@types/node@20.11.5) examples/react-query-v5: dependencies: @@ -511,11 +511,11 @@ importers: specifier: workspace:* version: link:../../packages/swagger-ts '@tanstack/react-query': - specifier: ^5.17.15 - version: 5.17.15(react@18.2.0) + specifier: ^5.17.19 + version: 5.17.19(react@18.2.0) '@tanstack/react-query-devtools': specifier: 5.0.0 - version: 5.0.0(@tanstack/react-query@5.17.15)(react-dom@18.2.0)(react@18.2.0) + version: 5.0.0(@tanstack/react-query@5.17.19)(react-dom@18.2.0)(react@18.2.0) axios: specifier: ^1.6.5 version: 1.6.5 @@ -537,7 +537,7 @@ importers: version: 18.2.18 '@vitejs/plugin-react': specifier: ^4.2.1 - version: 4.2.1(vite@4.5.1) + version: 4.2.1(vite@4.5.2) msw: specifier: ^1.3.2 version: 1.3.2(typescript@5.2.2) @@ -548,8 +548,8 @@ importers: specifier: workspace:* version: link:../../packages/unplugin vite: - specifier: ^4.5.1 - version: 4.5.1(@types/node@20.11.5) + specifier: ^4.5.2 + version: 4.5.2(@types/node@20.11.5) examples/simple-single: dependencies: @@ -760,7 +760,7 @@ importers: devDependencies: '@vitejs/plugin-vue': specifier: ^4.6.2 - version: 4.6.2(vite@4.5.1)(vue@3.4.15) + version: 4.6.2(vite@4.5.2)(vue@3.4.15) msw: specifier: ^1.3.2 version: 1.3.2(typescript@5.2.2) @@ -771,8 +771,8 @@ importers: specifier: ~5.2.2 version: 5.2.2 vite: - specifier: ^4.5.1 - version: 4.5.1(@types/node@20.11.5) + specifier: ^4.5.2 + version: 4.5.2(@types/node@20.11.5) examples/vue-query-v5: dependencies: @@ -798,8 +798,8 @@ importers: specifier: workspace:* version: link:../../packages/swagger-zod '@tanstack/vue-query': - specifier: ^5.17.15 - version: 5.17.15(vue@3.4.15) + specifier: ^5.17.19 + version: 5.17.19(vue@3.4.15) axios: specifier: ^1.6.5 version: 1.6.5 @@ -809,7 +809,7 @@ importers: devDependencies: '@vitejs/plugin-vue': specifier: ^4.6.2 - version: 4.6.2(vite@4.5.1)(vue@3.4.15) + version: 4.6.2(vite@4.5.2)(vue@3.4.15) msw: specifier: ^1.3.2 version: 1.3.2(typescript@5.2.2) @@ -820,8 +820,8 @@ importers: specifier: ~5.2.2 version: 5.2.2 vite: - specifier: ^4.5.1 - version: 4.5.1(@types/node@20.11.5) + specifier: ^4.5.2 + version: 4.5.2(@types/node@20.11.5) examples/zod: dependencies: @@ -3749,8 +3749,8 @@ packages: resolution: {integrity: sha512-DJSilV5+ytBP1FbFcEJovv4rnnm/CokuVvrBEtW/Va9DvuJ3HksbXUJEpI0aV1KtuL4ZoO9AVE6PyNLzF7tLeA==} dev: false - /@tanstack/query-core@5.17.15: - resolution: {integrity: sha512-QURxpu77/ICA4d61aPvV7EcJ2MwmksxUejKBaq/xLcO2TUJAlXf4PFKHC/WxnVFI/7F1jeLx85AO3Vpk0+uBXw==} + /@tanstack/query-core@5.17.19: + resolution: {integrity: sha512-Lzw8FUtnLCc9Jwz0sw9xOjZB+/mCCmJev38v2wHMUl/ioXNIhnNWeMxu0NKUjIhAd62IRB3eAtvxAGDJ55UkyA==} dev: false /@tanstack/query-devtools@5.0.0: @@ -3772,7 +3772,7 @@ packages: use-sync-external-store: 1.2.0(react@18.2.0) dev: false - /@tanstack/react-query-devtools@5.0.0(@tanstack/react-query@5.17.15)(react-dom@18.2.0)(react@18.2.0): + /@tanstack/react-query-devtools@5.0.0(@tanstack/react-query@5.17.19)(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-4yw29d89eOqUmliRKGmEOjuq2AGSM3i4jjw/YFMrErg0neVITy2bkoU3fPXZ339czlupqq0b4e20uFVtqkEqGQ==} peerDependencies: '@tanstack/react-query': ^5.0.0 @@ -3780,7 +3780,7 @@ packages: react-dom: ^18.0.0 dependencies: '@tanstack/query-devtools': 5.0.0 - '@tanstack/react-query': 5.17.15(react@18.2.0) + '@tanstack/react-query': 5.17.19(react@18.2.0) react: 18.2.0 react-dom: 18.2.0(react@18.2.0) dev: false @@ -3803,12 +3803,12 @@ packages: use-sync-external-store: 1.2.0(react@18.2.0) dev: false - /@tanstack/react-query@5.17.15(react@18.2.0): - resolution: {integrity: sha512-9qur91mOihaUN7pXm6ioDtS+4qgkBcCiIaZyvi3lZNcQZsrMGCYZ+eP3hiFrV4khoJyJrFUX1W0NcCVlgwNZxQ==} + /@tanstack/react-query@5.17.19(react@18.2.0): + resolution: {integrity: sha512-qaQENB6/03Gj3dFZGvdmUoqeUGlGm7P1p0RmaR04Bf1Ib1T9lLGimcC9T3oCFbrx0b2ZF21ngjFZNjj9uPJMcg==} peerDependencies: react: ^18.0.0 dependencies: - '@tanstack/query-core': 5.17.15 + '@tanstack/query-core': 5.17.19 react: 18.2.0 dev: false @@ -3821,12 +3821,12 @@ packages: solid-js: 1.8.11 dev: false - /@tanstack/solid-query@5.17.15(solid-js@1.8.11): - resolution: {integrity: sha512-O8RUqvv630MyU2PpUq7uMPO0nCL/RsIp4aLUGJclPovf9PvdgNuzQM0cFCYPHyegM2pZRjMK7Ek4wTAOKXdBhg==} + /@tanstack/solid-query@5.17.19(solid-js@1.8.11): + resolution: {integrity: sha512-MKvmksjpF91mfjFJ/QnvA3onSObl0mg/Gn8TS5LI+hNJbPy+X1qbDjt1/OrOSwmrnh5nGdEvjJbinoGpLPFLSg==} peerDependencies: solid-js: ^1.6.0 dependencies: - '@tanstack/query-core': 5.17.15 + '@tanstack/query-core': 5.17.19 solid-js: 1.8.11 dev: false @@ -3839,12 +3839,12 @@ packages: svelte: 3.59.2 dev: false - /@tanstack/svelte-query@5.17.15(svelte@3.59.2): - resolution: {integrity: sha512-pg2fpU05px00GsjZw5j5MYDXcianqPnRQQX/a4uGsyx/yyktqEplbs2aQgE1IJcJLZ/sER8ez2cwUgj3r0/sOg==} + /@tanstack/svelte-query@5.17.19(svelte@3.59.2): + resolution: {integrity: sha512-NVzko4m7i7kUO0DwJhru5MJFRhibNHODOyOi/k9sIpQw9jRfAuOK533shtkI5nmof3dD9kfpjfc08urLXh06eg==} peerDependencies: svelte: ^3.54.0 || ^4.0.0 || ^5.0.0-next.0 dependencies: - '@tanstack/query-core': 5.17.15 + '@tanstack/query-core': 5.17.19 svelte: 3.59.2 dev: false @@ -3864,8 +3864,8 @@ packages: vue-demi: 0.13.11(vue@3.4.15) dev: false - /@tanstack/vue-query@5.17.15(vue@3.4.15): - resolution: {integrity: sha512-Rw32liAftueRpB5Q9+qOtZ3LJhpeI9/TtRdVv2Gn1re9Um9Swvk0GbocGsPncire2gRexV0zJJ16LX1Dvnanjw==} + /@tanstack/vue-query@5.17.19(vue@3.4.15): + resolution: {integrity: sha512-8LsQmOy44qV1FxAPukjhdEYvcDoRq4P+PRkKeig7EsdfgaopxhSH+/GpxyDZiyEfU2Rg/JYQ3p88ufQYV424Sw==} peerDependencies: '@vue/composition-api': ^1.1.2 vue: ^2.6.0 || ^3.3.0 @@ -3874,7 +3874,7 @@ packages: optional: true dependencies: '@tanstack/match-sorter-utils': 8.8.4 - '@tanstack/query-core': 5.17.15 + '@tanstack/query-core': 5.17.19 '@vue/devtools-api': 6.5.1 vue: 3.4.15(typescript@5.2.2) vue-demi: 0.14.6(vue@3.4.15) @@ -4368,7 +4368,7 @@ packages: server-only: 0.0.1 dev: false - /@vitejs/plugin-react@4.2.1(vite@4.5.1): + /@vitejs/plugin-react@4.2.1(vite@4.5.2): resolution: {integrity: sha512-oojO9IDc4nCUUi8qIR11KoQm0XFFLIwsRBwHRR4d/88IWghn1y6ckz/bJ8GHDCsYEJee8mDzqtJxh15/cisJNQ==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: @@ -4379,19 +4379,19 @@ packages: '@babel/plugin-transform-react-jsx-source': 7.23.3(@babel/core@7.23.6) '@types/babel__core': 7.20.5 react-refresh: 0.14.0 - vite: 4.5.1(@types/node@20.11.5) + vite: 4.5.2(@types/node@20.11.5) transitivePeerDependencies: - supports-color dev: true - /@vitejs/plugin-vue@4.6.2(vite@4.5.1)(vue@3.4.15): + /@vitejs/plugin-vue@4.6.2(vite@4.5.2)(vue@3.4.15): resolution: {integrity: sha512-kqf7SGFoG+80aZG6Pf+gsZIVvGSCKE98JbiWqcCV9cThtg91Jav0yvYFC9Zb+jKetNGF6ZKeoaxgZfND21fWKw==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: vite: ^4.0.0 || ^5.0.0 vue: ^3.2.25 dependencies: - vite: 4.5.1(@types/node@20.11.5) + vite: 4.5.2(@types/node@20.11.5) vue: 3.4.15(typescript@5.2.2) dev: true @@ -5152,8 +5152,8 @@ packages: base64-js: 1.5.1 ieee754: 1.2.1 - /bun-types@1.0.23: - resolution: {integrity: sha512-K3eFQrZk2LWAdp7qcMz+m40Mz+RQc3jpgroQRlQqvQLSFL4qQ3tULBrKHzSwh0P9P7vyHbhyJ5IGKj/cmQFLGg==} + /bun-types@1.0.25: + resolution: {integrity: sha512-9lxeUR/OJsvlZH4GOWteiAdx7ikrSxCUX7Rr0JJux+DrR3LejouVLxIZnTeQ3UPAZovvSgKivWeHPJ2wlo7/Kg==} dependencies: '@types/node': 20.11.5 '@types/ws': 8.5.10 @@ -8573,15 +8573,6 @@ packages: ts-node: 10.9.2(@types/node@20.11.5)(typescript@5.3.3) yaml: 2.3.4 - /postcss@8.4.32: - resolution: {integrity: sha512-D/kj5JNu6oo2EIy+XL/26JEDTlIbB8hw85G8StOE6L74RQAVVP5rej6wxCNqyMbR4RkPfqvezVbPw81Ngd6Kcw==} - engines: {node: ^10 || ^12 || >=14} - dependencies: - nanoid: 3.3.7 - picocolors: 1.0.0 - source-map-js: 1.0.2 - dev: true - /postcss@8.4.33: resolution: {integrity: sha512-Kkpbhhdjw2qQs2O2DGX+8m5OVqEcbB9HRBvuYM9pgrjEFUg30A9LmXNlTAUj4S9kgtGyrMbTzVjH7E+s5Re2yg==} engines: {node: ^10 || ^12 || >=14} @@ -8608,9 +8599,17 @@ packages: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} - /prettier-eslint@16.2.0: - resolution: {integrity: sha512-GDTSKc62VaLceiaI/qMaKo2oco2CIWtbj4Zr6ckhbTgcBL/uR0d9jkMzh9OtBIT/Z7iBoCB4OHj/aJ5YuNgAuA==} + /prettier-eslint@16.3.0: + resolution: {integrity: sha512-Lh102TIFCr11PJKUMQ2kwNmxGhTsv/KzUg9QYF2Gkw259g/kPgndZDWavk7/ycbRvj2oz4BPZ1gCU8bhfZH/Xg==} engines: {node: '>=16.10.0'} + peerDependencies: + prettier-plugin-svelte: ^3.0.0 + svelte-eslint-parser: '*' + peerDependenciesMeta: + prettier-plugin-svelte: + optional: true + svelte-eslint-parser: + optional: true dependencies: '@typescript-eslint/parser': 6.15.0(eslint@8.56.0)(typescript@5.3.3) common-tags: 1.8.2 @@ -10325,8 +10324,8 @@ packages: - typescript dev: true - /vite@4.5.1(@types/node@20.11.5): - resolution: {integrity: sha512-AXXFaAJ8yebyqzoNB9fu2pHoo/nWX+xZlaRwoeYUxEqBO+Zj4msE5G+BhGBll9lYEKv9Hfks52PAF2X7qDYXQA==} + /vite@4.5.2(@types/node@20.11.5): + resolution: {integrity: sha512-tBCZBNSBbHQkaGyhGCDUGqeo2ph8Fstyp6FMSvTtsXeZSPpSMGlviAOav2hxVTqFcx8Hj/twtWKsMJXNY0xI8w==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true peerDependencies: @@ -10355,7 +10354,7 @@ packages: dependencies: '@types/node': 20.11.5 esbuild: 0.18.20 - postcss: 8.4.32 + postcss: 8.4.33 rollup: 3.29.4 optionalDependencies: fsevents: 2.3.3