[{"data":1,"prerenderedAt":3021,"buildId":3022},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates":3},{"id":4,"title":5,"body":6,"description":3004,"extension":3005,"frontmatter":3006,"heading":3010,"meta":3012,"navigation":3014,"order":2991,"path":3015,"seo":3016,"sitemap":3017,"source":3018,"stem":3019,"__hash__":3020},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates.md","Templates - Write files with defineTemplate",{"type":7,"value":8,"toc":2986},"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,2729,2734,2754,2777,2982],[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 key={imp.path} names={ast.file.getNames(imp).map((item) => ({ ...item, space: 'type' }))} path={imp.path} root={target.path} \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,2633,77,2640,77,2678,77,2693,77,2703,77,2713,77,2719,77,2725],{"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,2533,2536,2538,2540,2542,2544,2546,2548,2550,2552,2554,2556,2558,2560,2562,2565,2567,2569,2571,2573,2575,2577,2580,2582,2584,2587,2589,2591,2593,2595,2597,2600,2603,2605,2607,2609,2611,2613,2615,2617,2619,2621,2623,2625,2627,2629,2631],{"class":43,"style":44},[41,2528,1005],{"style":51},[41,2530,191],{"style":51},[41,2532,1932],{"style":194},[41,2534,2535],{"style":86},"key",[41,2537,1938],{"style":47},[41,2539,197],{"style":51},[41,2541,2517],{"style":55},[41,2543,29],{"style":47},[41,2545,901],{"style":51},[41,2547,69],{"style":51},[41,2549,1935],{"style":86},[41,2551,1938],{"style":47},[41,2553,197],{"style":51},[41,2555,592],{"style":55},[41,2557,29],{"style":47},[41,2559,207],{"style":51},[41,2561,29],{"style":47},[41,2563,2564],{"style":86},"getNames",[41,2566,142],{"style":51},[41,2568,2517],{"style":55},[41,2570,321],{"style":51},[41,2572,29],{"style":47},[41,2574,2511],{"style":86},[41,2576,2514],{"style":51},[41,2578,2579],{"style":55},"item",[41,2581,176],{"style":51},[41,2583,2522],{"style":47},[41,2585,2586],{"style":51},"({ ",[41,2588,200],{"style":47},[41,2590,2579],{"style":55},[41,2592,58],{"style":47},[41,2594,2477],{"style":51},[41,2596,126],{"style":47},[41,2598,2599],{"style":75},"'type' ",[41,2601,2602],{"style":51},"}))} ",[41,2604,901],{"style":86},[41,2606,1938],{"style":47},[41,2608,197],{"style":51},[41,2610,2517],{"style":55},[41,2612,29],{"style":47},[41,2614,901],{"style":51},[41,2616,69],{"style":51},[41,2618,877],{"style":86},[41,2620,1938],{"style":47},[41,2622,197],{"style":51},[41,2624,2447],{"style":55},[41,2626,29],{"style":47},[41,2628,901],{"style":51},[41,2630,69],{"style":51},[41,2632,1969],{"style":51},[41,2634,2635,2637],{"class":43,"style":44},[41,2636,960],{"style":51},[41,2638,2639],{"style":51},"))}",[41,2641,2642,2644,2646,2649,2651,2653,2655,2658,2660,2662,2664,2666,2668,2671,2673,2676],{"class":43,"style":44},[41,2643,960],{"style":55},[41,2645,191],{"style":51},[41,2647,2648],{"style":194},"Code ",[41,2650,173],{"style":86},[41,2652,1938],{"style":47},[41,2654,197],{"style":51},[41,2656,2657],{"style":75},"`",[41,2659,1049],{"style":55},[41,2661,145],{"style":55},[41,2663,29],{"style":47},[41,2665,173],{"style":51},[41,2667,235],{"style":55},[41,2669,2670],{"style":75},"Schema`",[41,2672,69],{"style":51},[41,2674,2675],{"style":86},"export",[41,2677,217],{"style":51},[41,2679,2680,2682,2684,2686,2688,2691],{"class":43,"style":44},[41,2681,1005],{"style":55},[41,2683,197],{"style":51},[41,2685,2023],{"style":55},[41,2687,29],{"style":47},[41,2689,2690],{"style":51},"text",[41,2692,235],{"style":51},[41,2694,2695,2697,2699,2701],{"class":43,"style":44},[41,2696,960],{"style":55},[41,2698,223],{"style":51},[41,2700,2257],{"style":194},[41,2702,217],{"style":51},[41,2704,2705,2707,2709,2711],{"class":43,"style":44},[41,2706,843],{"style":55},[41,2708,223],{"style":51},[41,2710,226],{"style":194},[41,2712,217],{"style":51},[41,2714,2715,2717],{"class":43,"style":44},[41,2716,158],{"style":51},[41,2718,321],{"style":51},[41,2720,2721,2723],{"class":43,"style":44},[41,2722,1101],{"style":51},[41,2724,132],{"style":47},[41,2726,2727],{"class":43,"style":44},[41,2728,242],{"style":51},[563,2730,2731,2732],{"id":1609},"Caching with ",[14,2733,1609],{},[10,2735,2736,2739,2740,2743,2744,2746,2747,1148,2750,2753],{},[14,2737,2738],{},"memo(key, compute)"," runs ",[14,2741,2742],{},"compute"," once per ",[14,2745,2535],{}," and build, then returns the stored value. It is a composable, so it reads the current context. ",[14,2748,2749],{},"ctx.memo(key, compute)",[14,2751,2752],{},"this.memo(key, compute)"," do the same. Every plugin shares the store, so:",[534,2755,2756,2763,2770],{},[537,2757,2758,2759,2762],{},"Prefix the key with your plugin name, such as ",[14,2760,2761],{},"my-plugin:",", unless every plugin should share the value.",[537,2764,2765,2766,2015,2768,29],{},"Put the node in the key for a value from one node: ",[14,2767,1720],{},[14,2769,1716],{},[537,2771,2772,2773,2776],{},"Use ",[14,2774,2775],{},"ctx.resolver.memo(key, compute)"," for a value only your plugin reads.",[31,2778,2781],{"language":578,"filename":2779,"code":2780,"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,2782,2783,77,2806,77,2808,77,2823,77,2835,77,2847,77,2854,77,2892,77,2955,77,2961,77,2963,77,2970,77,2978],{"class":583},[41,2784,2785,2787,2789,2791,2793,2795,2797,2800,2802,2804],{"class":43,"style":44},[41,2786,48],{"style":47},[41,2788,52],{"style":51},[41,2790,592],{"style":55},[41,2792,58],{"style":47},[41,2794,16],{"style":55},[41,2796,58],{"style":47},[41,2798,2799],{"style":55},"memo ",[41,2801,69],{"style":51},[41,2803,72],{"style":47},[41,2805,76],{"style":75},[41,2807],{"class":43,"style":44},[41,2809,2810,2812,2814,2817,2819,2821],{"class":43,"style":44},[41,2811,101],{"style":47},[41,2813,104],{"style":47},[41,2815,2816],{"style":55},"memoOperation ",[41,2818,110],{"style":47},[41,2820,16],{"style":86},[41,2822,115],{"style":51},[41,2824,2825,2827,2829,2831,2833],{"class":43,"style":44},[41,2826,120],{"style":51},[41,2828,123],{"style":51},[41,2830,126],{"style":47},[41,2832,452],{"style":75},[41,2834,132],{"style":47},[41,2836,2837,2839,2841,2843,2845],{"class":43,"style":44},[41,2838,120],{"style":47},[41,2840,139],{"style":86},[41,2842,142],{"style":51},[41,2844,145],{"style":55},[41,2846,153],{"style":51},[41,2848,2849,2851],{"class":43,"style":44},[41,2850,158],{"style":51},[41,2852,2853],{"style":704},"\u002F\u002F One entry per operation. Other templates that ask for the same key reuse it.",[41,2855,2856,2858,2860,2863,2865,2867,2869,2872,2874,2876,2878,2880,2882,2884,2886,2889],{"class":43,"style":44},[41,2857,158],{"style":704},[41,2859,104],{"style":47},[41,2861,2862],{"style":55},"schemas ",[41,2864,110],{"style":47},[41,2866,1609],{"style":86},[41,2868,142],{"style":51},[41,2870,2871],{"style":75},"`my-plugin:schemas:",[41,2873,1049],{"style":55},[41,2875,145],{"style":55},[41,2877,29],{"style":47},[41,2879,854],{"style":51},[41,2881,235],{"style":55},[41,2883,2657],{"style":75},[41,2885,58],{"style":47},[41,2887,2888],{"style":51},"() ",[41,2890,2891],{"style":47},"=>",[41,2893,2894,2896,2898,2900,2902,2904,2907,2909,2911,2913,2915,2917,2919,2921,2923,2925,2928,2930,2933,2935,2938,2940,2942,2944,2946,2948,2951,2953],{"class":43,"style":44},[41,2895,843],{"style":47},[41,2897,592],{"style":55},[41,2899,29],{"style":47},[41,2901,145],{"style":51},[41,2903,29],{"style":47},[41,2905,2906],{"style":51},"collect",[41,2908,191],{"style":47},[41,2910,592],{"style":55},[41,2912,29],{"style":47},[41,2914,439],{"style":51},[41,2916,217],{"style":47},[41,2918,142],{"style":51},[41,2920,145],{"style":55},[41,2922,58],{"style":47},[41,2924,52],{"style":51},[41,2926,2927],{"style":51},"depth",[41,2929,126],{"style":47},[41,2931,2932],{"style":75},"'shallow'",[41,2934,58],{"style":47},[41,2936,2937],{"style":51},"schema",[41,2939,126],{"style":47},[41,2941,142],{"style":51},[41,2943,2937],{"style":55},[41,2945,176],{"style":51},[41,2947,2522],{"style":47},[41,2949,2950],{"style":55},"schema ",[41,2952,242],{"style":51},[41,2954,132],{"style":47},[41,2956,2957,2959],{"class":43,"style":44},[41,2958,158],{"style":47},[41,2960,321],{"style":51},[41,2962],{"class":43,"style":44},[41,2964,2965,2967],{"class":43,"style":44},[41,2966,158],{"style":51},[41,2968,2969],{"style":47},"return",[41,2971,2972,2974,2976],{"class":43,"style":44},[41,2973,120],{"style":47},[41,2975,235],{"style":51},[41,2977,132],{"style":47},[41,2979,2980],{"class":43,"style":44},[41,2981,242],{"style":51},[2983,2984,2985],"blockquote",{"as":1645},"The value stays in memory until the build ends. Store derived data, such as names or paths, not generated source.",{"title":2987,"searchDepth":2988,"depth":2988,"links":2989},"",5,[2990],{"id":345,"depth":2991,"text":16,"children":2992},2,[2993,2995,2997,2998,3000,3002],{"id":565,"depth":2994,"text":566},3,{"id":728,"depth":2994,"text":2996},"Writing FileNodes",{"id":1124,"depth":2994,"text":1127},{"id":207,"depth":2994,"text":2999},"Naming files with file",{"id":1588,"depth":2994,"text":3001},"Importing names with from and code",{"id":1609,"depth":2994,"text":3003},"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":3007,"title":5,"description":3004,"outline":3008,"order":2991,"navigation":3009},"doc",[2991,2994],{"title":3010,"icon":3011},"Templates","i-iconoir-code-brackets",{"layout":3007,"outline":3013},[2991,2994],{"title":3010,"icon":3011},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates",{"title":5,"description":3004},{"loc":3015},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates.md","docs\u002F5.x\u002Freference\u002Fkit\u002Ftemplates","VAz7Zg2ifSs_BDStlWvThT5i8YpIffZdJhyNreQakz4",1795989038348,"2e8b4c62-5b8c-4587-97c0-530d08a9bd53"]