[{"data":1,"prerenderedAt":474},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":473,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-zod\u002Findex.md",{},"Zod",{"type":8,"value":9,"toc":464},"minimark",[10,14,34,39,125,146,150,172,176,294,302,306,312],[11,12,13],"p",{},"The Zod plugin generates a Zod v4 schema for every schema in your OpenAPI spec.",[11,15,16,17,21,22,25,26,29,30,33],{},"The client plugins ",[18,19,20],"code",{},"@kubb\u002Fplugin-fetch",", ",[18,23,24],{},"@kubb\u002Fplugin-axios",", and ",[18,27,28],{},"@kubb\u002Fplugin-client"," use these schemas when you set their ",[18,31,32],{},"validator"," option.",[35,36,38],"h2",{"id":37},"installation","Installation",[40,41,43,72,90,108],"code-group",{"sync":42},"package-manager",[44,45,50],"pre",{"language":46,"filename":47,"code":48,"class":49},"shell","bun","bun add -d @kubb\u002Fplugin-zod","highlights",[18,51,53],{"class":52},"language-shell",[54,55,58,62,66,69],"span",{"class":56,"style":57},"line","display: inline",[54,59,61],{"style":60},"color:#6f42c1;--hls-dark:#b392f0","bun ",[54,63,65],{"style":64},"color:#24292e;--hls-dark:#e1e4e8","add -d ",[54,67,68],{"style":64},"@",[54,70,71],{"style":64},"kubb\u002Fplugin-zod",[44,73,76],{"language":46,"filename":74,"code":75,"class":49},"pnpm","pnpm add -D @kubb\u002Fplugin-zod",[18,77,78],{"class":52},[54,79,80,83,86,88],{"class":56,"style":57},[54,81,82],{"style":60},"pnpm ",[54,84,85],{"style":64},"add -D ",[54,87,68],{"style":64},[54,89,71],{"style":64},[44,91,94],{"language":46,"filename":92,"code":93,"class":49},"npm","npm install --save-dev @kubb\u002Fplugin-zod",[18,95,96],{"class":52},[54,97,98,101,104,106],{"class":56,"style":57},[54,99,100],{"style":60},"npm ",[54,102,103],{"style":64},"install --save-dev ",[54,105,68],{"style":64},[54,107,71],{"style":64},[44,109,112],{"language":46,"filename":110,"code":111,"class":49},"yarn","yarn add -D @kubb\u002Fplugin-zod",[18,113,114],{"class":52},[54,115,116,119,121,123],{"class":56,"style":57},[54,117,118],{"style":60},"yarn ",[54,120,85],{"style":64},[54,122,68],{"style":64},[54,124,71],{"style":64},[11,126,127,128,131,132,137,138,141,142,145],{},"Or run ",[18,129,130],{},"kubb add plugin-zod"," to install the version the ",[133,134,136],"a",{"href":135},"\u002Fregistry","Kubb registry"," pins and add ",[18,139,140],{},"pluginZod()"," to ",[18,143,144],{},"kubb.config.ts",".",[35,147,149],{"id":148},"setup","Setup",[151,152,153,157],"ul",{},[154,155,156],"li",{},"No other plugins are needed.",[154,158,159,160,163,164,167,168,171],{},"Install ",[18,161,162],{},"zod"," v4 in the app that uses the generated code. ",[18,165,166],{},"compile"," needs 4.5 or later, and ",[18,169,170],{},"typeGuards"," needs 4.6 or later.",[35,173,175],{"id":174},"options-worth-knowing","Options worth knowing",[151,177,178,190,201,214,224,241,255,273,286],{},[154,179,180,183,184,141,187,145],{},[18,181,182],{},"mini"," (beta) generates Zod Mini schemas for smaller bundles, and switches ",[18,185,186],{},"importPath",[18,188,189],{},"zod\u002Fmini",[154,191,192,194,195,198,199,145],{},[18,193,186],{}," sets the module the generated files import ",[18,196,197],{},"z"," from. The default is ",[18,200,162],{},[154,202,203,206,207,210,211,145],{},[18,204,205],{},"inferred"," adds a ",[18,208,209],{},"z.infer"," type next to each schema, so you can skip ",[18,212,213],{},"@kubb\u002Fplugin-ts",[154,215,216,219,220,223],{},[18,217,218],{},"coercion"," wraps schemas in ",[18,221,222],{},"z.coerce",", so input is converted before validation. Pass an object to coerce only dates, strings, or numbers.",[154,225,226,229,230,233,234,237,238,145],{},[18,227,228],{},"guidType"," picks ",[18,231,232],{},"z.uuid()"," (default) or ",[18,235,236],{},"z.guid()"," for ",[18,239,240],{},"format: uuid",[154,242,243,246,247,250,251,254],{},[18,244,245],{},"regexType"," writes a ",[18,248,249],{},"pattern"," as a regex literal (default) or a ",[18,252,253],{},"RegExp"," constructor.",[154,256,257,260,261,264,265,268,269,272],{},[18,258,259],{},"oneOfType"," validates a ",[18,262,263],{},"oneOf"," with ",[18,266,267],{},"z.union"," and strict object members (default) or with ",[18,270,271],{},"z.xor",", which needs exactly one member to match.",[154,274,275,277,278,281,282,285],{},[18,276,170],{}," adds ",[18,279,280],{},"is*"," type guards and ",[18,283,284],{},"assert*"," assertions.",[154,287,288,219,290,293],{},[18,289,166],{},[18,291,292],{},"z.compile"," for faster validation. Circular schemas are left as they are.",[11,295,296,297,301],{},"See ",[133,298,300],{"href":299},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Foptions","Options"," for every option and its default.",[35,303,305],{"id":304},"example","Example",[11,307,308,309,311],{},"The config below generates the schemas with a ",[18,310,209],{}," type next to each one.",[44,313,316],{"language":314,"filename":144,"code":315,"class":49},"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: [\n    pluginZod({ inferred: true }),\n  ],\n})",[18,317,319,342,343,342,359,342,361,342,375,342,392,342,416,342,428,342,451,342,460],{"class":318},"language-typescript",[54,320,321,325,329,332,335,338],{"class":56,"style":57},[54,322,324],{"style":323},"color:#d73a49;--hls-dark:#f97583","import ",[54,326,328],{"style":327},"color:#005cc5;--hls-dark:#79b8ff","{ ",[54,330,331],{"style":64},"defineConfig ",[54,333,334],{"style":327},"} ",[54,336,337],{"style":323},"from ",[54,339,341],{"style":340},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[54,344,345,347,349,352,354,356],{"class":56,"style":57},[54,346,324],{"style":323},[54,348,328],{"style":327},[54,350,351],{"style":64},"pluginZod ",[54,353,334],{"style":327},[54,355,337],{"style":323},[54,357,358],{"style":340},"'@kubb\u002Fplugin-zod'",[54,360],{"class":56,"style":57},[54,362,363,366,369,372],{"class":56,"style":57},[54,364,365],{"style":323},"export ",[54,367,368],{"style":323},"default ",[54,370,371],{"style":60},"defineConfig",[54,373,374],{"style":327},"({",[54,376,377,380,383,386,389],{"class":56,"style":57},[54,378,379],{"style":327},"  ",[54,381,382],{"style":327},"input",[54,384,385],{"style":323},": ",[54,387,388],{"style":340},"'.\u002FpetStore.yaml'",[54,390,391],{"style":323},",",[54,393,394,396,399,401,403,406,408,411,414],{"class":56,"style":57},[54,395,379],{"style":323},[54,397,398],{"style":327},"output",[54,400,385],{"style":323},[54,402,328],{"style":327},[54,404,405],{"style":327},"path",[54,407,385],{"style":323},[54,409,410],{"style":340},"'.\u002Fsrc\u002Fgen' ",[54,412,413],{"style":327},"}",[54,415,391],{"style":323},[54,417,418,420,423,425],{"class":56,"style":57},[54,419,379],{"style":323},[54,421,422],{"style":327},"plugins",[54,424,385],{"style":323},[54,426,427],{"style":327},"[",[54,429,430,433,436,439,441,443,446,449],{"class":56,"style":57},[54,431,432],{"style":327},"    ",[54,434,435],{"style":60},"pluginZod",[54,437,438],{"style":327},"({ ",[54,440,205],{"style":327},[54,442,385],{"style":323},[54,444,445],{"style":327},"true ",[54,447,448],{"style":327},"})",[54,450,391],{"style":323},[54,452,453,455,458],{"class":56,"style":57},[54,454,379],{"style":323},[54,456,457],{"style":327},"]",[54,459,391],{"style":323},[54,461,462],{"class":56,"style":57},[54,463,448],{"style":327},{"title":465,"searchDepth":466,"depth":466,"links":467},"",5,[468,470,471,472],{"id":37,"depth":469,"text":38},2,{"id":148,"depth":469,"text":149},{"id":174,"depth":469,"text":175},{"id":304,"depth":469,"text":305},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod",1793647023764]