[{"data":1,"prerenderedAt":640},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Fhow-to\u002Fprinters":3},{"id":4,"title":5,"body":6,"description":625,"extension":626,"frontmatter":627,"heading":5,"meta":632,"navigation":633,"order":619,"path":634,"seo":635,"sitemap":636,"source":637,"stem":638,"__hash__":639},"docs\u002Fdocs\u002F5.x\u002Fhow-to\u002Fprinters.md","Customize generated code with printers",{"type":7,"value":8,"toc":617},"minimark",[9,18,44,49,67,194,212,216,226,321,331,487,510,514,520],[10,11,12,13,17],"p",{},"Set ",[14,15,16],"code",{},"printer.nodes"," on TypeScript, Zod, or Faker plugins to change how schema types are emitted. Override only the handlers you need.",[10,19,20,21,24,25,28,29,32,33,38,39,43],{},"Write handlers as regular methods, not arrow functions, when they use ",[14,22,23],{},"this.base",", ",[14,26,27],{},"this.transform",", or ",[14,30,31],{},"this.options",". See ",[34,35,37],"a",{"href":36},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fast#printer-handlers-and-context","printer handlers"," for the context and signatures. To change the schema itself before every output, use a ",[34,40,42],{"href":41},"\u002Fdocs\u002F5.x\u002Fhow-to\u002Fmacros","macro"," instead.",[45,46,48],"h2",{"id":47},"typescript-types","TypeScript types",[10,50,51,54,55,58,59,62,63,66],{},[14,52,53],{},"@kubb\u002Fplugin-ts"," prints type strings, so a handler returns the TypeScript type as a string. This override prints ",[14,56,57],{},"date"," schemas as the JavaScript ",[14,60,61],{},"Date"," object instead of ",[14,64,65],{},"string",".",[68,69,74],"pre",{"language":70,"filename":71,"code":72,"class":73},"typescript","date.ts","import { pluginTs } from '@kubb\u002Fplugin-ts'\n\npluginTs({\n  printer: {\n    nodes: {\n      date() {\n        return 'Date'\n      },\n    },\n  },\n})","highlights",[14,75,77,104,105,104,107,104,116,104,130,104,142,104,152,104,163,104,173,104,181,104,189],{"class":76},"language-typescript",[78,79,82,86,90,94,97,100],"span",{"class":80,"style":81},"line","display: inline",[78,83,85],{"style":84},"color:#d73a49;--hls-dark:#f97583","import ",[78,87,89],{"style":88},"color:#005cc5;--hls-dark:#79b8ff","{ ",[78,91,93],{"style":92},"color:#24292e;--hls-dark:#e1e4e8","pluginTs ",[78,95,96],{"style":88},"} ",[78,98,99],{"style":84},"from ",[78,101,103],{"style":102},"color:#032f62;--hls-dark:#9ecbff","'@kubb\u002Fplugin-ts'","\n",[78,106],{"class":80,"style":81},[78,108,109,113],{"class":80,"style":81},[78,110,112],{"style":111},"color:#6f42c1;--hls-dark:#b392f0","pluginTs",[78,114,115],{"style":88},"({",[78,117,118,121,124,127],{"class":80,"style":81},[78,119,120],{"style":88},"  ",[78,122,123],{"style":88},"printer",[78,125,126],{"style":84},": ",[78,128,129],{"style":88},"{",[78,131,132,135,138,140],{"class":80,"style":81},[78,133,134],{"style":88},"    ",[78,136,137],{"style":88},"nodes",[78,139,126],{"style":84},[78,141,129],{"style":88},[78,143,144,147,149],{"class":80,"style":81},[78,145,146],{"style":88},"      ",[78,148,57],{"style":111},[78,150,151],{"style":88},"() {",[78,153,154,157,160],{"class":80,"style":81},[78,155,156],{"style":88},"        ",[78,158,159],{"style":84},"return ",[78,161,162],{"style":102},"'Date'",[78,164,165,167,170],{"class":80,"style":81},[78,166,146],{"style":102},[78,168,169],{"style":88},"}",[78,171,172],{"style":84},",",[78,174,175,177,179],{"class":80,"style":81},[78,176,134],{"style":84},[78,178,169],{"style":88},[78,180,172],{"style":84},[78,182,183,185,187],{"class":80,"style":81},[78,184,120],{"style":84},[78,186,169],{"style":88},[78,188,172],{"style":84},[78,190,191],{"class":80,"style":81},[78,192,193],{"style":88},"})",[10,195,196,197,200,201,204,205,207,208,211],{},"Inside a handler, ",[14,198,199],{},"this.transform(node)"," returns the printed type of a nested schema as a string. This is a breaking change for handlers that passed that result into ",[14,202,203],{},"ts.factory",": build the type as a string instead. Handlers that return a compiler node from ",[14,206,70],{}," 5 or 6, or from ",[14,209,210],{},"@typescript\u002Ftypescript6",", still work, but that form is deprecated and is removed in the next major.",[45,213,215],{"id":214},"zod-schemas","Zod schemas",[10,217,218,221,222,225],{},[14,219,220],{},"@kubb\u002Fplugin-zod"," prints expression strings, so a handler returns the Zod code as a string. With ",[14,223,224],{},"mini: true"," the same overrides target the Zod Mini printer instead.",[68,227,229],{"language":70,"filename":71,"code":228,"class":73},"import { pluginZod } from '@kubb\u002Fplugin-zod'\n\npluginZod({\n  printer: {\n    nodes: {\n      date() {\n        return 'z.iso.date()'\n      },\n    },\n  },\n})",[14,230,231,104,247,104,249,104,256,104,266,104,276,104,284,104,293,104,301,104,309,104,317],{"class":76},[78,232,233,235,237,240,242,244],{"class":80,"style":81},[78,234,85],{"style":84},[78,236,89],{"style":88},[78,238,239],{"style":92},"pluginZod ",[78,241,96],{"style":88},[78,243,99],{"style":84},[78,245,246],{"style":102},"'@kubb\u002Fplugin-zod'",[78,248],{"class":80,"style":81},[78,250,251,254],{"class":80,"style":81},[78,252,253],{"style":111},"pluginZod",[78,255,115],{"style":88},[78,257,258,260,262,264],{"class":80,"style":81},[78,259,120],{"style":88},[78,261,123],{"style":88},[78,263,126],{"style":84},[78,265,129],{"style":88},[78,267,268,270,272,274],{"class":80,"style":81},[78,269,134],{"style":88},[78,271,137],{"style":88},[78,273,126],{"style":84},[78,275,129],{"style":88},[78,277,278,280,282],{"class":80,"style":81},[78,279,146],{"style":88},[78,281,57],{"style":111},[78,283,151],{"style":88},[78,285,286,288,290],{"class":80,"style":81},[78,287,156],{"style":88},[78,289,159],{"style":84},[78,291,292],{"style":102},"'z.iso.date()'",[78,294,295,297,299],{"class":80,"style":81},[78,296,146],{"style":102},[78,298,169],{"style":88},[78,300,172],{"style":84},[78,302,303,305,307],{"class":80,"style":81},[78,304,134],{"style":84},[78,306,169],{"style":88},[78,308,172],{"style":84},[78,310,311,313,315],{"class":80,"style":81},[78,312,120],{"style":84},[78,314,169],{"style":88},[78,316,172],{"style":84},[78,318,319],{"class":80,"style":81},[78,320,193],{"style":88},[10,322,323,324,326,327,330],{},"Use ",[14,325,23],{}," to keep the default output and decorate it. This override appends ",[14,328,329],{},".openapi(...)"," to every object schema, and nested nodes still print through the regular handlers.",[68,332,335],{"language":70,"filename":333,"code":334,"class":73},"openapi.ts","import { pluginZod } from '@kubb\u002Fplugin-zod'\n\npluginZod({\n  printer: {\n    nodes: {\n      object(node) {\n        return `${this.base(node)}.openapi(${JSON.stringify({ description: node.description })})`\n      },\n    },\n  },\n})",[14,336,337,104,351,104,353,104,359,104,369,104,379,104,395,104,459,104,467,104,475,104,483],{"class":76},[78,338,339,341,343,345,347,349],{"class":80,"style":81},[78,340,85],{"style":84},[78,342,89],{"style":88},[78,344,239],{"style":92},[78,346,96],{"style":88},[78,348,99],{"style":84},[78,350,246],{"style":102},[78,352],{"class":80,"style":81},[78,354,355,357],{"class":80,"style":81},[78,356,253],{"style":111},[78,358,115],{"style":88},[78,360,361,363,365,367],{"class":80,"style":81},[78,362,120],{"style":88},[78,364,123],{"style":88},[78,366,126],{"style":84},[78,368,129],{"style":88},[78,370,371,373,375,377],{"class":80,"style":81},[78,372,134],{"style":88},[78,374,137],{"style":88},[78,376,126],{"style":84},[78,378,129],{"style":88},[78,380,381,383,386,389,392],{"class":80,"style":81},[78,382,146],{"style":88},[78,384,385],{"style":111},"object",[78,387,388],{"style":88},"(",[78,390,391],{"style":92},"node",[78,393,394],{"style":88},") {",[78,396,397,399,401,404,407,410,412,415,417,419,422,424,427,429,432,434,437,440,443,445,447,449,452,454,456],{"class":80,"style":81},[78,398,156],{"style":88},[78,400,159],{"style":84},[78,402,403],{"style":102},"`",[78,405,406],{"style":92},"${",[78,408,409],{"style":92},"this",[78,411,66],{"style":84},[78,413,414],{"style":111},"base",[78,416,388],{"style":88},[78,418,391],{"style":92},[78,420,421],{"style":88},")",[78,423,169],{"style":92},[78,425,426],{"style":102},".openapi(",[78,428,406],{"style":92},[78,430,431],{"style":88},"JSON",[78,433,66],{"style":84},[78,435,436],{"style":111},"stringify",[78,438,439],{"style":88},"({ ",[78,441,442],{"style":88},"description",[78,444,126],{"style":84},[78,446,391],{"style":92},[78,448,66],{"style":84},[78,450,451],{"style":88},"description ",[78,453,193],{"style":88},[78,455,169],{"style":92},[78,457,458],{"style":102},")`",[78,460,461,463,465],{"class":80,"style":81},[78,462,146],{"style":102},[78,464,169],{"style":88},[78,466,172],{"style":84},[78,468,469,471,473],{"class":80,"style":81},[78,470,134],{"style":84},[78,472,169],{"style":88},[78,474,172],{"style":84},[78,476,477,479,481],{"class":80,"style":81},[78,478,120],{"style":84},[78,480,169],{"style":88},[78,482,172],{"style":84},[78,484,485],{"class":80,"style":81},[78,486,193],{"style":88},[10,488,489,490,493,494,497,498,501,502,505,506,66],{},"A Zod handler can also read ",[14,491,492],{},"this.options.direction",", which is ",[14,495,496],{},"'decode'"," while printing response schemas and ",[14,499,500],{},"'encode'"," while printing request bodies and parameters. Return a different expression per direction and the plugin treats the node as a two-way conversion, emitting an ",[14,503,504],{},"${name}InputSchema"," variant that request bodies resolve to. See ",[34,507,509],{"href":508},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-zod\u002Fguides\u002Fcustomization#encode-custom-types","Encode a custom type on requests",[45,511,513],{"id":512},"faker-mocks","Faker mocks",[10,515,516,519],{},[14,517,518],{},"@kubb\u002Fplugin-faker"," also prints strings, one Faker expression per schema node. This override generates floats where the spec declares integers.",[68,521,524],{"language":70,"filename":522,"code":523,"class":73},"integer.ts","import { pluginFaker } from '@kubb\u002Fplugin-faker'\n\npluginFaker({\n  printer: {\n    nodes: {\n      integer() {\n        return 'faker.number.float()'\n      },\n    },\n  },\n})",[14,525,526,104,542,104,544,104,551,104,561,104,571,104,580,104,589,104,597,104,605,104,613],{"class":76},[78,527,528,530,532,535,537,539],{"class":80,"style":81},[78,529,85],{"style":84},[78,531,89],{"style":88},[78,533,534],{"style":92},"pluginFaker ",[78,536,96],{"style":88},[78,538,99],{"style":84},[78,540,541],{"style":102},"'@kubb\u002Fplugin-faker'",[78,543],{"class":80,"style":81},[78,545,546,549],{"class":80,"style":81},[78,547,548],{"style":111},"pluginFaker",[78,550,115],{"style":88},[78,552,553,555,557,559],{"class":80,"style":81},[78,554,120],{"style":88},[78,556,123],{"style":88},[78,558,126],{"style":84},[78,560,129],{"style":88},[78,562,563,565,567,569],{"class":80,"style":81},[78,564,134],{"style":88},[78,566,137],{"style":88},[78,568,126],{"style":84},[78,570,129],{"style":88},[78,572,573,575,578],{"class":80,"style":81},[78,574,146],{"style":88},[78,576,577],{"style":111},"integer",[78,579,151],{"style":88},[78,581,582,584,586],{"class":80,"style":81},[78,583,156],{"style":88},[78,585,159],{"style":84},[78,587,588],{"style":102},"'faker.number.float()'",[78,590,591,593,595],{"class":80,"style":81},[78,592,146],{"style":102},[78,594,169],{"style":88},[78,596,172],{"style":84},[78,598,599,601,603],{"class":80,"style":81},[78,600,134],{"style":84},[78,602,169],{"style":88},[78,604,172],{"style":84},[78,606,607,609,611],{"class":80,"style":81},[78,608,120],{"style":84},[78,610,169],{"style":88},[78,612,172],{"style":84},[78,614,615],{"class":80,"style":81},[78,616,193],{"style":88},{"title":618,"searchDepth":619,"depth":619,"links":620},"",5,[621,623,624],{"id":47,"depth":622,"text":48},2,{"id":214,"depth":622,"text":215},{"id":512,"depth":622,"text":513},"Printers turn Kubb's AST schema nodes into generated code. The printer option on plugin-ts, plugin-zod, and plugin-faker replaces the handler for a single schema type, so you change what one plugin emits without forking it.","md",{"layout":628,"title":5,"description":625,"outline":629,"order":619,"navigation":630},"doc","deep",{"title":5,"icon":631},"i-iconoir-printing-page",{"layout":628,"outline":629},{"title":5,"icon":631},"\u002Fdocs\u002F5.x\u002Fhow-to\u002Fprinters",{"title":5,"description":625},{"loc":634},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Fhow-to\u002Fprinters.md","docs\u002F5.x\u002Fhow-to\u002Fprinters","SdUKgbTLRHu7CzJLNq58_uW4NhjnWv6VOXPwTI4bQks",1792931640135]