[{"data":1,"prerenderedAt":3025},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates":3},{"id":4,"title":5,"body":6,"description":3008,"extension":3009,"frontmatter":3010,"heading":3014,"meta":3016,"navigation":3018,"order":2995,"path":3019,"seo":3020,"sitemap":3021,"source":3022,"stem":3023,"__hash__":3024},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates.md","Templates - Write files with defineTemplate",{"type":7,"value":8,"toc":2990},"minimark",[9,30,342,348,405,482,493,519,548,553,562,712,719,732,1094,1108,1114,1152,1397,1402,1652,1657,1692,1766,1979,1986,2002,2008,2035,2043,2089,2092,2112,2120,2130,2137,2146,2191,2197,2733,2738,2758,2781,2986],[10,11,12,13,17,18,21,22,29],"p",{},"A template writes your plugin's files for each node of one kind. Define it with ",[14,15,16],"code",{},"defineTemplate",", then register it in your plugin's ",[14,19,20],{},"setup"," with ",[23,24,26],"a",{"href":25},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fplugins#setup-context",[14,27,28],{},"addTemplate",".",[31,32,37],"pre",{"language":33,"filename":34,"code":35,"class":36},"tsx","zodSchema.tsx","import { addTemplate, defineExtension, defineTemplate } from 'kubb\u002Fkit'\nimport { File } from '@kubb\u002Frenderer-jsx'\n\nexport const zodSchema = defineTemplate({\n  kind: 'Schema',\n  render(node, ctx) {\n    if (!node.name) return null\n    return \u003CFile {...ctx.file(node)}>…\u003C\u002FFile>\n  },\n})\n\nexport const pluginZod = defineExtension({\n  kind: 'plugin',\n  meta: { name: 'plugin-zod' },\n  setup(options) {\n    addTemplate(zodSchema)\n    return options\n  },\n})","highlights",[14,38,40,77,78,77,95,77,97,77,116,77,133,77,154,77,183,77,229,77,238,77,243,77,245,77,260,77,273,77,295,77,308,77,322,77,330,77,338],{"class":39},"language-tsx",[41,42,45,49,53,56,59,62,64,67,70,73],"span",{"class":43,"style":44},"line","display: inline",[41,46,48],{"style":47},"color:#d73a49;--hls-dark:#f97583","import ",[41,50,52],{"style":51},"color:#005cc5;--hls-dark:#79b8ff","{ ",[41,54,28],{"style":55},"color:#24292e;--hls-dark:#e1e4e8",[41,57,58],{"style":47},", ",[41,60,61],{"style":55},"defineExtension",[41,63,58],{"style":47},[41,65,66],{"style":55},"defineTemplate ",[41,68,69],{"style":51},"} ",[41,71,72],{"style":47},"from ",[41,74,76],{"style":75},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fkit'","\n",[41,79,80,82,84,88,90,92],{"class":43,"style":44},[41,81,48],{"style":47},[41,83,52],{"style":51},[41,85,87],{"style":86},"color:#6f42c1;--hls-dark:#b392f0","File ",[41,89,69],{"style":51},[41,91,72],{"style":47},[41,93,94],{"style":75},"'@kubb\u002Frenderer-jsx'",[41,96],{"class":43,"style":44},[41,98,99,102,105,108,111,113],{"class":43,"style":44},[41,100,101],{"style":47},"export ",[41,103,104],{"style":47},"const ",[41,106,107],{"style":55},"zodSchema ",[41,109,110],{"style":47},"= ",[41,112,16],{"style":86},[41,114,115],{"style":51},"({",[41,117,118,121,124,127,130],{"class":43,"style":44},[41,119,120],{"style":51},"  ",[41,122,123],{"style":51},"kind",[41,125,126],{"style":47},": ",[41,128,129],{"style":75},"'Schema'",[41,131,132],{"style":47},",",[41,134,135,137,140,143,146,148,151],{"class":43,"style":44},[41,136,120],{"style":47},[41,138,139],{"style":86},"render",[41,141,142],{"style":51},"(",[41,144,145],{"style":55},"node",[41,147,58],{"style":47},[41,149,150],{"style":55},"ctx",[41,152,153],{"style":51},") {",[41,155,156,159,162,164,167,169,171,174,177,180],{"class":43,"style":44},[41,157,158],{"style":51},"    ",[41,160,161],{"style":47},"if ",[41,163,142],{"style":51},[41,165,166],{"style":47},"!",[41,168,145],{"style":55},[41,170,29],{"style":47},[41,172,173],{"style":51},"name",[41,175,176],{"style":51},") ",[41,178,179],{"style":47},"return ",[41,181,182],{"style":51},"null",[41,184,185,187,189,192,195,198,201,203,205,208,210,212,215,218,221,224,227],{"class":43,"style":44},[41,186,158],{"style":51},[41,188,179],{"style":47},[41,190,191],{"style":51},"\u003C",[41,193,87],{"style":194},"color:#22863a;--hls-dark:#85e89d",[41,196,197],{"style":51},"{",[41,199,200],{"style":47},"...",[41,202,150],{"style":55},[41,204,29],{"style":47},[41,206,207],{"style":86},"file",[41,209,142],{"style":51},[41,211,145],{"style":55},[41,213,214],{"style":51},")}",[41,216,217],{"style":51},">",[41,219,220],{"style":55},"…",[41,222,223],{"style":51},"\u003C\u002F",[41,225,226],{"style":194},"File",[41,228,217],{"style":51},[41,230,231,233,236],{"class":43,"style":44},[41,232,120],{"style":51},[41,234,235],{"style":51},"}",[41,237,132],{"style":47},[41,239,240],{"class":43,"style":44},[41,241,242],{"style":51},"})",[41,244],{"class":43,"style":44},[41,246,247,249,251,254,256,258],{"class":43,"style":44},[41,248,101],{"style":47},[41,250,104],{"style":47},[41,252,253],{"style":55},"pluginZod ",[41,255,110],{"style":47},[41,257,61],{"style":86},[41,259,115],{"style":51},[41,261,262,264,266,268,271],{"class":43,"style":44},[41,263,120],{"style":51},[41,265,123],{"style":51},[41,267,126],{"style":47},[41,269,270],{"style":75},"'plugin'",[41,272,132],{"style":47},[41,274,275,277,280,282,284,286,288,291,293],{"class":43,"style":44},[41,276,120],{"style":47},[41,278,279],{"style":51},"meta",[41,281,126],{"style":47},[41,283,52],{"style":51},[41,285,173],{"style":51},[41,287,126],{"style":47},[41,289,290],{"style":75},"'plugin-zod' ",[41,292,235],{"style":51},[41,294,132],{"style":47},[41,296,297,299,301,303,306],{"class":43,"style":44},[41,298,120],{"style":47},[41,300,20],{"style":86},[41,302,142],{"style":51},[41,304,305],{"style":55},"options",[41,307,153],{"style":51},[41,309,310,312,314,316,319],{"class":43,"style":44},[41,311,158],{"style":51},[41,313,28],{"style":86},[41,315,142],{"style":51},[41,317,318],{"style":55},"zodSchema",[41,320,321],{"style":51},")",[41,323,324,326,328],{"class":43,"style":44},[41,325,158],{"style":51},[41,327,179],{"style":47},[41,329,305],{"style":55},[41,331,332,334,336],{"class":43,"style":44},[41,333,120],{"style":55},[41,335,235],{"style":51},[41,337,132],{"style":47},[41,339,340],{"class":43,"style":44},[41,341,242],{"style":51},[343,344,346],"h2",{"id":345},"definetemplate",[14,347,16],{},[349,350,351,367],"table",{},[352,353,354],"thead",{},[355,356,357,361,364],"tr",{},[358,359,360],"th",{},"Field",[358,362,363],{},"Type",[358,365,366],{},"Does",[368,369,370,388],"tbody",{},[355,371,372,377,382],{},[373,374,375],"td",{},[14,376,123],{},[373,378,379],{},[14,380,381],{},"'Schema' | 'Operation' | 'Operations'",[373,383,384,385,387],{},"Required. Picks the nodes ",[14,386,139],{}," gets.",[355,389,390,394,399],{},[373,391,392],{},[14,393,139],{},[373,395,396],{},[14,397,398],{},"(node, ctx) => Output",[373,400,401,402,29],{},"Required. Returns the files for one node, or for every operation with ",[14,403,404],{},"'Operations'",[349,406,407,426],{},[352,408,409],{},[355,410,411,415,420,423],{},[358,412,413],{},[14,414,123],{},[358,416,417,419],{},[14,418,139],{}," gets",[358,421,422],{},"Runs",[358,424,425],{},"Use it for",[368,427,428,446,465],{},[355,429,430,434,440,443],{},[373,431,432],{},[14,433,129],{},[373,435,436,437],{},"A ",[14,438,439],{},"SchemaNode",[373,441,442],{},"Once per schema the plugin keeps",[373,444,445],{},"Types, validators, factories",[355,447,448,453,459,462],{},[373,449,450],{},[14,451,452],{},"'Operation'",[373,454,455,456],{},"An ",[14,457,458],{},"OperationNode",[373,460,461],{},"Once per operation the plugin keeps",[373,463,464],{},"Clients, hooks, handlers",[355,466,467,471,476,479],{},[373,468,469],{},[14,470,404],{},[373,472,473],{},[14,474,475],{},"Array\u003COperationNode>",[373,477,478],{},"Once, after every operation",[373,480,481],{},"Index or aggregate files",[10,483,484,486,487,489,490,29],{},[14,485,123],{}," types the node, so ",[14,488,139],{}," needs no annotation. Type the context with the plugin: ",[14,491,492],{},"defineTemplate\u003CPluginZod>({ … })",[10,494,495,498,499,58,502,58,505,507,508,511,512,514,515,518],{},[14,496,497],{},"Output"," is JSX, a ",[14,500,501],{},"FileNode",[14,503,504],{},"Array\u003CFileNode>",[14,506,182],{},", or ",[14,509,510],{},"undefined",", or a promise of one of them. A ",[14,513,501],{}," is stored as it is. To write files yourself, call ",[14,516,517],{},"ctx.upsertFile()"," and return nothing.",[520,521,522,536,539],"ul",{},[523,524,525,526,532,533,29],"li",{},"Kit renders JSX with ",[23,527,529],{"href":528},"\u002Fdocs\u002F5.x\u002Freference\u002Fjsx",[14,530,531],{},"jsxRenderer",". Pass another renderer with ",[14,534,535],{},"addTemplate(template, { renderer })",[523,537,538],{},"Templates of one kind run in the order you add them.",[523,540,541,542,544,545,547],{},"A template is a plain value. Import another plugin's template and pass it to ",[14,543,28],{},", or call its ",[14,546,139],{}," from your own template.",[549,550,552],"h3",{"id":551},"skipping-nodes","Skipping nodes",[10,554,555,556,558,559,561],{},"Return ",[14,557,182],{}," from ",[14,560,139],{}," to write nothing for a node. Check the node first:",[31,563,567],{"language":564,"filename":565,"code":566,"class":36},"typescript","getOperation.ts","import { ast, defineTemplate } from 'kubb\u002Fkit'\n\nexport const getOperation = defineTemplate({\n  kind: 'Operation',\n  render(node, ctx) {\n    if (!ast.http.isOperation(node) || node.method !== 'GET') return null\n    \u002F\u002F node is a GET operation here\n    return null\n  },\n})",[14,568,570,77,589,77,591,77,606,77,618,77,634,77,684,77,692,77,700,77,708],{"class":569},"language-typescript",[41,571,572,574,576,579,581,583,585,587],{"class":43,"style":44},[41,573,48],{"style":47},[41,575,52],{"style":51},[41,577,578],{"style":55},"ast",[41,580,58],{"style":47},[41,582,66],{"style":55},[41,584,69],{"style":51},[41,586,72],{"style":47},[41,588,76],{"style":75},[41,590],{"class":43,"style":44},[41,592,593,595,597,600,602,604],{"class":43,"style":44},[41,594,101],{"style":47},[41,596,104],{"style":47},[41,598,599],{"style":55},"getOperation ",[41,601,110],{"style":47},[41,603,16],{"style":86},[41,605,115],{"style":51},[41,607,608,610,612,614,616],{"class":43,"style":44},[41,609,120],{"style":51},[41,611,123],{"style":51},[41,613,126],{"style":47},[41,615,452],{"style":75},[41,617,132],{"style":47},[41,619,620,622,624,626,628,630,632],{"class":43,"style":44},[41,621,120],{"style":47},[41,623,139],{"style":86},[41,625,142],{"style":51},[41,627,145],{"style":55},[41,629,58],{"style":47},[41,631,150],{"style":55},[41,633,153],{"style":51},[41,635,636,638,640,642,644,646,648,651,653,656,658,660,662,665,667,669,672,675,678,680,682],{"class":43,"style":44},[41,637,158],{"style":51},[41,639,161],{"style":47},[41,641,142],{"style":51},[41,643,166],{"style":47},[41,645,578],{"style":55},[41,647,29],{"style":47},[41,649,650],{"style":51},"http",[41,652,29],{"style":47},[41,654,655],{"style":86},"isOperation",[41,657,142],{"style":51},[41,659,145],{"style":55},[41,661,176],{"style":51},[41,663,664],{"style":47},"|| ",[41,666,145],{"style":55},[41,668,29],{"style":47},[41,670,671],{"style":51},"method ",[41,673,674],{"style":47},"!== ",[41,676,677],{"style":75},"'GET'",[41,679,176],{"style":51},[41,681,179],{"style":47},[41,683,182],{"style":51},[41,685,686,688],{"class":43,"style":44},[41,687,158],{"style":51},[41,689,691],{"style":690},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F node is a GET operation here",[41,693,694,696,698],{"class":43,"style":44},[41,695,158],{"style":690},[41,697,179],{"style":47},[41,699,182],{"style":51},[41,701,702,704,706],{"class":43,"style":44},[41,703,120],{"style":51},[41,705,235],{"style":51},[41,707,132],{"style":47},[41,709,710],{"class":43,"style":44},[41,711,242],{"style":51},[549,713,715,716,718],{"id":714},"filenodes","Writing ",[14,717,501],{},"s",[10,720,721,722,724,725,731],{},"A template can return ",[14,723,501],{},"s from ",[23,726,728],{"href":727},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fast#factory-functions",[14,729,730],{},"ast.factory"," instead of JSX:",[31,733,736],{"language":564,"filename":734,"code":735,"class":36},"operationFile.ts","import { ast, defineTemplate } from 'kubb\u002Fkit'\n\nexport const operationFile = defineTemplate({\n  kind: 'Operation',\n  render(node, ctx) {\n    const file = ctx.resolver.file({\n      name: node.operationId,\n      extname: '.ts',\n      root: ctx.root,\n      output: { path: 'operations', mode: 'directory' },\n    })\n\n    return [\n      ast.factory.createFile({\n        baseName: file.baseName,\n        path: file.path,\n        sources: [\n          ast.factory.createSource({\n            nodes: [ast.factory.createText(`export const op = '${node.operationId}'`)],\n          }),\n        ],\n      }),\n    ]\n  },\n})",[14,737,738,77,756,77,758,77,773,77,785,77,801,77,825,77,843,77,857,77,874,77,907,77,913,77,915,77,924,77,942,77,960,77,976,77,987,77,1005,77,1052,77,1060,77,1069,77,1077,77,1083,77,1090],{"class":569},[41,739,740,742,744,746,748,750,752,754],{"class":43,"style":44},[41,741,48],{"style":47},[41,743,52],{"style":51},[41,745,578],{"style":55},[41,747,58],{"style":47},[41,749,66],{"style":55},[41,751,69],{"style":51},[41,753,72],{"style":47},[41,755,76],{"style":75},[41,757],{"class":43,"style":44},[41,759,760,762,764,767,769,771],{"class":43,"style":44},[41,761,101],{"style":47},[41,763,104],{"style":47},[41,765,766],{"style":55},"operationFile ",[41,768,110],{"style":47},[41,770,16],{"style":86},[41,772,115],{"style":51},[41,774,775,777,779,781,783],{"class":43,"style":44},[41,776,120],{"style":51},[41,778,123],{"style":51},[41,780,126],{"style":47},[41,782,452],{"style":75},[41,784,132],{"style":47},[41,786,787,789,791,793,795,797,799],{"class":43,"style":44},[41,788,120],{"style":47},[41,790,139],{"style":86},[41,792,142],{"style":51},[41,794,145],{"style":55},[41,796,58],{"style":47},[41,798,150],{"style":55},[41,800,153],{"style":51},[41,802,803,805,807,810,812,814,816,819,821,823],{"class":43,"style":44},[41,804,158],{"style":51},[41,806,104],{"style":47},[41,808,809],{"style":55},"file ",[41,811,110],{"style":47},[41,813,150],{"style":55},[41,815,29],{"style":47},[41,817,818],{"style":51},"resolver",[41,820,29],{"style":47},[41,822,207],{"style":86},[41,824,115],{"style":51},[41,826,827,830,832,834,836,838,841],{"class":43,"style":44},[41,828,829],{"style":51},"      ",[41,831,173],{"style":51},[41,833,126],{"style":47},[41,835,145],{"style":55},[41,837,29],{"style":47},[41,839,840],{"style":51},"operationId",[41,842,132],{"style":47},[41,844,845,847,850,852,855],{"class":43,"style":44},[41,846,829],{"style":47},[41,848,849],{"style":51},"extname",[41,851,126],{"style":47},[41,853,854],{"style":75},"'.ts'",[41,856,132],{"style":47},[41,858,859,861,864,866,868,870,872],{"class":43,"style":44},[41,860,829],{"style":47},[41,862,863],{"style":51},"root",[41,865,126],{"style":47},[41,867,150],{"style":55},[41,869,29],{"style":47},[41,871,863],{"style":51},[41,873,132],{"style":47},[41,875,876,878,881,883,885,888,890,893,895,898,900,903,905],{"class":43,"style":44},[41,877,829],{"style":47},[41,879,880],{"style":51},"output",[41,882,126],{"style":47},[41,884,52],{"style":51},[41,886,887],{"style":51},"path",[41,889,126],{"style":47},[41,891,892],{"style":75},"'operations'",[41,894,58],{"style":47},[41,896,897],{"style":51},"mode",[41,899,126],{"style":47},[41,901,902],{"style":75},"'directory' ",[41,904,235],{"style":51},[41,906,132],{"style":47},[41,908,909,911],{"class":43,"style":44},[41,910,158],{"style":47},[41,912,242],{"style":51},[41,914],{"class":43,"style":44},[41,916,917,919,921],{"class":43,"style":44},[41,918,158],{"style":51},[41,920,179],{"style":47},[41,922,923],{"style":51},"[",[41,925,926,928,930,932,935,937,940],{"class":43,"style":44},[41,927,829],{"style":51},[41,929,578],{"style":55},[41,931,29],{"style":47},[41,933,934],{"style":51},"factory",[41,936,29],{"style":47},[41,938,939],{"style":86},"createFile",[41,941,115],{"style":51},[41,943,944,947,950,952,954,956,958],{"class":43,"style":44},[41,945,946],{"style":51},"        ",[41,948,949],{"style":51},"baseName",[41,951,126],{"style":47},[41,953,207],{"style":55},[41,955,29],{"style":47},[41,957,949],{"style":51},[41,959,132],{"style":47},[41,961,962,964,966,968,970,972,974],{"class":43,"style":44},[41,963,946],{"style":47},[41,965,887],{"style":51},[41,967,126],{"style":47},[41,969,207],{"style":55},[41,971,29],{"style":47},[41,973,887],{"style":51},[41,975,132],{"style":47},[41,977,978,980,983,985],{"class":43,"style":44},[41,979,946],{"style":47},[41,981,982],{"style":51},"sources",[41,984,126],{"style":47},[41,986,923],{"style":51},[41,988,989,992,994,996,998,1000,1003],{"class":43,"style":44},[41,990,991],{"style":51},"          ",[41,993,578],{"style":55},[41,995,29],{"style":47},[41,997,934],{"style":51},[41,999,29],{"style":47},[41,1001,1002],{"style":86},"createSource",[41,1004,115],{"style":51},[41,1006,1007,1010,1013,1015,1017,1019,1021,1023,1025,1028,1030,1033,1036,1038,1040,1042,1044,1047,1050],{"class":43,"style":44},[41,1008,1009],{"style":51},"            ",[41,1011,1012],{"style":51},"nodes",[41,1014,126],{"style":47},[41,1016,923],{"style":51},[41,1018,578],{"style":55},[41,1020,29],{"style":47},[41,1022,934],{"style":51},[41,1024,29],{"style":47},[41,1026,1027],{"style":86},"createText",[41,1029,142],{"style":51},[41,1031,1032],{"style":75},"`export const op = '",[41,1034,1035],{"style":55},"${",[41,1037,145],{"style":55},[41,1039,29],{"style":47},[41,1041,840],{"style":51},[41,1043,235],{"style":55},[41,1045,1046],{"style":75},"'`",[41,1048,1049],{"style":51},")]",[41,1051,132],{"style":47},[41,1053,1054,1056,1058],{"class":43,"style":44},[41,1055,991],{"style":47},[41,1057,242],{"style":51},[41,1059,132],{"style":47},[41,1061,1062,1064,1067],{"class":43,"style":44},[41,1063,946],{"style":47},[41,1065,1066],{"style":51},"]",[41,1068,132],{"style":47},[41,1070,1071,1073,1075],{"class":43,"style":44},[41,1072,829],{"style":47},[41,1074,242],{"style":51},[41,1076,132],{"style":47},[41,1078,1079,1081],{"class":43,"style":44},[41,1080,158],{"style":47},[41,1082,1066],{"style":51},[41,1084,1085,1088],{"class":43,"style":44},[41,1086,1087],{"style":51},"  }",[41,1089,132],{"style":47},[41,1091,1092],{"class":43,"style":44},[41,1093,242],{"style":51},[10,1095,1096,1097,1100,1101,1103,1104,1107],{},"This template writes ",[14,1098,1099],{},"operations\u002F\u003CoperationId>.ts"," in the output folder. When your plugin has an ",[14,1102,880],{}," option, pass ",[14,1105,1106],{},"ctx.options.output"," instead of a fixed value.",[549,1109,1111],{"id":1110},"templatecontext",[14,1112,1113],{},"TemplateContext",[10,1115,1116,1118,1119,1121,1122,1128,1129,58,1132,1134,1135,1138,1139,1134,1142,1145,1146,1148,1149,29],{},[14,1117,139],{}," gets ",[14,1120,150],{}," with these fields. Kit runs it through ",[23,1123,1125],{"href":1124},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fplugins",[14,1126,1127],{},"withContext",", so ",[14,1130,1131],{},"this",[14,1133,150],{}," and ",[14,1136,1137],{},"useKubb()"," are the same template context, and composables such as ",[14,1140,1141],{},"useConfig()",[14,1143,1144],{},"memo()"," work there. Setup-only composables such as ",[14,1147,28],{}," report ",[14,1150,1151],{},"KUBB_NO_CONTEXT",[349,1153,1154,1165],{},[352,1155,1156],{},[355,1157,1158,1160,1162],{},[358,1159,360],{},[358,1161,363],{},[358,1163,1164],{},"Holds",[368,1166,1167,1182,1197,1227,1242,1260,1285,1300,1332,1347,1362,1382],{},[355,1168,1169,1174,1179],{},[373,1170,1171],{},[14,1172,1173],{},"ctx.config",[373,1175,1176],{},[14,1177,1178],{},"Config",[373,1180,1181],{},"The resolved Kubb config.",[355,1183,1184,1189,1194],{},[373,1185,1186],{},[14,1187,1188],{},"ctx.root",[373,1190,1191],{},[14,1192,1193],{},"string",[373,1195,1196],{},"Absolute path of the root output folder, the same for every plugin.",[355,1198,1199,1204,1209],{},[373,1200,1201],{},[14,1202,1203],{},"ctx.options",[373,1205,1206],{},[14,1207,1208],{},"TResolvedOptions",[373,1210,1211,1212,58,1215,1218,1219,1222,1223,1226],{},"The node's options after ",[14,1213,1214],{},"exclude",[14,1216,1217],{},"include",", and ",[14,1220,1221],{},"override",". In ",[14,1224,1225],{},"operations()",", the plugin's options.",[355,1228,1229,1234,1239],{},[373,1230,1231],{},[14,1232,1233],{},"ctx.plugin",[373,1235,1236],{},[14,1237,1238],{},"Plugin",[373,1240,1241],{},"The current plugin.",[355,1243,1244,1249,1254],{},[373,1245,1246],{},[14,1247,1248],{},"ctx.resolver",[373,1250,1251],{},[14,1252,1253],{},"Resolver",[373,1255,1256,1257,29],{},"The current plugin's ",[23,1258,818],{"href":1259},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fresolvers",[355,1261,1262,1267,1272],{},[373,1263,1264],{},[14,1265,1266],{},"ctx.printer",[373,1268,1269],{},[14,1270,1271],{},"Printer | undefined",[373,1273,1274,1275,1281,1282,1284],{},"The printer from the plugin's ",[23,1276,1278],{"href":1277},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fplugins#printer",[14,1279,1280],{},"setPrinter"," factory, or ",[14,1283,510],{}," without one.",[355,1286,1287,1292,1297],{},[373,1288,1289],{},[14,1290,1291],{},"ctx.adapter",[373,1293,1294],{},[14,1295,1296],{},"Adapter",[373,1298,1299],{},"The adapter that parsed the input.",[355,1301,1302,1307,1312],{},[373,1303,1304],{},[14,1305,1306],{},"ctx.meta",[373,1308,1309],{},[14,1310,1311],{},"InputMeta",[373,1313,1314,1315,58,1318,58,1321,58,1324,1327,1328,1331],{},"Document metadata: ",[14,1316,1317],{},"title",[14,1319,1320],{},"version",[14,1322,1323],{},"baseURL",[14,1325,1326],{},"servers",", and the ",[14,1329,1330],{},"auth"," schemes.",[355,1333,1334,1339,1344],{},[373,1335,1336],{},[14,1337,1338],{},"ctx.schemas",[373,1340,1341],{},[14,1342,1343],{},"ReadonlyArray\u003CSchemaNode>",[373,1345,1346],{},"Every schema in the spec, in adapter order. The OpenAPI adapter puts a referenced schema first, except in reference cycles.",[355,1348,1349,1354,1359],{},[373,1350,1351],{},[14,1352,1353],{},"ctx.operations",[373,1355,1356],{},[14,1357,1358],{},"ReadonlyArray\u003COperationNode>",[373,1360,1361],{},"Every operation in the spec, in adapter order.",[355,1363,1364,1369,1374],{},[373,1365,1366],{},[14,1367,1368],{},"ctx.hooks",[373,1370,1371],{},[14,1372,1373],{},"Hookable\u003CKubbHooks>",[373,1375,1376,1377,1381],{},"The build's ",[23,1378,1380],{"href":1379},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks","hook"," emitter.",[355,1383,1384,1389,1394],{},[373,1385,1386],{},[14,1387,1388],{},"ctx.signal",[373,1390,1391],{},[14,1392,1393],{},"AbortSignal | undefined",[373,1395,1396],{},"Stops generation at the next safe checkpoint.",[10,1398,1399,1401],{},[14,1400,150],{}," also has these helpers:",[349,1403,1404,1416],{},[352,1405,1406],{},[355,1407,1408,1411,1414],{},[358,1409,1410],{},"Helper",[358,1412,1413],{},"Signature",[358,1415,366],{},[368,1417,1418,1433,1446,1464,1482,1497,1512,1527,1551,1572,1593,1612,1630],{},[355,1419,1420,1425,1430],{},[373,1421,1422],{},[14,1423,1424],{},"ctx.addFile()",[373,1426,1427],{},[14,1428,1429],{},"(...files: Array\u003CFileNode>) => Promise\u003Cvoid>",[373,1431,1432],{},"Adds files, skipping any that already exist.",[355,1434,1435,1439,1443],{},[373,1436,1437],{},[14,1438,517],{},[373,1440,1441],{},[14,1442,1429],{},[373,1444,1445],{},"Adds files, or merges their sources and imports into an existing file.",[355,1447,1448,1453,1458],{},[373,1449,1450],{},[14,1451,1452],{},"ctx.getFile()",[373,1454,1455],{},[14,1456,1457],{},"(path: string) => FileNode | undefined",[373,1459,1460,1461,1463],{},"Returns the file at ",[14,1462,887],{}," as the build holds it now, such as one an earlier plugin wrote.",[355,1465,1466,1471,1476],{},[373,1467,1468],{},[14,1469,1470],{},"ctx.dispatch()",[373,1472,1473],{},[14,1474,1475],{},"({ result, renderer?, pointer? }) => Promise\u003Cvoid>",[373,1477,1478,1479,29],{},"Adds a template result: files as they are, or elements through ",[14,1480,1481],{},"renderer",[355,1483,1484,1489,1494],{},[373,1485,1486],{},[14,1487,1488],{},"ctx.getPlugin()",[373,1490,1491],{},[14,1492,1493],{},"(name: string) => Plugin | undefined",[373,1495,1496],{},"Returns a plugin by name.",[355,1498,1499,1504,1509],{},[373,1500,1501],{},[14,1502,1503],{},"ctx.requirePlugin()",[373,1505,1506],{},[14,1507,1508],{},"(name: string) => Plugin",[373,1510,1511],{},"Returns a plugin by name, or throws.",[355,1513,1514,1519,1524],{},[373,1515,1516],{},[14,1517,1518],{},"ctx.getResolver()",[373,1520,1521],{},[14,1522,1523],{},"(name: string) => Resolver",[373,1525,1526],{},"Returns another plugin's resolver.",[355,1528,1529,1534,1539],{},[373,1530,1531],{},[14,1532,1533],{},"ctx.file()",[373,1535,1536],{},[14,1537,1538],{},"(node, options?) => FileTarget",[373,1540,1541,1542,1545,1546,29],{},"Returns the ",[14,1543,1544],{},"\u003CFile>"," props for a node's file. See ",[23,1547,1549],{"href":1548},"#file",[14,1550,207],{},[355,1552,1553,1558,1563],{},[373,1554,1555],{},[14,1556,1557],{},"ctx.from()",[373,1559,1560],{},[14,1561,1562],{},"(source?) => From",[373,1564,1565,1566,29],{},"Returns a plugin's resolver whose names carry their imports. See ",[23,1567,1569],{"href":1568},"#from",[14,1570,1571],{},"from",[355,1573,1574,1579,1584],{},[373,1575,1576],{},[14,1577,1578],{},"ctx.memo()",[373,1580,1581],{},[14,1582,1583],{},"(key: string, compute: () => T) => T",[373,1585,1586,1587,29],{},"Caches a value for the whole build. See ",[23,1588,1590],{"href":1589},"#memo",[14,1591,1592],{},"memo",[355,1594,1595,1600,1605],{},[373,1596,1597],{},[14,1598,1599],{},"ctx.info()",[373,1601,1602],{},[14,1603,1604],{},"(message: string, options?: { code?, help?, location? }) => void",[373,1606,1607,1608,1611],{},"Reports an ",[14,1609,1610],{},"info"," diagnostic for this plugin.",[355,1613,1614,1619,1623],{},[373,1615,1616],{},[14,1617,1618],{},"ctx.warn()",[373,1620,1621],{},[14,1622,1604],{},[373,1624,1625,1626,1629],{},"Reports a ",[14,1627,1628],{},"warning",", which does not fail the build.",[355,1631,1632,1637,1642],{},[373,1633,1634],{},[14,1635,1636],{},"ctx.error()",[373,1638,1639],{},[14,1640,1641],{},"(error: string | Error, options?: { code?, help?, location? }) => void",[373,1643,1607,1644,1647,1648,1651],{},[14,1645,1646],{},"error",", which fails the build. A ",[14,1649,1650],{},"Diagnostics.Error"," keeps its code, help, and location.",[549,1653,1654,1655],{"id":207},"Naming files with ",[14,1656,207],{},[10,1658,1659,1662,1663,1665,1666,58,1668,58,1670,1327,1672,1134,1675,1678,1679,1681,1682,1684,1685,1134,1688,1691],{},[14,1660,1661],{},"file(node, options?)"," returns the ",[14,1664,1544],{}," props for the file a template writes: ",[14,1667,949],{},[14,1669,887],{},[14,1671,279],{},[14,1673,1674],{},"banner",[14,1676,1677],{},"footer"," from the plugin's ",[14,1680,880],{},". Spread it onto ",[14,1683,1544],{},". It is a composable, so it reads the current template context. ",[14,1686,1687],{},"ctx.file(node)",[14,1689,1690],{},"this.file(node)"," do the same.",[520,1693,1694,1708,1731,1757],{},[523,1695,1696,1697,1700,1701,1704,1705,1707],{},"A schema's file is named after ",[14,1698,1699],{},"node.name",", and an operation's file after ",[14,1702,1703],{},"node.operationId",". Pass ",[14,1706,173],{}," to choose another name.",[523,1709,1710,1711,1714,1715,1718,1719,1722,1723,1726,1727,1730],{},"An operation file that would land on a component schema's file, ignoring case, gets an ",[14,1712,1713],{},"Operation"," suffix: operation ",[14,1716,1717],{},"point"," goes to ",[14,1720,1721],{},"pointOperation.ts",", next to schema ",[14,1724,1725],{},"point.ts",". The declarations keep their names. Kit adds it only when the plugin has a ",[14,1728,1729],{},"Schema"," template, so a plugin that writes only operation files keeps the plain name.",[523,1732,1733,1734,1737,1738,1740,1741,1134,1743,1746,1747,58,1749,1134,1751,1753,1754,29],{},"Pass ",[14,1735,1736],{},"plugin"," to get another plugin's file, such as the types to import. ",[14,1739,207],{}," then uses that plugin's resolver, ",[14,1742,880],{},[14,1744,1745],{},"group",", after its ",[14,1748,1217],{},[14,1750,1214],{},[14,1752,1221],{}," rules. A missing plugin reports ",[14,1755,1756],{},"KUBB_PLUGIN_NOT_FOUND",[523,1758,1759,1760,1763,1764,29],{},"Outside a template or a printer factory, ",[14,1761,1762],{},"file()"," reports ",[14,1765,1151],{},[31,1767,1770],{"language":33,"filename":1768,"code":1769,"class":36},"zodOperation.tsx","import { defineTemplate, file } from 'kubb\u002Fkit'\nimport { File } from '@kubb\u002Frenderer-jsx'\n\nexport const zodOperation = defineTemplate({\n  kind: 'Operation',\n  render(node) {\n    const types = file(node, { plugin: 'plugin-ts' })\n\n    return (\n      \u003CFile {...file(node)}>\n        \u003CFile.Import names={[{ name: 'Pet' }]} path={types.path} \u002F>\n      \u003C\u002FFile>\n    )\n  },\n})",[14,1771,1772,77,1790,77,1804,77,1806,77,1821,77,1833,77,1845,77,1875,77,1877,77,1885,77,1907,77,1953,77,1963,77,1969,77,1975],{"class":39},[41,1773,1774,1776,1778,1780,1782,1784,1786,1788],{"class":43,"style":44},[41,1775,48],{"style":47},[41,1777,52],{"style":51},[41,1779,16],{"style":55},[41,1781,58],{"style":47},[41,1783,809],{"style":55},[41,1785,69],{"style":51},[41,1787,72],{"style":47},[41,1789,76],{"style":75},[41,1791,1792,1794,1796,1798,1800,1802],{"class":43,"style":44},[41,1793,48],{"style":47},[41,1795,52],{"style":51},[41,1797,87],{"style":86},[41,1799,69],{"style":51},[41,1801,72],{"style":47},[41,1803,94],{"style":75},[41,1805],{"class":43,"style":44},[41,1807,1808,1810,1812,1815,1817,1819],{"class":43,"style":44},[41,1809,101],{"style":47},[41,1811,104],{"style":47},[41,1813,1814],{"style":55},"zodOperation ",[41,1816,110],{"style":47},[41,1818,16],{"style":86},[41,1820,115],{"style":51},[41,1822,1823,1825,1827,1829,1831],{"class":43,"style":44},[41,1824,120],{"style":51},[41,1826,123],{"style":51},[41,1828,126],{"style":47},[41,1830,452],{"style":75},[41,1832,132],{"style":47},[41,1834,1835,1837,1839,1841,1843],{"class":43,"style":44},[41,1836,120],{"style":47},[41,1838,139],{"style":86},[41,1840,142],{"style":51},[41,1842,145],{"style":55},[41,1844,153],{"style":51},[41,1846,1847,1849,1851,1854,1856,1858,1860,1862,1864,1866,1868,1870,1873],{"class":43,"style":44},[41,1848,158],{"style":51},[41,1850,104],{"style":47},[41,1852,1853],{"style":55},"types ",[41,1855,110],{"style":47},[41,1857,207],{"style":86},[41,1859,142],{"style":51},[41,1861,145],{"style":55},[41,1863,58],{"style":47},[41,1865,52],{"style":51},[41,1867,1736],{"style":51},[41,1869,126],{"style":47},[41,1871,1872],{"style":75},"'plugin-ts' ",[41,1874,242],{"style":51},[41,1876],{"class":43,"style":44},[41,1878,1879,1881,1883],{"class":43,"style":44},[41,1880,158],{"style":51},[41,1882,179],{"style":47},[41,1884,142],{"style":51},[41,1886,1887,1889,1891,1893,1895,1897,1899,1901,1903,1905],{"class":43,"style":44},[41,1888,829],{"style":51},[41,1890,191],{"style":51},[41,1892,87],{"style":194},[41,1894,197],{"style":51},[41,1896,200],{"style":47},[41,1898,207],{"style":86},[41,1900,142],{"style":51},[41,1902,145],{"style":55},[41,1904,214],{"style":51},[41,1906,217],{"style":51},[41,1908,1909,1911,1913,1916,1919,1922,1925,1927,1929,1932,1935,1937,1939,1941,1944,1946,1948,1950],{"class":43,"style":44},[41,1910,946],{"style":55},[41,1912,191],{"style":51},[41,1914,1915],{"style":194},"File.Import ",[41,1917,1918],{"style":86},"names",[41,1920,1921],{"style":47},"=",[41,1923,1924],{"style":51},"{[{ ",[41,1926,173],{"style":51},[41,1928,126],{"style":47},[41,1930,1931],{"style":75},"'Pet' ",[41,1933,1934],{"style":51},"}]} ",[41,1936,887],{"style":86},[41,1938,1921],{"style":47},[41,1940,197],{"style":51},[41,1942,1943],{"style":55},"types",[41,1945,29],{"style":47},[41,1947,887],{"style":51},[41,1949,69],{"style":51},[41,1951,1952],{"style":51},"\u002F>",[41,1954,1955,1957,1959,1961],{"class":43,"style":44},[41,1956,829],{"style":55},[41,1958,223],{"style":51},[41,1960,226],{"style":194},[41,1962,217],{"style":51},[41,1964,1965,1967],{"class":43,"style":44},[41,1966,158],{"style":51},[41,1968,321],{"style":51},[41,1970,1971,1973],{"class":43,"style":44},[41,1972,1087],{"style":51},[41,1974,132],{"style":47},[41,1976,1977],{"class":43,"style":44},[41,1978,242],{"style":51},[549,1980,1981,1982,1134,1984],{"id":1571},"Importing names with ",[14,1983,1571],{},[14,1985,14],{},[10,1987,1988,1991,1992,58,1995,1998,1999,29],{},[14,1989,1990],{},"from(source?)"," wraps a plugin's resolver, so each name it returns comes with its import from that plugin's file. Call it as ",[14,1993,1994],{},"from(source)",[14,1996,1997],{},"ctx.from(source)"," or ",[14,2000,2001],{},"this.from(source)",[10,2003,2004,2007],{},[14,2005,2006],{},"source"," is one of:",[520,2009,2010,2016,2029],{},[523,2011,2012,2013,29],{},"A plugin name, such as ",[14,2014,2015],{},"'plugin-ts'",[523,2017,2018,2019,2025,2026,29],{},"A name a plugin offers with ",[23,2020,2022],{"href":2021},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fplugins#provide",[14,2023,2024],{},"provide",", such as ",[14,2027,2028],{},"'types'",[523,2030,2031,2032,2034],{},"Nothing, for the current plugin. ",[14,2033,1557],{}," is then typed with that plugin's resolver.",[10,2036,2037,2038,2040,2041,29],{},"Any other ",[14,2039,2006],{}," fails with ",[14,2042,1756],{},[349,2044,2045,2055],{},[352,2046,2047],{},[355,2048,2049,2052],{},[358,2050,2051],{},"Member",[358,2053,2054],{},"Returns",[368,2056,2057,2074],{},[355,2058,2059,2064],{},[373,2060,2061],{},[14,2062,2063],{},"from(source).resolver",[373,2065,2066,2067,58,2070,2073],{},"The plugin's resolver. Each method that returns a name returns a ",[14,2068,2069],{},"RefName",[14,2071,2072],{},"{ name, import }",", which prints as the name.",[355,2075,2076,2081],{},[373,2077,2078],{},[14,2079,2080],{},"from(source).ref(node, name)",[373,2082,2083,2085,2086,2088],{},[14,2084,173],{}," with the import from the plugin's file for ",[14,2087,145],{},". Use it for a name no resolver method returns, such as one from a shared helper.",[10,2090,2091],{},"The first argument of a resolver method picks the file to import from:",[520,2093,2094,2102,2109],{},[523,2095,2096,2097,2099,2100,29],{},"An operation node: the plugin's file for that operation, with the same ",[14,2098,1713],{}," suffix as ",[14,2101,207],{},[523,2103,2104,2105,2108],{},"A schema node, ",[14,2106,2107],{},"{ name }"," or a schema name: the plugin's file for that schema. The schema must be in the document.",[523,2110,2111],{},"Anything else, such as a status code: no import.",[10,2113,2114,2115,1998,2117,2119],{},"A name also gets no import when the result is not an identifier, such as a description, or when the plugin's ",[14,2116,1217],{},[14,2118,1214],{}," rules leave the node out.",[10,2121,2122,2123,2129],{},"You pass only the node. The target resolver's ",[23,2124,2126],{"href":2125},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fresolvers#resolver-overrides",[14,2127,2128],{},"file.name"," decides the file.",[10,2131,2132,2133,2136],{},"Imports are value imports. Set ",[14,2134,2135],{},"space: 'type'"," on the names you use only as types.",[10,2138,2139,2141,2142,2145],{},[14,2140,14],{}," is a template tag that returns ",[14,2143,2144],{},"{ text, imports }",":",[520,2147,2148,2161,2179,2185],{},[523,2149,2150,2151,2154,2155,2157,2158,2160],{},"Its placeholders (",[14,2152,2153],{},"${…}",") take names from ",[14,2156,1571],{},", other ",[14,2159,14],{}," results, strings and numbers.",[523,2162,2163,58,2165,1134,2167,2170,2171,2174,2175,2178],{},[14,2164,182],{},[14,2166,510],{},[14,2168,2169],{},"false"," print nothing, so ",[14,2172,2173],{},"${cond && name}"," works when ",[14,2176,2177],{},"cond"," is a boolean.",[523,2180,2181,2184],{},[14,2182,2183],{},"code.join(parts, separator)"," joins several parts and keeps their imports.",[523,2186,2187,2188,2190],{},"The imports come in the order of use. ",[14,2189,1544],{}," merges the ones that share a path.",[10,2192,2193,2194,2196],{},"Import paths are absolute. Pass the file you write as ",[14,2195,863],{},", so each path becomes relative to it:",[31,2198,2200],{"language":33,"filename":34,"code":2199,"class":36},"import { ast, code, defineTemplate, file, from } from 'kubb\u002Fkit'\nimport { Code, File } from '@kubb\u002Frenderer-jsx'\n\nexport const zodSchema = defineTemplate({\n  kind: 'Schema',\n  render(node) {\n    if (!node.name) return null\n    const target = file(node)\n    const types = from('plugin-ts').resolver\n    const source = code`export const ${node.name}Schema = z.object({}) satisfies z.ZodType\u003C${types.name(node.name)}>`\n\n    return (\n      \u003CFile {...target}>\n        \u003CFile.Import names={[{ name: 'z', space: 'value' }]} path=\"zod\" \u002F>\n        {source.imports.map((imp) => (\n          \u003CFile.Import\n            key={imp.path}\n            names={ast.file.getNames(imp).map((item) => ({ ...item, space: 'type' }))}\n            path={imp.path}\n            root={target.path}\n          \u002F>\n        ))}\n        \u003CCode name={`${node.name}Schema`} export>\n          {source.text}\n        \u003C\u002FCode>\n      \u003C\u002FFile>\n    )\n  },\n})",[14,2201,2202,77,2232,77,2251,77,2253,77,2267,77,2279,77,2291,77,2313,77,2332,77,2354,77,2406,77,2408,77,2416,77,2435,77,2477,77,2508,77,2517,77,2536,77,2595,77,2613,77,2631,77,2637,77,2644,77,2682,77,2697,77,2707,77,2717,77,2723,77,2729],{"class":39},[41,2203,2204,2206,2208,2210,2212,2214,2216,2218,2220,2222,2224,2226,2228,2230],{"class":43,"style":44},[41,2205,48],{"style":47},[41,2207,52],{"style":51},[41,2209,578],{"style":55},[41,2211,58],{"style":47},[41,2213,14],{"style":55},[41,2215,58],{"style":47},[41,2217,16],{"style":55},[41,2219,58],{"style":47},[41,2221,207],{"style":55},[41,2223,58],{"style":47},[41,2225,72],{"style":55},[41,2227,69],{"style":51},[41,2229,72],{"style":47},[41,2231,76],{"style":75},[41,2233,2234,2236,2238,2241,2243,2245,2247,2249],{"class":43,"style":44},[41,2235,48],{"style":47},[41,2237,52],{"style":51},[41,2239,2240],{"style":86},"Code",[41,2242,58],{"style":47},[41,2244,87],{"style":86},[41,2246,69],{"style":51},[41,2248,72],{"style":47},[41,2250,94],{"style":75},[41,2252],{"class":43,"style":44},[41,2254,2255,2257,2259,2261,2263,2265],{"class":43,"style":44},[41,2256,101],{"style":47},[41,2258,104],{"style":47},[41,2260,107],{"style":55},[41,2262,110],{"style":47},[41,2264,16],{"style":86},[41,2266,115],{"style":51},[41,2268,2269,2271,2273,2275,2277],{"class":43,"style":44},[41,2270,120],{"style":51},[41,2272,123],{"style":51},[41,2274,126],{"style":47},[41,2276,129],{"style":75},[41,2278,132],{"style":47},[41,2280,2281,2283,2285,2287,2289],{"class":43,"style":44},[41,2282,120],{"style":47},[41,2284,139],{"style":86},[41,2286,142],{"style":51},[41,2288,145],{"style":55},[41,2290,153],{"style":51},[41,2292,2293,2295,2297,2299,2301,2303,2305,2307,2309,2311],{"class":43,"style":44},[41,2294,158],{"style":51},[41,2296,161],{"style":47},[41,2298,142],{"style":51},[41,2300,166],{"style":47},[41,2302,145],{"style":55},[41,2304,29],{"style":47},[41,2306,173],{"style":51},[41,2308,176],{"style":51},[41,2310,179],{"style":47},[41,2312,182],{"style":51},[41,2314,2315,2317,2319,2322,2324,2326,2328,2330],{"class":43,"style":44},[41,2316,158],{"style":51},[41,2318,104],{"style":47},[41,2320,2321],{"style":55},"target ",[41,2323,110],{"style":47},[41,2325,207],{"style":86},[41,2327,142],{"style":51},[41,2329,145],{"style":55},[41,2331,321],{"style":51},[41,2333,2334,2336,2338,2340,2342,2344,2346,2348,2350,2352],{"class":43,"style":44},[41,2335,158],{"style":51},[41,2337,104],{"style":47},[41,2339,1853],{"style":55},[41,2341,110],{"style":47},[41,2343,1571],{"style":86},[41,2345,142],{"style":51},[41,2347,2015],{"style":75},[41,2349,321],{"style":51},[41,2351,29],{"style":47},[41,2353,818],{"style":51},[41,2355,2356,2358,2360,2363,2365,2367,2370,2372,2374,2376,2378,2380,2383,2385,2387,2389,2391,2393,2395,2397,2399,2401,2403],{"class":43,"style":44},[41,2357,158],{"style":51},[41,2359,104],{"style":47},[41,2361,2362],{"style":55},"source ",[41,2364,110],{"style":47},[41,2366,14],{"style":55},[41,2368,2369],{"style":75},"`export const ",[41,2371,1035],{"style":55},[41,2373,145],{"style":55},[41,2375,29],{"style":47},[41,2377,173],{"style":51},[41,2379,235],{"style":55},[41,2381,2382],{"style":75},"Schema = z.object({}) satisfies z.ZodType\u003C",[41,2384,1035],{"style":55},[41,2386,1943],{"style":55},[41,2388,29],{"style":47},[41,2390,173],{"style":86},[41,2392,142],{"style":51},[41,2394,145],{"style":55},[41,2396,29],{"style":47},[41,2398,173],{"style":51},[41,2400,321],{"style":51},[41,2402,235],{"style":55},[41,2404,2405],{"style":75},">`",[41,2407],{"class":43,"style":44},[41,2409,2410,2412,2414],{"class":43,"style":44},[41,2411,158],{"style":75},[41,2413,179],{"style":47},[41,2415,142],{"style":51},[41,2417,2418,2420,2422,2424,2426,2428,2431,2433],{"class":43,"style":44},[41,2419,829],{"style":51},[41,2421,191],{"style":51},[41,2423,87],{"style":194},[41,2425,197],{"style":51},[41,2427,200],{"style":47},[41,2429,2430],{"style":55},"target",[41,2432,235],{"style":51},[41,2434,217],{"style":51},[41,2436,2437,2439,2441,2443,2445,2447,2449,2451,2453,2456,2458,2461,2463,2466,2468,2470,2472,2475],{"class":43,"style":44},[41,2438,946],{"style":55},[41,2440,191],{"style":51},[41,2442,1915],{"style":194},[41,2444,1918],{"style":86},[41,2446,1921],{"style":47},[41,2448,1924],{"style":51},[41,2450,173],{"style":51},[41,2452,126],{"style":47},[41,2454,2455],{"style":75},"'z'",[41,2457,58],{"style":47},[41,2459,2460],{"style":51},"space",[41,2462,126],{"style":47},[41,2464,2465],{"style":75},"'value' ",[41,2467,1934],{"style":51},[41,2469,887],{"style":86},[41,2471,1921],{"style":47},[41,2473,2474],{"style":75},"\"zod\" ",[41,2476,1952],{"style":51},[41,2478,2479,2481,2483,2485,2487,2490,2492,2495,2498,2501,2503,2506],{"class":43,"style":44},[41,2480,946],{"style":55},[41,2482,197],{"style":51},[41,2484,2006],{"style":55},[41,2486,29],{"style":47},[41,2488,2489],{"style":51},"imports",[41,2491,29],{"style":47},[41,2493,2494],{"style":86},"map",[41,2496,2497],{"style":51},"((",[41,2499,2500],{"style":55},"imp",[41,2502,176],{"style":51},[41,2504,2505],{"style":47},"=> ",[41,2507,142],{"style":51},[41,2509,2510,2512,2514],{"class":43,"style":44},[41,2511,991],{"style":51},[41,2513,191],{"style":51},[41,2515,2516],{"style":194},"File.Import",[41,2518,2519,2521,2524,2526,2528,2530,2532,2534],{"class":43,"style":44},[41,2520,1009],{"style":194},[41,2522,2523],{"style":86},"key",[41,2525,1921],{"style":47},[41,2527,197],{"style":51},[41,2529,2500],{"style":55},[41,2531,29],{"style":47},[41,2533,887],{"style":51},[41,2535,235],{"style":51},[41,2537,2538,2540,2542,2544,2546,2548,2550,2552,2554,2557,2559,2561,2563,2565,2567,2569,2572,2574,2576,2579,2581,2583,2585,2587,2589,2592],{"class":43,"style":44},[41,2539,1009],{"style":51},[41,2541,1918],{"style":86},[41,2543,1921],{"style":47},[41,2545,197],{"style":51},[41,2547,578],{"style":55},[41,2549,29],{"style":47},[41,2551,207],{"style":51},[41,2553,29],{"style":47},[41,2555,2556],{"style":86},"getNames",[41,2558,142],{"style":51},[41,2560,2500],{"style":55},[41,2562,321],{"style":51},[41,2564,29],{"style":47},[41,2566,2494],{"style":86},[41,2568,2497],{"style":51},[41,2570,2571],{"style":55},"item",[41,2573,176],{"style":51},[41,2575,2505],{"style":47},[41,2577,2578],{"style":51},"({ ",[41,2580,200],{"style":47},[41,2582,2571],{"style":55},[41,2584,58],{"style":47},[41,2586,2460],{"style":51},[41,2588,126],{"style":47},[41,2590,2591],{"style":75},"'type' ",[41,2593,2594],{"style":51},"}))}",[41,2596,2597,2599,2601,2603,2605,2607,2609,2611],{"class":43,"style":44},[41,2598,1009],{"style":51},[41,2600,887],{"style":86},[41,2602,1921],{"style":47},[41,2604,197],{"style":51},[41,2606,2500],{"style":55},[41,2608,29],{"style":47},[41,2610,887],{"style":51},[41,2612,235],{"style":51},[41,2614,2615,2617,2619,2621,2623,2625,2627,2629],{"class":43,"style":44},[41,2616,1009],{"style":51},[41,2618,863],{"style":86},[41,2620,1921],{"style":47},[41,2622,197],{"style":51},[41,2624,2430],{"style":55},[41,2626,29],{"style":47},[41,2628,887],{"style":51},[41,2630,235],{"style":51},[41,2632,2633,2635],{"class":43,"style":44},[41,2634,991],{"style":51},[41,2636,1952],{"style":51},[41,2638,2639,2641],{"class":43,"style":44},[41,2640,946],{"style":51},[41,2642,2643],{"style":51},"))}",[41,2645,2646,2648,2650,2653,2655,2657,2659,2662,2664,2666,2668,2670,2672,2675,2677,2680],{"class":43,"style":44},[41,2647,946],{"style":55},[41,2649,191],{"style":51},[41,2651,2652],{"style":194},"Code ",[41,2654,173],{"style":86},[41,2656,1921],{"style":47},[41,2658,197],{"style":51},[41,2660,2661],{"style":75},"`",[41,2663,1035],{"style":55},[41,2665,145],{"style":55},[41,2667,29],{"style":47},[41,2669,173],{"style":51},[41,2671,235],{"style":55},[41,2673,2674],{"style":75},"Schema`",[41,2676,69],{"style":51},[41,2678,2679],{"style":86},"export",[41,2681,217],{"style":51},[41,2683,2684,2686,2688,2690,2692,2695],{"class":43,"style":44},[41,2685,991],{"style":55},[41,2687,197],{"style":51},[41,2689,2006],{"style":55},[41,2691,29],{"style":47},[41,2693,2694],{"style":51},"text",[41,2696,235],{"style":51},[41,2698,2699,2701,2703,2705],{"class":43,"style":44},[41,2700,946],{"style":55},[41,2702,223],{"style":51},[41,2704,2240],{"style":194},[41,2706,217],{"style":51},[41,2708,2709,2711,2713,2715],{"class":43,"style":44},[41,2710,829],{"style":55},[41,2712,223],{"style":51},[41,2714,226],{"style":194},[41,2716,217],{"style":51},[41,2718,2719,2721],{"class":43,"style":44},[41,2720,158],{"style":51},[41,2722,321],{"style":51},[41,2724,2725,2727],{"class":43,"style":44},[41,2726,1087],{"style":51},[41,2728,132],{"style":47},[41,2730,2731],{"class":43,"style":44},[41,2732,242],{"style":51},[549,2734,2735,2736],{"id":1592},"Caching with ",[14,2737,1592],{},[10,2739,2740,2743,2744,2747,2748,2750,2751,1134,2754,2757],{},[14,2741,2742],{},"memo(key, compute)"," runs ",[14,2745,2746],{},"compute"," once per ",[14,2749,2523],{}," and build, then returns the stored value. It is a composable, so it reads the current context. ",[14,2752,2753],{},"ctx.memo(key, compute)",[14,2755,2756],{},"this.memo(key, compute)"," do the same. Every plugin shares the store, so:",[520,2759,2760,2767,2774],{},[523,2761,2762,2763,2766],{},"Prefix the key with your plugin name, such as ",[14,2764,2765],{},"my-plugin:",", unless every plugin should share the value.",[523,2768,2769,2770,1998,2772,29],{},"Put the node in the key for a value from one node: ",[14,2771,1703],{},[14,2773,1699],{},[523,2775,2776,2777,2780],{},"Use ",[14,2778,2779],{},"ctx.resolver.memo(key, compute)"," for a value only your plugin reads.",[31,2782,2785],{"language":564,"filename":2783,"code":2784,"class":36},"memoOperation.ts","import { ast, defineTemplate, memo } from 'kubb\u002Fkit'\n\nexport const memoOperation = defineTemplate({\n  kind: 'Operation',\n  render(node) {\n    \u002F\u002F One entry per operation. Other templates that ask for the same key reuse it.\n    const schemas = memo(`my-plugin:schemas:${node.operationId}`, () =>\n      ast.node.collect\u003Cast.SchemaNode>(node, { depth: 'shallow', schema: (schema) => schema }),\n    )\n\n    return\n  },\n})",[14,2786,2787,77,2810,77,2812,77,2827,77,2839,77,2851,77,2858,77,2896,77,2959,77,2965,77,2967,77,2974,77,2982],{"class":569},[41,2788,2789,2791,2793,2795,2797,2799,2801,2804,2806,2808],{"class":43,"style":44},[41,2790,48],{"style":47},[41,2792,52],{"style":51},[41,2794,578],{"style":55},[41,2796,58],{"style":47},[41,2798,16],{"style":55},[41,2800,58],{"style":47},[41,2802,2803],{"style":55},"memo ",[41,2805,69],{"style":51},[41,2807,72],{"style":47},[41,2809,76],{"style":75},[41,2811],{"class":43,"style":44},[41,2813,2814,2816,2818,2821,2823,2825],{"class":43,"style":44},[41,2815,101],{"style":47},[41,2817,104],{"style":47},[41,2819,2820],{"style":55},"memoOperation ",[41,2822,110],{"style":47},[41,2824,16],{"style":86},[41,2826,115],{"style":51},[41,2828,2829,2831,2833,2835,2837],{"class":43,"style":44},[41,2830,120],{"style":51},[41,2832,123],{"style":51},[41,2834,126],{"style":47},[41,2836,452],{"style":75},[41,2838,132],{"style":47},[41,2840,2841,2843,2845,2847,2849],{"class":43,"style":44},[41,2842,120],{"style":47},[41,2844,139],{"style":86},[41,2846,142],{"style":51},[41,2848,145],{"style":55},[41,2850,153],{"style":51},[41,2852,2853,2855],{"class":43,"style":44},[41,2854,158],{"style":51},[41,2856,2857],{"style":690},"\u002F\u002F One entry per operation. Other templates that ask for the same key reuse it.",[41,2859,2860,2862,2864,2867,2869,2871,2873,2876,2878,2880,2882,2884,2886,2888,2890,2893],{"class":43,"style":44},[41,2861,158],{"style":690},[41,2863,104],{"style":47},[41,2865,2866],{"style":55},"schemas ",[41,2868,110],{"style":47},[41,2870,1592],{"style":86},[41,2872,142],{"style":51},[41,2874,2875],{"style":75},"`my-plugin:schemas:",[41,2877,1035],{"style":55},[41,2879,145],{"style":55},[41,2881,29],{"style":47},[41,2883,840],{"style":51},[41,2885,235],{"style":55},[41,2887,2661],{"style":75},[41,2889,58],{"style":47},[41,2891,2892],{"style":51},"() ",[41,2894,2895],{"style":47},"=>",[41,2897,2898,2900,2902,2904,2906,2908,2911,2913,2915,2917,2919,2921,2923,2925,2927,2929,2932,2934,2937,2939,2942,2944,2946,2948,2950,2952,2955,2957],{"class":43,"style":44},[41,2899,829],{"style":47},[41,2901,578],{"style":55},[41,2903,29],{"style":47},[41,2905,145],{"style":51},[41,2907,29],{"style":47},[41,2909,2910],{"style":51},"collect",[41,2912,191],{"style":47},[41,2914,578],{"style":55},[41,2916,29],{"style":47},[41,2918,439],{"style":51},[41,2920,217],{"style":47},[41,2922,142],{"style":51},[41,2924,145],{"style":55},[41,2926,58],{"style":47},[41,2928,52],{"style":51},[41,2930,2931],{"style":51},"depth",[41,2933,126],{"style":47},[41,2935,2936],{"style":75},"'shallow'",[41,2938,58],{"style":47},[41,2940,2941],{"style":51},"schema",[41,2943,126],{"style":47},[41,2945,142],{"style":51},[41,2947,2941],{"style":55},[41,2949,176],{"style":51},[41,2951,2505],{"style":47},[41,2953,2954],{"style":55},"schema ",[41,2956,242],{"style":51},[41,2958,132],{"style":47},[41,2960,2961,2963],{"class":43,"style":44},[41,2962,158],{"style":47},[41,2964,321],{"style":51},[41,2966],{"class":43,"style":44},[41,2968,2969,2971],{"class":43,"style":44},[41,2970,158],{"style":51},[41,2972,2973],{"style":47},"return",[41,2975,2976,2978,2980],{"class":43,"style":44},[41,2977,120],{"style":47},[41,2979,235],{"style":51},[41,2981,132],{"style":47},[41,2983,2984],{"class":43,"style":44},[41,2985,242],{"style":51},[2987,2988,2989],"blockquote",{"as":1628},"The value stays in memory until the build ends. Store derived data, such as names or paths, not generated source.",{"title":2991,"searchDepth":2992,"depth":2992,"links":2993},"",5,[2994],{"id":345,"depth":2995,"text":16,"children":2996},2,[2997,2999,3001,3002,3004,3006],{"id":551,"depth":2998,"text":552},3,{"id":714,"depth":2998,"text":3000},"Writing FileNodes",{"id":1110,"depth":2998,"text":1113},{"id":207,"depth":2998,"text":3003},"Naming files with file",{"id":1571,"depth":2998,"text":3005},"Importing names with from and code",{"id":1592,"depth":2998,"text":3007},"Caching with memo","defineTemplate declares a template that writes a plugin's files for each schema or operation. Covers its kinds, the TemplateContext, file, from, code, and the memo cache.","md",{"layout":3011,"title":5,"description":3008,"outline":3012,"order":2995,"navigation":3013},"doc",[2995,2998],{"title":3014,"icon":3015},"Templates","i-iconoir-code-brackets",{"layout":3011,"outline":3017},[2995,2998],{"title":3014,"icon":3015},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates",{"title":5,"description":3008},{"loc":3019},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates.md","docs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates","-ZvMCDN_2EnXYoAcAPkDyH4ngKZXcPQtZ3k36GoDPEs",1795442301038]