@kubb/plugin-zod 3.0.0-beta.1 → 3.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/{chunk-FLFW72FT.cjs → chunk-37OP7TSO.cjs} +45 -35
  2. package/dist/chunk-37OP7TSO.cjs.map +1 -0
  3. package/dist/{chunk-5PR4KKK7.js → chunk-OOAUU32I.js} +3 -3
  4. package/dist/chunk-OOAUU32I.js.map +1 -0
  5. package/dist/{chunk-6MMPQJME.cjs → chunk-QEYWJ6VH.cjs} +6 -6
  6. package/dist/chunk-QEYWJ6VH.cjs.map +1 -0
  7. package/dist/{chunk-UONLSRDV.js → chunk-SSOO3TXR.js} +45 -35
  8. package/dist/chunk-SSOO3TXR.js.map +1 -0
  9. package/dist/components.cjs +3 -3
  10. package/dist/components.d.cts +1 -1
  11. package/dist/components.d.ts +1 -1
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +4 -4
  14. package/dist/generators.d.cts +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +4 -4
  18. package/dist/index.d.cts +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +2 -2
  21. package/dist/{types-ryu2n1NA.d.cts → types-L1fXCZAs.d.cts} +7 -2
  22. package/dist/{types-ryu2n1NA.d.ts → types-L1fXCZAs.d.ts} +7 -2
  23. package/package.json +12 -12
  24. package/src/components/Zod.tsx +4 -2
  25. package/src/generators/__snapshots__/coercion.ts +3 -0
  26. package/src/generators/__snapshots__/coercionDates.ts +3 -0
  27. package/src/generators/__snapshots__/coercionNumbers.ts +3 -0
  28. package/src/generators/__snapshots__/coercionStrings.ts +3 -0
  29. package/src/generators/__snapshots__/createPet.ts +1 -1
  30. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +1 -1
  31. package/src/generators/__snapshots__/getPets.ts +2 -5
  32. package/src/generators/__snapshots__/operations.ts +0 -3
  33. package/src/generators/__snapshots__/showPetById.ts +1 -4
  34. package/src/parser/index.ts +46 -34
  35. package/src/types.ts +9 -2
  36. package/dist/chunk-5PR4KKK7.js.map +0 -1
  37. package/dist/chunk-6MMPQJME.cjs.map +0 -1
  38. package/dist/chunk-FLFW72FT.cjs.map +0 -1
  39. package/dist/chunk-UONLSRDV.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/Operations.tsx","../src/parser/index.ts","../src/components/Zod.tsx"],"names":["transformers","siblings","value","isKeyword","schemaKeywords","jsxs","Fragment","jsx","File","Const"],"mappings":";;;;;;AAYO,SAAS,UAAW,CAAA,EAAE,IAAM,EAAA,UAAA,EAA+B,EAAA;AAChE,EAAA,MAAM,iBAAiB,UAAW,CAAA,MAAA;AAAA,IAChC,CAAC,MAAM,GAAQ,KAAA;AACb,MAAA,IAAA,CAAK,IAAI,GAAI,CAAA,SAAA,CAAU,gBAAgB,CAAA,CAAA,CAAG,IAAI,GAAI,CAAA,IAAA;AAElD,MAAO,OAAA,IAAA;AAAA,KACT;AAAA,IACA;AAAC,GACH;AAEA,EAAA,MAAM,YAAY,UAAW,CAAA,MAAA;AAAA,IAC3B,CAAC,MAAM,GAAQ,KAAA;AACb,MAAA,IAAA,CAAK,CAAI,CAAA,EAAA,GAAA,CAAI,SAAU,CAAA,IAAI,GAAG,CAAI,GAAA;AAAA,QAChC,GAAI,KAAK,CAAI,CAAA,EAAA,GAAA,CAAI,UAAU,IAAI,CAAA,CAAA,CAAG,KAAM,EAAC;AAAA,QACzC,CAAC,IAAI,SAAU,CAAA,MAAM,GAAG,CAAe,YAAA,EAAA,GAAA,CAAI,SAAU,CAAA,cAAA,EAAgB,CAAA,EAAA;AAAA,OACvE;AAEA,MAAO,OAAA,IAAA;AAAA,KACT;AAAA,IACA;AAAC,GACH;AAEA,EAAA,uBAEI,IAAA,CAAA,QAAA,EAAA,EAAA,QAAA,EAAA;AAAA,oBAAC,GAAA,CAA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,IAAA,CAAK,EAAE,CAAK,IAAA;AAAA;AAAA,KAEnB,EAAA,CAAA;AAAA,IACC,aAAA,oBACCO,GAAAA,CAACC,IAAK,CAAA,MAAA,EAAL,EAAY,IAAM,EAAA,aAAA,EAAe,YAAY,EAAA,IAAA,EAAC,WAAW,EAAA,IAAA,EAAC,YAAU,IACnE,EAAA,QAAA,kBAAAD,GAAC,CAAA,IAAA,EAAA,EAAK,MAAM,EAAA,IAAA,EAAC,MAAM,aAChB,EAAA,QAAA,EAAA,CAAA,eAAA,EAAkB,IAAI,CAAA,CAAA,CAAA,EACzB,CACF,EAAA;AAAA,GAEJ,EAAA,CAAA;AAEJ","file":"chunk-SSOO3TXR.js","sourcesContent":["import type { SchemaNames } from '@kubb/plugin-oas/hooks'\nimport { Const, File } from '@kubb/react'\n\nimport transformers from '@kubb/core/transformers'\nimport type { HttpMethod, Operation } from '@kubb/oas'\nimport type { KubbNode } from '@kubb/react/types'\n\ntype Props = {\n name: string\n operations: Array<{ operation: Operation; data: SchemaNames }>\n}\n\nexport function Operations({ name, operations }: Props): KubbNode {\n const operationsJSON = operations.reduce(\n (prev, acc) => {\n prev[`\"${acc.operation.getOperationId()}\"`] = acc.data\n\n return prev\n },\n {} as Record<string, unknown>,\n )\n\n const pathsJSON = operations.reduce(\n (prev, acc) => {\n prev[`\"${acc.operation.path}\"`] = {\n ...(prev[`\"${acc.operation.path}\"`] || ({} as Record<HttpMethod, string>)),\n [acc.operation.method]: `operations[\"${acc.operation.getOperationId()}\"]`,\n }\n\n return prev\n },\n {} as Record<string, Record<HttpMethod, string>>,\n )\n\n return (\n <>\n <File.Source name={name} isExportable isIndexable>\n <Const export name={name} asConst>\n {`{${transformers.stringifyObject(operationsJSON)}}`}\n </Const>\n </File.Source>\n <File.Source name={'paths'} isExportable isIndexable>\n <Const export name={'paths'} asConst>\n {`{${transformers.stringifyObject(pathsJSON)}}`}\n </Const>\n </File.Source>\n </>\n )\n}\n","import transformers, { createJSDocBlockText } from '@kubb/core/transformers'\nimport { type SchemaKeywordMapper, type SchemaTree, isKeyword, schemaKeywords } from '@kubb/plugin-oas'\n\nimport type { Schema, SchemaKeywordBase, SchemaMapper } from '@kubb/plugin-oas'\n\nconst zodKeywordMapper = {\n any: () => 'z.any()',\n unknown: () => 'z.unknown()',\n number: (coercion?: boolean, min?: number, max?: number) => {\n return [coercion ? 'z.coerce.number()' : 'z.number()', min !== undefined ? `.min(${min})` : undefined, max !== undefined ? `.max(${max})` : undefined]\n .filter(Boolean)\n .join('')\n },\n integer: (coercion?: boolean, min?: number, max?: number) => {\n return [\n coercion ? 'z.coerce.number().int()' : 'z.number().int()',\n min !== undefined ? `.min(${min})` : undefined,\n max !== undefined ? `.max(${max})` : undefined,\n ]\n .filter(Boolean)\n .join('')\n },\n object: (value?: string) => `z.object({${value}})`,\n string: (coercion?: boolean, min?: number, max?: number) => {\n return [coercion ? 'z.coerce.string()' : 'z.string()', min !== undefined ? `.min(${min})` : undefined, max !== undefined ? `.max(${max})` : undefined]\n .filter(Boolean)\n .join('')\n },\n boolean: () => 'z.boolean()',\n undefined: () => 'z.undefined()',\n nullable: () => '.nullable()',\n null: () => 'z.null()',\n nullish: () => '.nullish()',\n array: (items: string[] = [], min?: number, max?: number) => {\n return [`z.array(${items?.join('')})`, min !== undefined ? `.min(${min})` : undefined, max !== undefined ? `.max(${max})` : undefined]\n .filter(Boolean)\n .join('')\n },\n tuple: (items: string[] = []) => `z.tuple([${items?.join(', ')}])`,\n enum: (items: string[] = []) => `z.enum([${items?.join(', ')}])`,\n union: (items: string[] = []) => `z.union([${items?.join(', ')}])`,\n const: (value?: string | number | boolean) => `z.literal(${value ?? ''})`,\n /**\n * ISO 8601\n */\n datetime: (offset = false, local = false) => {\n if (offset) {\n return `z.string().datetime({ offset: ${offset} })`\n }\n\n if (local) {\n return `z.string().datetime({ local: ${local} })`\n }\n\n return 'z.string().datetime()'\n },\n /**\n * Type `'date'` Date\n * Type `'string'` ISO date format (YYYY-MM-DD)\n * @default ISO date format (YYYY-MM-DD)\n */\n date: (type: 'date' | 'string' = 'string', coercion?: boolean) => {\n if (type === 'string') {\n return 'z.string().date()'\n }\n\n if (coercion) {\n return 'z.coerce.date()'\n }\n\n return 'z.date()'\n },\n /**\n * Type `'date'` Date\n * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])\n * @default ISO time format (HH:mm:ss[.SSSSSS])\n */\n time: (type: 'date' | 'string' = 'string', coercion?: boolean) => {\n if (type === 'string') {\n return 'z.string().time()'\n }\n\n if (coercion) {\n return 'z.coerce.date()'\n }\n\n return 'z.date()'\n },\n uuid: () => '.uuid()',\n url: () => '.url()',\n strict: () => '.strict()',\n default: (value?: string | number | true) => `.default(${value ?? ''})`,\n and: (items: string[] = []) => items?.map((item) => `.and(${item})`).join(''),\n describe: (value = '') => `.describe(${value})`,\n min: (value?: number) => `.min(${value ?? ''})`,\n max: (value?: number) => `.max(${value ?? ''})`,\n optional: () => '.optional()',\n matches: (value = '') => `.regex(${value})`,\n email: () => '.email()',\n firstName: undefined,\n lastName: undefined,\n password: undefined,\n phone: undefined,\n readOnly: undefined,\n writeOnly: undefined,\n ref: (value?: string) => (value ? `z.lazy(() => ${value})` : undefined),\n blob: () => 'z.string()',\n deprecated: undefined,\n example: undefined,\n schema: undefined,\n catchall: (value?: string) => (value ? `.catchall(${value})` : undefined),\n name: undefined,\n} satisfies SchemaMapper<string | null | undefined>\n\n/**\n * @link based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n */\n\nexport function sort(items?: Schema[]): Schema[] {\n const order: string[] = [\n schemaKeywords.string,\n schemaKeywords.datetime,\n schemaKeywords.date,\n schemaKeywords.time,\n schemaKeywords.tuple,\n schemaKeywords.number,\n schemaKeywords.object,\n schemaKeywords.enum,\n schemaKeywords.url,\n schemaKeywords.email,\n schemaKeywords.firstName,\n schemaKeywords.lastName,\n schemaKeywords.password,\n schemaKeywords.matches,\n schemaKeywords.uuid,\n schemaKeywords.min,\n schemaKeywords.max,\n schemaKeywords.default,\n schemaKeywords.describe,\n schemaKeywords.optional,\n schemaKeywords.nullable,\n schemaKeywords.nullish,\n schemaKeywords.null,\n ]\n\n if (!items) {\n return []\n }\n\n return transformers.orderBy(items, [(v) => order.indexOf(v.keyword)], ['asc'])\n}\n\nconst shouldCoerce = (coercion: ParserOptions['coercion'] | undefined, type: 'dates' | 'strings' | 'numbers'): boolean => {\n if (coercion === undefined) {\n return false\n }\n if (typeof coercion === 'boolean') {\n return coercion\n }\n\n return !!coercion[type]\n}\n\ntype ParserOptions = {\n name: string\n typeName?: string\n description?: string\n keysToOmit?: string[]\n mapper?: Record<string, string>\n coercion?: boolean | { dates?: boolean; strings?: boolean; numbers?: boolean }\n}\n\nexport function parse({ parent, current, siblings }: SchemaTree, options: ParserOptions): string | undefined {\n const value = zodKeywordMapper[current.keyword as keyof typeof zodKeywordMapper]\n\n if (!value) {\n return undefined\n }\n\n if (isKeyword(current, schemaKeywords.union)) {\n // zod union type needs at least 2 items\n if (Array.isArray(current.args) && current.args.length === 1) {\n return parse({ parent, current: current.args[0] as Schema, siblings }, options)\n }\n if (Array.isArray(current.args) && !current.args.length) {\n return ''\n }\n\n return zodKeywordMapper.union(\n sort(current.args)\n .map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))\n .filter(Boolean),\n )\n }\n\n if (isKeyword(current, schemaKeywords.and)) {\n const items = sort(current.args)\n .filter((schema: Schema) => {\n return ![schemaKeywords.optional, schemaKeywords.describe].includes(schema.keyword as typeof schemaKeywords.describe)\n })\n .map((schema: Schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))\n .filter(Boolean)\n\n return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`\n }\n\n if (isKeyword(current, schemaKeywords.array)) {\n return zodKeywordMapper.array(\n sort(current.args.items)\n .map((schemas, _index, siblings) => parse({ parent: current, current: schemas, siblings }, options))\n .filter(Boolean),\n current.args.min,\n current.args.max,\n )\n }\n\n if (isKeyword(current, schemaKeywords.enum)) {\n if (current.args.asConst) {\n if (current.args.items.length === 1) {\n const child = {\n keyword: schemaKeywords.const,\n args: current.args.items[0],\n }\n return parse({ parent: current, current: child, siblings: [child] }, options)\n }\n\n return zodKeywordMapper.union(\n current.args.items\n .map((schema) => ({\n keyword: schemaKeywords.const,\n args: schema,\n }))\n .map((schema, _index, siblings) => {\n return parse({ parent: current, current: schema, siblings }, options)\n })\n .filter(Boolean),\n )\n }\n\n return zodKeywordMapper.enum(\n current.args.items.map((schema) => {\n if (schema.format === 'boolean') {\n return transformers.stringify(schema.value)\n }\n\n if (schema.format === 'number') {\n return transformers.stringify(schema.value)\n }\n return transformers.stringify(schema.value)\n }),\n )\n }\n\n if (isKeyword(current, schemaKeywords.ref)) {\n return zodKeywordMapper.ref(current.args?.name)\n }\n\n if (isKeyword(current, schemaKeywords.object)) {\n const properties = Object.entries(current.args?.properties || {})\n .filter((item) => {\n const schema = item[1]\n return schema && typeof schema.map === 'function'\n })\n .map(([name, schemas]) => {\n const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name) as SchemaKeywordMapper['name']\n const mappedName = nameSchema?.args || name\n\n // custom mapper(pluginOptions)\n if (options.mapper?.[mappedName]) {\n return `\"${name}\": ${options.mapper?.[mappedName]}`\n }\n\n return `\"${name}\": ${sort(schemas)\n .map((schema, array, siblings) => {\n return parse({ parent: current, current: schema, siblings }, options)\n })\n .filter(Boolean)\n .join('')}`\n })\n .join(',')\n\n const additionalProperties = current.args?.additionalProperties?.length\n ? current.args.additionalProperties\n .map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))\n .filter(Boolean)\n .join('')\n : undefined\n\n const text = [\n zodKeywordMapper.object(properties),\n current.args?.strict ? zodKeywordMapper.strict() : undefined,\n additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : undefined,\n ].filter(Boolean)\n\n return text.join('')\n }\n\n if (isKeyword(current, schemaKeywords.tuple)) {\n return zodKeywordMapper.tuple(\n current.args.items.map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options)).filter(Boolean),\n )\n }\n\n if (isKeyword(current, schemaKeywords.const)) {\n if (current.args.format === 'number' && current.args.value !== undefined) {\n return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()))\n }\n\n if (current.args.format === 'boolean' && current.args.value !== undefined) {\n return zodKeywordMapper.const(current.args.value)\n }\n return zodKeywordMapper.const(transformers.stringify(current.args.value))\n }\n\n if (isKeyword(current, schemaKeywords.matches)) {\n if (current.args) {\n return zodKeywordMapper.matches(transformers.toRegExpString(current.args))\n }\n }\n\n if (isKeyword(current, schemaKeywords.default)) {\n if (current.args) {\n return zodKeywordMapper.default(current.args)\n }\n }\n\n if (isKeyword(current, schemaKeywords.describe)) {\n if (current.args) {\n return zodKeywordMapper.describe(transformers.stringify(current.args.toString()))\n }\n }\n\n if (isKeyword(current, schemaKeywords.string)) {\n return zodKeywordMapper.string(shouldCoerce(options.coercion, 'strings'))\n }\n\n if (isKeyword(current, schemaKeywords.number)) {\n return zodKeywordMapper.number(shouldCoerce(options.coercion, 'numbers'))\n }\n\n if (isKeyword(current, schemaKeywords.integer)) {\n return zodKeywordMapper.integer(shouldCoerce(options.coercion, 'numbers'))\n }\n\n if (isKeyword(current, schemaKeywords.min)) {\n return zodKeywordMapper.min(current.args)\n }\n if (isKeyword(current, schemaKeywords.max)) {\n return zodKeywordMapper.max(current.args)\n }\n\n if (isKeyword(current, schemaKeywords.datetime)) {\n return zodKeywordMapper.datetime(current.args.offset, current.args.local)\n }\n\n if (isKeyword(current, schemaKeywords.date)) {\n return zodKeywordMapper.date(current.args.type, shouldCoerce(options.coercion, 'dates'))\n }\n\n if (isKeyword(current, schemaKeywords.time)) {\n return zodKeywordMapper.time(current.args.type, shouldCoerce(options.coercion, 'dates'))\n }\n\n if (current.keyword in zodKeywordMapper && 'args' in current) {\n const value = zodKeywordMapper[current.keyword as keyof typeof zodKeywordMapper] as (typeof zodKeywordMapper)['const']\n\n return value((current as SchemaKeywordBase<unknown>).args as any)\n }\n\n if (isKeyword(current, schemaKeywords.optional)) {\n if (siblings.some((schema) => isKeyword(schema, schemaKeywords.default))) return ''\n\n return value()\n }\n\n if (current.keyword in zodKeywordMapper) {\n return value()\n }\n\n return undefined\n}\n","import transformers from '@kubb/core/transformers'\nimport { type Schema, schemaKeywords } from '@kubb/plugin-oas'\nimport { isKeyword } from '@kubb/plugin-oas'\nimport { Const, File, Type } from '@kubb/react'\nimport type { KubbNode } from '@kubb/react/types'\nimport * as parserZod from '../parser/index.ts'\nimport type { PluginZod } from '../types.ts'\n\ntype Props = {\n name: string\n typeName?: string\n inferTypeName?: string\n tree: Array<Schema>\n description?: string\n coercion: PluginZod['resolvedOptions']['coercion']\n mapper: PluginZod['resolvedOptions']['mapper']\n keysToOmit?: string[]\n}\n\nexport function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }: Props): KubbNode {\n const hasTuple = tree.some((item) => isKeyword(item, schemaKeywords.tuple))\n\n const output = parserZod\n .sort(tree)\n .filter((item) => {\n if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {\n return false\n }\n\n return true\n })\n .map((schema, _index, siblings) =>\n parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName: typeName, description, mapper, coercion }),\n )\n .filter(Boolean)\n .join('')\n\n const suffix = output.endsWith('.nullable()') ? '.unwrap().and' : '.and'\n\n return (\n <>\n <File.Source name={name} isExportable isIndexable>\n <Const\n export\n name={name}\n JSDoc={{\n comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),\n }}\n >\n {[\n output,\n keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined,\n typeName ? ` as z.ZodType<${typeName}>` : '',\n ]\n .filter(Boolean)\n .join('') || 'z.undefined()'}\n </Const>\n </File.Source>\n {inferTypeName && (\n <File.Source name={inferTypeName} isExportable isIndexable isTypeOnly>\n <Type export name={inferTypeName}>\n {`z.infer<typeof ${name}>`}\n </Type>\n </File.Source>\n )}\n </>\n )\n}\n"]}
@@ -1,16 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var chunkFLFW72FT_cjs = require('./chunk-FLFW72FT.cjs');
3
+ var chunk37OP7TSO_cjs = require('./chunk-37OP7TSO.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "Operations", {
8
8
  enumerable: true,
9
- get: function () { return chunkFLFW72FT_cjs.Operations; }
9
+ get: function () { return chunk37OP7TSO_cjs.Operations; }
10
10
  });
11
11
  Object.defineProperty(exports, "Zod", {
12
12
  enumerable: true,
13
- get: function () { return chunkFLFW72FT_cjs.Zod; }
13
+ get: function () { return chunk37OP7TSO_cjs.Zod; }
14
14
  });
15
15
  //# sourceMappingURL=components.cjs.map
16
16
  //# sourceMappingURL=components.cjs.map
@@ -2,7 +2,7 @@ import { SchemaNames } from '@kubb/plugin-oas/hooks';
2
2
  import { Operation } from '@kubb/oas';
3
3
  import { KubbNode } from '@kubb/react/types';
4
4
  import { Schema } from '@kubb/plugin-oas';
5
- import { P as PluginZod } from './types-ryu2n1NA.cjs';
5
+ import { P as PluginZod } from './types-L1fXCZAs.cjs';
6
6
  import '@kubb/core';
7
7
 
8
8
  type Props$1 = {
@@ -2,7 +2,7 @@ import { SchemaNames } from '@kubb/plugin-oas/hooks';
2
2
  import { Operation } from '@kubb/oas';
3
3
  import { KubbNode } from '@kubb/react/types';
4
4
  import { Schema } from '@kubb/plugin-oas';
5
- import { P as PluginZod } from './types-ryu2n1NA.js';
5
+ import { P as PluginZod } from './types-L1fXCZAs.js';
6
6
  import '@kubb/core';
7
7
 
8
8
  type Props$1 = {
@@ -1,3 +1,3 @@
1
- export { Operations, Zod } from './chunk-UONLSRDV.js';
1
+ export { Operations, Zod } from './chunk-SSOO3TXR.js';
2
2
  //# sourceMappingURL=components.js.map
3
3
  //# sourceMappingURL=components.js.map
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunk6MMPQJME_cjs = require('./chunk-6MMPQJME.cjs');
4
- require('./chunk-FLFW72FT.cjs');
3
+ var chunkQEYWJ6VH_cjs = require('./chunk-QEYWJ6VH.cjs');
4
+ require('./chunk-37OP7TSO.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "operationsGenerator", {
9
9
  enumerable: true,
10
- get: function () { return chunk6MMPQJME_cjs.operationsGenerator; }
10
+ get: function () { return chunkQEYWJ6VH_cjs.operationsGenerator; }
11
11
  });
12
12
  Object.defineProperty(exports, "zodGenerator", {
13
13
  enumerable: true,
14
- get: function () { return chunk6MMPQJME_cjs.zodGenerator; }
14
+ get: function () { return chunkQEYWJ6VH_cjs.zodGenerator; }
15
15
  });
16
16
  //# sourceMappingURL=generators.cjs.map
17
17
  //# sourceMappingURL=generators.cjs.map
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginZod } from './types-ryu2n1NA.cjs';
2
+ import { P as PluginZod } from './types-L1fXCZAs.cjs';
3
3
  import '@kubb/core';
4
4
  import '@kubb/oas';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginZod } from './types-ryu2n1NA.js';
