[{"data":1,"prerenderedAt":754,"buildId":755},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":753,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-zod\u002Findex.md",{},"Zod",{"type":8,"value":9,"toc":744},"minimark",[10,14,33,38,138,168,172,186,236,240,389,393,407,737],[11,12,13],"p",{},"The Zod plugin generates a Zod v4 schema for every schema in your OpenAPI spec, plus the parameter, request, and response schemas of each operation.",[11,15,16,20,21,24,25,28,29,32],{},[17,18,19],"code",{},"@kubb\u002Fplugin-fetch",", ",[17,22,23],{},"@kubb\u002Fplugin-axios",", and ",[17,26,27],{},"@kubb\u002Fplugin-client"," validate with these schemas when you set their ",[17,30,31],{},"validator"," option.",[34,35,37],"h2",{"id":36},"installation","Installation",[39,40,42,65,85,103,121],"code-group",{"sync":41},"install",[43,44,49],"pre",{"language":45,"filename":46,"code":47,"class":48},"shell","kubb","kubb add plugin-zod","highlights",[17,50,52],{"class":51},"language-shell",[53,54,57,61],"span",{"class":55,"style":56},"line","display: inline",[53,58,60],{"style":59},"color:#6f42c1;--hls-dark:#b392f0","kubb ",[53,62,64],{"style":63},"color:#24292e;--hls-dark:#e1e4e8","add plugin-zod",[43,66,69],{"language":45,"filename":67,"code":68,"class":48},"bun","bun add -d @kubb\u002Fplugin-zod",[17,70,71],{"class":51},[53,72,73,76,79,82],{"class":55,"style":56},[53,74,75],{"style":59},"bun ",[53,77,78],{"style":63},"add -d ",[53,80,81],{"style":63},"@",[53,83,84],{"style":63},"kubb\u002Fplugin-zod",[43,86,89],{"language":45,"filename":87,"code":88,"class":48},"pnpm","pnpm add -D @kubb\u002Fplugin-zod",[17,90,91],{"class":51},[53,92,93,96,99,101],{"class":55,"style":56},[53,94,95],{"style":59},"pnpm ",[53,97,98],{"style":63},"add -D ",[53,100,81],{"style":63},[53,102,84],{"style":63},[43,104,107],{"language":45,"filename":105,"code":106,"class":48},"npm","npm install --save-dev @kubb\u002Fplugin-zod",[17,108,109],{"class":51},[53,110,111,114,117,119],{"class":55,"style":56},[53,112,113],{"style":59},"npm ",[53,115,116],{"style":63},"install --save-dev ",[53,118,81],{"style":63},[53,120,84],{"style":63},[43,122,125],{"language":45,"filename":123,"code":124,"class":48},"yarn","yarn add -D @kubb\u002Fplugin-zod",[17,126,127],{"class":51},[53,128,129,132,134,136],{"class":55,"style":56},[53,130,131],{"style":59},"yarn ",[53,133,98],{"style":63},[53,135,81],{"style":63},[53,137,84],{"style":63},[11,139,140,143,144,149,150,153,154,157,158,160,161,167],{},[17,141,142],{},"kubb add"," installs the version the ",[145,146,148],"a",{"href":147},"\u002Fregistry","Kubb registry"," pins and adds ",[17,151,152],{},"pluginZod()"," to ",[17,155,156],{},"kubb.config.ts",". It needs a ",[17,159,156],{},", so run ",[145,162,164],{"href":163},"\u002Fdocs\u002F5.x\u002Freference\u002Fcommands\u002Finit",[17,165,166],{},"kubb init"," first in a new project.",[34,169,171],{"id":170},"setup","Setup",[173,174,175,179],"ul",{},[176,177,178],"li",{},"No other plugins are needed.",[176,180,181,182,185],{},"Install ",[17,183,184],{},"zod"," v4 in the app that uses the generated code. Some options need a newer minor:",[187,188,189,202],"table",{},[190,191,192],"thead",{},[193,194,195,199],"tr",{},[196,197,198],"th",{},"Option",[196,200,201],{},"Needs",[203,204,205,216,226],"tbody",{},[193,206,207,213],{},[208,209,210],"td",{},[17,211,212],{},"oneOfType: 'xor'",[208,214,215],{},"Zod 4.2 or later",[193,217,218,223],{},[208,219,220],{},[17,221,222],{},"compile",[208,224,225],{},"Zod 4.5 or later",[193,227,228,233],{},[208,229,230],{},[17,231,232],{},"typeGuards",[208,234,235],{},"Zod 4.6 or later",[34,237,239],{"id":238},"options-worth-knowing","Options worth knowing",[187,241,242,254],{},[190,243,244],{},[193,245,246,248,251],{},[196,247,198],{},[196,249,250],{},"Default",[196,252,253],{},"What it does",[203,255,256,282,299,316,345,369],{},[193,257,258,266,271],{},[208,259,260],{},[145,261,263],{"href":262},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Foptions#inferred",[17,264,265],{},"inferred",[208,267,268],{},[17,269,270],{},"false",[208,272,273,274,277,278,281],{},"Adds a ",[17,275,276],{},"z.infer"," type next to each schema, so you can skip ",[17,279,280],{},"@kubb\u002Fplugin-ts",".",[193,283,284,292,296],{},[208,285,286],{},[145,287,289],{"href":288},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Foptions#mini",[17,290,291],{},"mini",[208,293,294],{},[17,295,270],{},[208,297,298],{},"Beta. Generates Zod Mini schemas for smaller bundles.",[193,300,301,309,313],{},[208,302,303],{},[145,304,306],{"href":305},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Foptions#coercion",[17,307,308],{},"coercion",[208,310,311],{},[17,312,270],{},[208,314,315],{},"Coerces input before validation, such as query strings.",[193,317,318,326,331],{},[208,319,320],{},[145,321,323],{"href":322},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Foptions#oneoftype",[17,324,325],{},"oneOfType",[208,327,328],{},[17,329,330],{},"'union'",[208,332,333,334,337,338,341,342,281],{},"Validates a ",[17,335,336],{},"oneOf"," with ",[17,339,340],{},"z.union"," or ",[17,343,344],{},"z.xor",[193,346,347,354,358],{},[208,348,349],{},[145,350,352],{"href":351},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Foptions#typeguards",[17,353,232],{},[208,355,356],{},[17,357,270],{},[208,359,360,361,364,365,368],{},"Adds ",[17,362,363],{},"is*"," type guards and ",[17,366,367],{},"assert*"," assertions.",[193,370,371,378,382],{},[208,372,373],{},[145,374,376],{"href":375},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Foptions#compile",[17,377,222],{},[208,379,380],{},[17,381,270],{},[208,383,384,385,388],{},"Wraps schemas in ",[17,386,387],{},"z.compile"," for faster validation.",[34,390,392],{"id":391},"example","Example",[11,394,395,396,398,399,402,403,406],{},"This config generates the schemas with a ",[17,397,276],{}," type next to each one. For a ",[17,400,401],{},"Pet"," schema, the plugin writes ",[17,404,405],{},"petSchema.ts",":",[39,408,409,548],{},[43,410,413],{"language":411,"filename":156,"code":412,"class":48},"typescript","import { defineConfig } from 'kubb\u002Fconfig'\nimport { pluginZod } from '@kubb\u002Fplugin-zod'\n\nexport default defineConfig({\n input: '.\u002FpetStore.yaml',\n output: { path: '.\u002Fsrc\u002Fgen' },\n plugins: [pluginZod({ inferred: true })],\n})",[17,414,416,439,440,439,456,439,458,439,472,439,489,439,513,439,543],{"class":415},"language-typescript",[53,417,418,422,426,429,432,435],{"class":55,"style":56},[53,419,421],{"style":420},"color:#d73a49;--hls-dark:#f97583","import ",[53,423,425],{"style":424},"color:#005cc5;--hls-dark:#79b8ff","{ ",[53,427,428],{"style":63},"defineConfig ",[53,430,431],{"style":424},"} ",[53,433,434],{"style":420},"from ",[53,436,438],{"style":437},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[53,441,442,444,446,449,451,453],{"class":55,"style":56},[53,443,421],{"style":420},[53,445,425],{"style":424},[53,447,448],{"style":63},"pluginZod ",[53,450,431],{"style":424},[53,452,434],{"style":420},[53,454,455],{"style":437},"'@kubb\u002Fplugin-zod'",[53,457],{"class":55,"style":56},[53,459,460,463,466,469],{"class":55,"style":56},[53,461,462],{"style":420},"export ",[53,464,465],{"style":420},"default ",[53,467,468],{"style":59},"defineConfig",[53,470,471],{"style":424},"({",[53,473,474,477,480,483,486],{"class":55,"style":56},[53,475,476],{"style":424}," ",[53,478,479],{"style":424},"input",[53,481,482],{"style":420},": ",[53,484,485],{"style":437},"'.\u002FpetStore.yaml'",[53,487,488],{"style":420},",",[53,490,491,493,496,498,500,503,505,508,511],{"class":55,"style":56},[53,492,476],{"style":420},[53,494,495],{"style":424},"output",[53,497,482],{"style":420},[53,499,425],{"style":424},[53,501,502],{"style":424},"path",[53,504,482],{"style":420},[53,506,507],{"style":437},"'.\u002Fsrc\u002Fgen' ",[53,509,510],{"style":424},"}",[53,512,488],{"style":420},[53,514,515,517,520,522,525,528,531,533,535,538,541],{"class":55,"style":56},[53,516,476],{"style":420},[53,518,519],{"style":424},"plugins",[53,521,482],{"style":420},[53,523,524],{"style":424},"[",[53,526,527],{"style":59},"pluginZod",[53,529,530],{"style":424},"({ ",[53,532,265],{"style":424},[53,534,482],{"style":420},[53,536,537],{"style":424},"true ",[53,539,540],{"style":424},"})]",[53,542,488],{"style":420},[53,544,545],{"class":55,"style":56},[53,546,547],{"style":424},"})",[43,549,552],{"language":411,"filename":550,"code":551,"class":48},"src\u002Fgen\u002Fzod\u002FpetSchema.ts","import * as z from 'zod'\n\nexport const petSchema = z.object({\n id: z.int(),\n name: z.string(),\n status: z.string().optional(),\n tags: z.array(z.string()).optional(),\n})\n\nexport type PetSchemaType = z.infer\u003Ctypeof petSchema>",[17,553,554,439,572,439,574,439,597,439,618,439,638,439,664,439,700,439,704,439,706],{"class":415},[53,555,556,558,561,564,567,569],{"class":55,"style":56},[53,557,421],{"style":420},[53,559,560],{"style":420},"* ",[53,562,563],{"style":420},"as ",[53,565,566],{"style":63},"z ",[53,568,434],{"style":420},[53,570,571],{"style":437},"'zod'",[53,573],{"class":55,"style":56},[53,575,576,578,581,584,587,590,592,595],{"class":55,"style":56},[53,577,462],{"style":420},[53,579,580],{"style":420},"const ",[53,582,583],{"style":63},"petSchema ",[53,585,586],{"style":420},"= ",[53,588,589],{"style":63},"z",[53,591,281],{"style":420},[53,593,594],{"style":59},"object",[53,596,471],{"style":424},[53,598,599,601,604,606,608,610,613,616],{"class":55,"style":56},[53,600,476],{"style":424},[53,602,603],{"style":424},"id",[53,605,482],{"style":420},[53,607,589],{"style":63},[53,609,281],{"style":420},[53,611,612],{"style":59},"int",[53,614,615],{"style":424},"()",[53,617,488],{"style":420},[53,619,620,622,625,627,629,631,634,636],{"class":55,"style":56},[53,621,476],{"style":420},[53,623,624],{"style":424},"name",[53,626,482],{"style":420},[53,628,589],{"style":63},[53,630,281],{"style":420},[53,632,633],{"style":59},"string",[53,635,615],{"style":424},[53,637,488],{"style":420},[53,639,640,642,645,647,649,651,653,655,657,660,662],{"class":55,"style":56},[53,641,476],{"style":420},[53,643,644],{"style":424},"status",[53,646,482],{"style":420},[53,648,589],{"style":63},[53,650,281],{"style":420},[53,652,633],{"style":59},[53,654,615],{"style":424},[53,656,281],{"style":420},[53,658,659],{"style":59},"optional",[53,661,615],{"style":424},[53,663,488],{"style":420},[53,665,666,668,671,673,675,677,680,683,685,687,689,692,694,696,698],{"class":55,"style":56},[53,667,476],{"style":420},[53,669,670],{"style":424},"tags",[53,672,482],{"style":420},[53,674,589],{"style":63},[53,676,281],{"style":420},[53,678,679],{"style":59},"array",[53,681,682],{"style":424},"(",[53,684,589],{"style":63},[53,686,281],{"style":420},[53,688,633],{"style":59},[53,690,691],{"style":424},"())",[53,693,281],{"style":420},[53,695,659],{"style":59},[53,697,615],{"style":424},[53,699,488],{"style":420},[53,701,702],{"class":55,"style":56},[53,703,547],{"style":424},[53,705],{"class":55,"style":56},[53,707,708,710,713,716,718,720,722,725,728,731,734],{"class":55,"style":56},[53,709,462],{"style":420},[53,711,712],{"style":420},"type ",[53,714,715],{"style":59},"PetSchemaType ",[53,717,586],{"style":420},[53,719,589],{"style":63},[53,721,281],{"style":420},[53,723,724],{"style":424},"infer",[53,726,727],{"style":420},"\u003C",[53,729,730],{"style":420},"typeof ",[53,732,733],{"style":63},"petSchema",[53,735,736],{"style":420},">",[11,738,739,740,281],{},"Next, ",[145,741,743],{"href":742},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Fguides\u002Fcustomization","customize the generated schemas",{"title":745,"searchDepth":746,"depth":746,"links":747},"",5,[748,750,751,752],{"id":36,"depth":749,"text":37},2,{"id":170,"depth":749,"text":171},{"id":238,"depth":749,"text":239},{"id":391,"depth":749,"text":392},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod",1795560936627,"4aa54817-6028-4256-a400-aed5c7c81dee"]