[{"data":1,"prerenderedAt":375},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Fguides\u002Fcompiled-schemas":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":374,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-zod\u002Fguides\u002Fcompiled-schemas.md",{},"Compile Zod schemas",{"type":8,"value":9,"toc":366},"minimark",[10,23,28,45,210,268,272,278,321,325,339,358],[11,12,13,14,18,19,22],"p",{},"Set ",[15,16,17],"code",{},"compile"," to wrap generated schemas in ",[15,20,21],{},"z.compile(...)"," for faster validation, and see which schemas stay on the interpreter. Needs Zod 4.5 or later.",[24,25,27],"h2",{"id":26},"turn-on-compile","Turn on compile",[11,29,30,31,34,35,38,39,44],{},"Pass ",[15,32,33],{},"true",", or ",[15,36,37],{},"{ strict: true }"," to make Zod throw when a part cannot be compiled. The ",[40,41,43],"a",{"href":42},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Fguides\u002Fcompiled-schemas#schemas-that-stay-uncompiled","schemas that stay uncompiled"," are not wrapped, so they raise no error.",[46,47,48,108],"code-group",{},[49,50,55],"pre",{"language":51,"filename":52,"code":53,"class":54},"typescript","kubb.config.ts","import { pluginZod } from '@kubb\u002Fplugin-zod'\n\npluginZod({ compile: true })","highlights",[15,56,58,85,86,85,88],{"class":57},"language-typescript",[59,60,63,67,71,75,78,81],"span",{"class":61,"style":62},"line","display: inline",[59,64,66],{"style":65},"color:#d73a49;--hls-dark:#f97583","import ",[59,68,70],{"style":69},"color:#005cc5;--hls-dark:#79b8ff","{ ",[59,72,74],{"style":73},"color:#24292e;--hls-dark:#e1e4e8","pluginZod ",[59,76,77],{"style":69},"} ",[59,79,80],{"style":65},"from ",[59,82,84],{"style":83},"color:#032f62;--hls-dark:#9ecbff","'@kubb\u002Fplugin-zod'","\n",[59,87],{"class":61,"style":62},[59,89,90,94,97,99,102,105],{"class":61,"style":62},[59,91,93],{"style":92},"color:#6f42c1;--hls-dark:#b392f0","pluginZod",[59,95,96],{"style":69},"({ ",[59,98,17],{"style":69},[59,100,101],{"style":65},": ",[59,103,104],{"style":69},"true ",[59,106,107],{"style":69},"})",[49,109,112],{"language":51,"filename":110,"code":111,"class":54},"src\u002Fgen\u002Fzod\u002FpetSchema.ts","export const petSchema = z.compile(\n  z.object({\n    id: z.int(),\n    name: z.string(),\n  }),\n)",[15,113,114,85,139,85,154,85,177,85,197,85,205],{"class":57},[59,115,116,119,122,125,128,131,134,136],{"class":61,"style":62},[59,117,118],{"style":65},"export ",[59,120,121],{"style":65},"const ",[59,123,124],{"style":73},"petSchema ",[59,126,127],{"style":65},"= ",[59,129,130],{"style":73},"z",[59,132,133],{"style":65},".",[59,135,17],{"style":92},[59,137,138],{"style":69},"(",[59,140,141,144,146,148,151],{"class":61,"style":62},[59,142,143],{"style":69},"  ",[59,145,130],{"style":73},[59,147,133],{"style":65},[59,149,150],{"style":92},"object",[59,152,153],{"style":69},"({",[59,155,156,159,162,164,166,168,171,174],{"class":61,"style":62},[59,157,158],{"style":69},"    ",[59,160,161],{"style":69},"id",[59,163,101],{"style":65},[59,165,130],{"style":73},[59,167,133],{"style":65},[59,169,170],{"style":92},"int",[59,172,173],{"style":69},"()",[59,175,176],{"style":65},",",[59,178,179,181,184,186,188,190,193,195],{"class":61,"style":62},[59,180,158],{"style":65},[59,182,183],{"style":69},"name",[59,185,101],{"style":65},[59,187,130],{"style":73},[59,189,133],{"style":65},[59,191,192],{"style":92},"string",[59,194,173],{"style":69},[59,196,176],{"style":65},[59,198,199,201,203],{"class":61,"style":62},[59,200,143],{"style":65},[59,202,107],{"style":69},[59,204,176],{"style":65},[59,206,207],{"class":61,"style":62},[59,208,209],{"style":69},")",[211,212,213,226],"table",{},[214,215,216],"thead",{},[217,218,219,223],"tr",{},[220,221,222],"th",{},"Value",[220,224,225],{},"Effect",[227,228,229,241,253],"tbody",{},[217,230,231,238],{},[232,233,234,237],"td",{},[15,235,236],{},"false"," (default)",[232,239,240],{},"Leaves schemas uncompiled.",[217,242,243,247],{},[232,244,245],{},[15,246,33],{},[232,248,249,250,252],{},"Compiles schemas with ",[15,251,21],{},". A part that cannot be compiled falls back to the interpreter.",[217,254,255,259],{},[232,256,257],{},[15,258,37],{},[232,260,261,262,264,265,267],{},"Passes ",[15,263,37],{}," to ",[15,266,21],{},", so Zod throws when a part cannot be compiled into flat JavaScript. Schemas Kubb leaves uncompiled raise no error.",[24,269,271],{"id":270},"schemas-that-stay-uncompiled","Schemas that stay uncompiled",[11,273,274,275,277],{},"Kubb leaves these schemas without ",[15,276,21],{},":",[279,280,281,289,300],"ul",{},[282,283,284,285,288],"li",{},"Schemas with circular references (",[15,286,287],{},"z.lazy",").",[282,290,291,292,295,296,299],{},"Bare ",[15,293,294],{},"$ref"," response aliases. An alias that adds a description, such as ",[15,297,298],{},"petSchema.describe('A pet')",", is compiled.",[282,301,302,303,306,307,310,311,314,315,317,318,133],{},"With ",[15,304,305],{},"strict: true",", a ",[15,308,309],{},"z.coerce"," or ",[15,312,313],{},"z.xor"," schema, a union with such a member, and a schema that reaches a circular one through a ",[15,316,294],{},". The module then loads without a ",[15,319,320],{},"ZodCompileUnsupportedError",[24,322,324],{"id":323},"coerced-and-int64-fields","Coerced and int64 fields",[11,326,327,328,331,332,338],{},"Every ",[15,329,330],{},"format: int64"," schema is coerced, and so is every schema that ",[40,333,335],{"href":334},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Fguides\u002Fcoercion",[15,336,337],{},"coercion"," covers.",[279,340,341,344],{},[282,342,343],{},"An object or array that holds a coerced field is still compiled, and Zod runs that field on its interpreter.",[282,345,346,347,350,351,357],{},"To compile an ",[15,348,349],{},"int64"," schema, set ",[40,352,354],{"href":353},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fadapter-oas\u002Foptions#integertype",[15,355,356],{},"integerType: 'number'"," on the adapter.",[11,359,360,361,133],{},"For every option value, see ",[40,362,364],{"href":363},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Foptions#compile",[15,365,17],{},{"title":367,"searchDepth":368,"depth":368,"links":369},"",5,[370,372,373],{"id":26,"depth":371,"text":27},2,{"id":270,"depth":371,"text":271},{"id":323,"depth":371,"text":324},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Fguides\u002Fcompiled-schemas",1794776439454]