2
+ import { P as PluginZod } from './types-L1fXCZAs.js';
3
3
  import '@kubb/core';
4
4
  import '@kubb/oas';
5
5
 
@@ -1,4 +1,4 @@
1
- export { operationsGenerator, zodGenerator } from './chunk-5PR4KKK7.js';
2
- import './chunk-UONLSRDV.js';
1
+ export { operationsGenerator, zodGenerator } from './chunk-OOAUU32I.js';
2
+ import './chunk-SSOO3TXR.js';
3
3
  //# sourceMappingURL=generators.js.map
4
4
  //# sourceMappingURL=generators.js.map
package/dist/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunk6MMPQJME_cjs = require('./chunk-6MMPQJME.cjs');
4
- require('./chunk-FLFW72FT.cjs');
3
+ var chunkQEYWJ6VH_cjs = require('./chunk-QEYWJ6VH.cjs');
4
+ require('./chunk-37OP7TSO.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "pluginZod", {
9
9
  enumerable: true,
10
- get: function () { return chunk6MMPQJME_cjs.pluginZod; }
10
+ get: function () { return chunkQEYWJ6VH_cjs.pluginZod; }
11
11
  });
12
12
  Object.defineProperty(exports, "pluginZodName", {
13
13
  enumerable: true,
14
- get: function () { return chunk6MMPQJME_cjs.pluginZodName; }
14
+ get: function () { return chunkQEYWJ6VH_cjs.pluginZodName; }
15
15
  });
