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