16
16
  //# sourceMappingURL=index.cjs.map
17
17
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginZod } from './types-ryu2n1NA.cjs';
2
+ import { O as Options, P as PluginZod } from './types-L1fXCZAs.cjs';
3
3
  import '@kubb/oas';
4
4
  import '@kubb/plugin-oas';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginZod } from './types-ryu2n1NA.js';
2
+ import { O as Options, P as PluginZod } from './types-L1fXCZAs.js';
3
3
  import '@kubb/oas';
4
4
  import '@kubb/plugin-oas';
5
5
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { pluginZod, pluginZodName } from './chunk-5PR4KKK7.js';
2
- import './chunk-UONLSRDV.js';
1
+ export { pluginZod, pluginZodName } from './chunk-OOAUU32I.js';
2
+ import './chunk-SSOO3TXR.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
@@ -52,8 +52,13 @@ type Options = {
52
52
  inferred?: boolean;
53
53
  /**
54
54
  * Use of z.coerce.string() instead of z.string()
55
+ * can also be an object to enable coercion for dates, strings, and numbers
55
56
  */
56
- coercion?: boolean;
57
+ coercion?: boolean | {
58
+ dates?: boolean;
59
+ strings?: boolean;
60
+ numbers?: boolean;
61
+ };
57
62
  operations?: boolean;
58
63
  mapper?: Record<string, string>;
59
64
  transformers?: {
@@ -88,7 +93,7 @@ type ResolvedOptions = {
88
93
  mapper: NonNullable<Options['mapper']>;
89
94
  importPath: NonNullable<Options['importPath']>;
90
95
  coercion: NonNullable<Options['coercion']>;
91
- operations: NonNullable<Options['coercion']>;
96
+ operations: NonNullable<Options['operations']>;
92
97
  };
93
98
  type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
94
99
 
@@ -52,8 +52,13 @@ type Options = {
52
52
  inferred?: boolean;
53
53
  /**
54
54
  * Use of z.coerce.string() instead of z.string()
55
+ * can also be an object to enable coercion for dates, strings, and numbers
55
56
  */
56
- coercion?: boolean;
57
+ coercion?: boolean | {
58
+ dates?: boolean;
59
+ strings?: boolean;
60
+ numbers?: boolean;
61
+ };
57
62
  operations?: boolean;
58
63
  mapper?: Record<string, string>;
59
64
  transformers?: {
@@ -88,7 +93,7 @@ type ResolvedOptions = {
88
93
  mapper: NonNullable<Options['mapper']>;
89
94
  importPath: NonNullable<Options['importPath']>;
90
95
  coercion: NonNullable<Options['coercion']>;
91
- operations: NonNullable<Options['coercion']>;
96
+ operations: NonNullable<Options['operations']>;
92
97
  };
93
98
  type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
94
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-zod",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.10",
4
4
  "description": "Generator plugin-zod",
5
5
  "keywords": [
6
6
  "typescript",
@@ -58,21 +58,21 @@
58
58
  "!/**/__tests__/**"
59
59
  ],
60
60
  "dependencies": {
61
- "@kubb/core": "3.0.0-beta.1",
62
- "@kubb/fs": "3.0.0-beta.1",
63
- "@kubb/oas": "3.0.0-beta.1",
64
- "@kubb/parser-ts": "3.0.0-beta.1",
65
- "@kubb/plugin-oas": "3.0.0-beta.1",
66
- "@kubb/plugin-ts": "3.0.0-beta.1",
67
- "@kubb/react": "3.0.0-beta.1"
61
+ "@kubb/core": "3.0.0-beta.10",
62
+ "@kubb/fs": "3.0.0-beta.10",
63
+ "@kubb/oas": "3.0.0-beta.10",
64
+ "@kubb/plugin-oas": "3.0.0-beta.10",
65
+ "@kubb/parser-ts": "3.0.0-beta.10",
66
+ "@kubb/plugin-ts": "3.0.0-beta.10",
67
+ "@kubb/react": "3.0.0-beta.10"
68
68
  },
69
69
  "devDependencies": {
70
- "tsup": "^8.3.0",
71
- "@kubb/config-ts": "3.0.0-beta.1",
72
- "@kubb/config-tsup": "3.0.0-beta.1"
70
+ "tsup": "^8.3.5",
71
+ "@kubb/config-ts": "3.0.0-beta.10",
72
+ "@kubb/config-tsup": "3.0.0-beta.10"
73
73
  },
74
74
  "peerDependencies": {
75
- "@kubb/react": "3.0.0-beta.1"
75
+ "@kubb/react": "3.0.0-beta.10"
76
76
  },
77
77
  "engines": {
78
78
  "node": ">=20"
@@ -29,7 +29,9 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key
29
29
 
30
30
  return true
31
31
  })
32
- .map((item) => parserZod.parse(undefined, item, { name, keysToOmit, typeName: typeName, description, mapper, coercion }))
32
+ .map((schema, _index, siblings) =>
33
+ parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName: typeName, description, mapper, coercion }),
34
+ )
33
35
  .filter(Boolean)
34
36
  .join('')
35
37
 
@@ -51,7 +53,7 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key
51
53
  typeName ? ` as z.ZodType<${typeName}>` : '',
52
54
  ]
53
55
  .filter(Boolean)
54
- .join('') || ''}
56
+ .join('') || 'z.undefined()'}
55
57
  </Const>
56
58
  </File.Source>
57
59
  {inferTypeName && (
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+
3
+ export const pet = z.object({ "id": z.coerce.number().int(), "name": z.coerce.string(), "date": z.coerce.date().optional(), "tag": z.coerce.string().min(5).max(100).optional() });
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+
3
+ export const pet = z.object({ "id": z.number().int(), "name": z.string(), "date": z.coerce.date().optional(), "tag": z.string().min(5).max(100).optional() });
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+
3
+ export const pet = z.object({ "id": z.coerce.number().int(), "name": z.string(), "date": z.date().optional(), "tag": z.string().min(5).max(100).optional() });
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+
3
+ export const pet = z.object({ "id": z.number().int(), "name": z.coerce.string(), "date": z.date().optional(), "tag": z.coerce.string().min(5).max(100).optional() });
@@ -12,4 +12,4 @@ export const createPetsError = z.lazy(() => error);
12
12
 
13
13
  export const createPetsMutationRequest = z.object({ "name": z.string(), "tag": z.string() });
14
14
 
15
- export const createPetsMutationResponse = z.any();
15
+ export const createPetsMutationResponse = z.lazy(() => createPets201);
@@ -12,4 +12,4 @@ export const createPetsError = z.lazy(() => error);
12
12
 
13
13
  export const createPetsMutationRequest = z.object({ "name": z.string(), "tag": z.string() });
14
14
 
15
- export const createPetsMutationResponse = z.unknown();
15
+ export const createPetsMutationResponse = z.lazy(() => createPets201);
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
 
3
- export const listPetsQueryParams = z.object({ "limit": z.string().describe("How many items to return at one time (max 100)").optional() }).optional();
3
+ export const listPetsQueryParams = z.object({ "limit": z.string().describe("How many items to return at one time (max 100)").optional(), "offset": z.number().int().default(0) }).optional();
4
4
 
5
5
  /**
6
6
  * @description A paged array of pets
@@ -12,7 +12,4 @@ export const listPets200 = z.lazy(() => pets);
12
12
  */
13
13
  export const listPetsError = z.lazy(() => error);
14
14
 
15
- /**
16
- * @description A paged array of pets
17
- */
18
- export const listPetsQueryResponse = z.lazy(() => pets);
15
+ export const listPetsQueryResponse = z.lazy(() => listPets200);
@@ -8,7 +8,6 @@ import { listPetsQueryResponse, listPetsQueryParams, createPetsMutationRequest,
8
8
  header: undefined
9
9
  },
10
10
  responses: {
11
- 200: listPetsQueryResponse,
12
11
  default: listPetsQueryResponse
13
12
  },
14
13
  errors: {}
@@ -20,7 +19,6 @@ import { listPetsQueryResponse, listPetsQueryParams, createPetsMutationRequest,
20
19
  header: undefined
21
20
  },
22
21
  responses: {
23
- 201: createPetsMutationResponse,
24
22
  default: createPetsMutationResponse
25
23
  },
26
24
  errors: {}
@@ -32,7 +30,6 @@ import { listPetsQueryResponse, listPetsQueryParams, createPetsMutationRequest,
32
30
  header: undefined
33
31
  },
34
32
  responses: {
35
- 200: showPetByIdQueryResponse,
36
33
  default: showPetByIdQueryResponse
37
34
  },
38
35
  errors: {}
@@ -12,7 +12,4 @@ export const showPetById200 = z.lazy(() => pet);
12
12
  */
13
13
  export const showPetByIdError = z.lazy(() => error);
14
14
 
15
- /**
16
- * @description Expected response to a valid request
17
- */
18
- export const showPetByIdQueryResponse = z.lazy(() => pet);
15
+ export const showPetByIdQueryResponse = z.lazy(() => showPetById200);
@@ -1,5 +1,5 @@
1
1
  import transformers, { createJSDocBlockText } from '@kubb/core/transformers'
2
- import { type SchemaKeywordMapper, isKeyword, schemaKeywords } from '@kubb/plugin-oas'
2
+ import { type SchemaKeywordMapper, type SchemaTree, isKeyword, schemaKeywords } from '@kubb/plugin-oas'
3
3
 
4
4
  import type { Schema, SchemaKeywordBase, SchemaMapper } from '@kubb/plugin-oas'
5
5
 
@@ -150,17 +150,27 @@ export function sort(items?: Schema[]): Schema[] {
150
150
  return transformers.orderBy(items, [(v) => order.indexOf(v.keyword)], ['asc'])
151
151
  }
152
152
 
153
+ const shouldCoerce = (coercion: ParserOptions['coercion'] | undefined, type: 'dates' | 'strings' | 'numbers'): boolean => {
154
+ if (coercion === undefined) {
155
+ return false
156
+ }
157
+ if (typeof coercion === 'boolean') {
158
+ return coercion
159
+ }
160
+
161
+ return !!coercion[type]
162
+ }
163
+
153
164
  type ParserOptions = {
154
165
  name: string
155
166
  typeName?: string
156
167
  description?: string
157
-
158
168
  keysToOmit?: string[]
159
169
  mapper?: Record<string, string>
160
- coercion?: boolean
170
+ coercion?: boolean | { dates?: boolean; strings?: boolean; numbers?: boolean }
161
171
  }
162
172
 
163
- export function parse(parent: Schema | undefined, current: Schema, options: ParserOptions): string | undefined {
173
+ export function parse({ parent, current, siblings }: SchemaTree, options: ParserOptions): string | undefined {
164
174
  const value = zodKeywordMapper[current.keyword as keyof typeof zodKeywordMapper]
165
175
 
166
176
  if (!value) {
@@ -170,7 +180,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
170
180
  if (isKeyword(current, schemaKeywords.union)) {
171
181
  // zod union type needs at least 2 items
172
182
  if (Array.isArray(current.args) && current.args.length === 1) {
173
- return parse(parent, current.args[0] as Schema, options)
183
+ return parse({ parent, current: current.args[0] as Schema, siblings }, options)
174
184
  }
175
185
  if (Array.isArray(current.args) && !current.args.length) {
176
186
  return ''
@@ -178,7 +188,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
178
188
 
179
189
  return zodKeywordMapper.union(
180
190
  sort(current.args)
181
- .map((schema) => parse(current, schema, options))
191
+ .map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))
182
192
  .filter(Boolean),
183
193
  )
184
194
  }
@@ -188,7 +198,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
188
198
  .filter((schema: Schema) => {
189
199
  return ![schemaKeywords.optional, schemaKeywords.describe].includes(schema.keyword as typeof schemaKeywords.describe)
190
200
  })
191
- .map((schema: Schema) => parse(current, schema, options))
201
+ .map((schema: Schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))
192
202
  .filter(Boolean)
193
203
 
194
204
  return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`
@@ -197,7 +207,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
197
207
  if (isKeyword(current, schemaKeywords.array)) {
198
208
  return zodKeywordMapper.array(
199
209
  sort(current.args.items)
200
- .map((schemas) => parse(current, schemas, options))
210
+ .map((schemas, _index, siblings) => parse({ parent: current, current: schemas, siblings }, options))
201
211
  .filter(Boolean),
202
212
  current.args.min,
203
213
  current.args.max,
@@ -207,27 +217,21 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
207
217
  if (isKeyword(current, schemaKeywords.enum)) {
208
218
  if (current.args.asConst) {
209
219
  if (current.args.items.length === 1) {
210
- return parse(
211
- current,
212
- {
213
- keyword: schemaKeywords.const,
214
- args: current.args.items[0],
215
- },
216
- options,
217
- )
220
+ const child = {
221
+ keyword: schemaKeywords.const,
222
+ args: current.args.items[0],
223
+ }
224
+ return parse({ parent: current, current: child, siblings: [child] }, options)
218
225
  }
219
226
 
220
227
  return zodKeywordMapper.union(
221
228
  current.args.items
222
- .map((schema) => {
223
- return parse(
224
- current,
225
- {
226
- keyword: schemaKeywords.const,
227
- args: schema,
228
- },
229
- options,
230
- )
229
+ .map((schema) => ({
230
+ keyword: schemaKeywords.const,
231
+ args: schema,
232
+ }))
233
+ .map((schema, _index, siblings) => {
234
+ return parse({ parent: current, current: schema, siblings }, options)
231
235
  })
232
236
  .filter(Boolean),
233
237
  )
@@ -267,8 +271,8 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
267
271
  }
268
272
 
269
273
  return `"${name}": ${sort(schemas)
270
- .map((schema, array) => {
271
- return parse(current, schema, options)
274
+ .map((schema, array, siblings) => {
275
+ return parse({ parent: current, current: schema, siblings }, options)
272
276
  })
273
277
  .filter(Boolean)
274
278
  .join('')}`
@@ -277,7 +281,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
277
281
 
278
282
  const additionalProperties = current.args?.additionalProperties?.length
279
283
  ? current.args.additionalProperties
280
- .map((schema) => parse(current, schema, options))
284
+ .map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))
281
285
  .filter(Boolean)
282
286
  .join('')
283
287
  : undefined
@@ -292,7 +296,9 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
292
296
  }
293
297
 
294
298
  if (isKeyword(current, schemaKeywords.tuple)) {
295
- return zodKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean))
299
+ return zodKeywordMapper.tuple(
300
+ current.args.items.map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options)).filter(Boolean),
301
+ )
296
302
  }
297
303
 
298
304
  if (isKeyword(current, schemaKeywords.const)) {
@@ -325,15 +331,15 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
325
331
  }
326
332
 
327
333
  if (isKeyword(current, schemaKeywords.string)) {
328
- return zodKeywordMapper.string(options.coercion)
334
+ return zodKeywordMapper.string(shouldCoerce(options.coercion, 'strings'))
329
335
  }
330
336
 
331
337
  if (isKeyword(current, schemaKeywords.number)) {
332
- return zodKeywordMapper.number(options.coercion)
338
+ return zodKeywordMapper.number(shouldCoerce(options.coercion, 'numbers'))
333
339
  }
334
340
 
335
341
  if (isKeyword(current, schemaKeywords.integer)) {
336
- return zodKeywordMapper.integer(options.coercion)
342
+ return zodKeywordMapper.integer(shouldCoerce(options.coercion, 'numbers'))
337
343
  }
338
344
 
339
345
  if (isKeyword(current, schemaKeywords.min)) {
@@ -348,11 +354,11 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
348
354
  }
349
355
 
350
356
  if (isKeyword(current, schemaKeywords.date)) {
351
- return zodKeywordMapper.date(current.args.type, options.coercion)
357
+ return zodKeywordMapper.date(current.args.type, shouldCoerce(options.coercion, 'dates'))
352
358
  }
353
359
 
354
360
  if (isKeyword(current, schemaKeywords.time)) {
355
- return zodKeywordMapper.time(current.args.type, options.coercion)
361
+ return zodKeywordMapper.time(current.args.type, shouldCoerce(options.coercion, 'dates'))
356
362
  }
357
363
 
358
364
  if (current.keyword in zodKeywordMapper && 'args' in current) {
@@ -361,6 +367,12 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
361
367
  return value((current as SchemaKeywordBase<unknown>).args as any)
362
368
  }
363
369
 
370
+ if (isKeyword(current, schemaKeywords.optional)) {
371
+ if (siblings.some((schema) => isKeyword(schema, schemaKeywords.default))) return ''
372
+
373
+ return value()
374
+ }
375
+
364
376
  if (current.keyword in zodKeywordMapper) {
365
377
  return value()
366
378
  }
package/src/types.ts CHANGED
@@ -53,8 +53,15 @@ export type Options = {
53
53
  inferred?: boolean
54
54
  /**
55
55
  * Use of z.coerce.string() instead of z.string()
56
+ * can also be an object to enable coercion for dates, strings, and numbers
56
57
  */
57
- coercion?: boolean
58
+ coercion?:
59
+ | boolean
60
+ | {
61
+ dates?: boolean
62
+ strings?: boolean
63
+ numbers?: boolean
64
+ }
58
65
  operations?: boolean
59
66
  mapper?: Record<string, string>
60
67
  transformers?: {
@@ -93,7 +100,7 @@ type ResolvedOptions = {
93
100
  mapper: NonNullable<Options['mapper']>
94
101
  importPath: NonNullable<Options['importPath']>
95
102
  coercion: NonNullable<Options['coercion']>
96
- operations: NonNullable<Options['coercion']>
103
+ operations: NonNullable<Options['operations']>
97
104
  }
98
105
 
99
106
  export type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>