[{"data":1,"prerenderedAt":969,"buildId":970},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fadapters":3},{"id":4,"title":5,"body":6,"description":951,"extension":952,"frontmatter":953,"heading":958,"meta":960,"navigation":962,"order":947,"path":963,"seo":964,"sitemap":965,"source":966,"stem":967,"__hash__":968},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fadapters.md","Adapters - Turn a spec into the Kubb AST",{"type":7,"value":8,"toc":945},"minimark",[9,53,76,481,609,614,816,837,844,849],[10,11,12,13,21,22,28,29,32,33,36,37,40,41,47,48,52],"p",{},"An adapter turns your spec into the ",[14,15,17],"a",{"href":16},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fast#node-tree",[18,19,20],"code",{},"InputNode"," every plugin reads. Define one with ",[14,23,25],{"href":24},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fextensions#define-extension",[18,26,27],{},"defineExtension"," and ",[18,30,31],{},"kind: 'adapter'",". ",[18,34,35],{},"setup"," resolves the user's options. ",[18,38,39],{},"build"," returns the adapter for them. ",[14,42,44],{"href":43},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fextensions#meta",[18,45,46],{},"meta"," and the ",[14,49,51],{"href":50},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fextensions#factory-statics","factory statics"," work as for every extension.",[54,55,57,58,32,64,67,68,71,72,75],"blockquote",{"as":56},"tip","For OpenAPI 2.0, 3.0, 3.1, and 3.2, use the official ",[14,59,61],{"href":60},"\u002Fextensions\u002Fkubb-labs\u002Fadapter-oas",[18,62,63],{},"@kubb\u002Fadapter-oas",[18,65,66],{},"defineConfig"," from ",[18,69,70],{},"kubb\u002Fconfig"," sets it when the config has no ",[18,73,74],{},"adapter",". Write your own only for another spec, such as AsyncAPI, GraphQL, JSON Schema, or gRPC.",[77,78,83],"pre",{"language":79,"filename":80,"code":81,"class":82},"typescript","adapterCustom.ts","import { ast, defineExtension } from 'kubb\u002Fkit'\nimport type { AdapterFactoryOptions } from 'kubb\u002Fkit'\n\ntype AdapterCustom = AdapterFactoryOptions\u003C'custom', { strict?: boolean }, { strict: boolean }>\n\nexport const adapterCustom = defineExtension\u003CAdapterCustom>({\n kind: 'adapter',\n meta: { name: 'custom' },\n setup: (options) => ({ strict: options.strict ?? false }),\n build: () => ({\n document: null,\n async parse(_source) {\n \u002F\u002F Fill schemas and operations from your spec.\n const node = ast.factory.createInput({ schemas: [], operations: [] })\n\n return { node, document: null, sources: [] }\n },\n async validate() {\n \u002F\u002F Throw here when the spec is invalid.\n },\n }),\n})","highlights",[18,84,86,119,120,119,139,119,141,119,192,119,194,119,219,119,235,119,257,119,303,119,318,119,333,119,351,119,360,119,403,119,405,119,435,119,442,119,454,119,461,119,469,119,477],{"class":85},"language-typescript",[87,88,91,95,99,103,106,109,112,115],"span",{"class":89,"style":90},"line","display: inline",[87,92,94],{"style":93},"color:#d73a49;--hls-dark:#f97583","import ",[87,96,98],{"style":97},"color:#005cc5;--hls-dark:#79b8ff","{ ",[87,100,102],{"style":101},"color:#24292e;--hls-dark:#e1e4e8","ast",[87,104,105],{"style":93},", ",[87,107,108],{"style":101},"defineExtension ",[87,110,111],{"style":97},"} ",[87,113,114],{"style":93},"from ",[87,116,118],{"style":117},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fkit'","\n",[87,121,122,124,127,129,133,135,137],{"class":89,"style":90},[87,123,94],{"style":93},[87,125,126],{"style":101},"type ",[87,128,98],{"style":97},[87,130,132],{"style":131},"color:#6f42c1;--hls-dark:#b392f0","AdapterFactoryOptions ",[87,134,111],{"style":97},[87,136,114],{"style":93},[87,138,118],{"style":117},[87,140],{"class":89,"style":90},[87,142,143,145,148,151,154,157,160,162,164,167,170,173,176,178,180,182,185,187,189],{"class":89,"style":90},[87,144,126],{"style":93},[87,146,147],{"style":131},"AdapterCustom ",[87,149,150],{"style":93},"= ",[87,152,153],{"style":131},"AdapterFactoryOptions",[87,155,156],{"style":93},"\u003C",[87,158,159],{"style":117},"'custom'",[87,161,105],{"style":93},[87,163,98],{"style":97},[87,165,166],{"style":97},"strict",[87,168,169],{"style":101},"?: ",[87,171,172],{"style":131},"boolean ",[87,174,175],{"style":97},"}",[87,177,105],{"style":93},[87,179,98],{"style":97},[87,181,166],{"style":97},[87,183,184],{"style":101},": ",[87,186,172],{"style":131},[87,188,175],{"style":97},[87,190,191],{"style":93},">",[87,193],{"class":89,"style":90},[87,195,196,199,202,205,207,209,211,214,216],{"class":89,"style":90},[87,197,198],{"style":93},"export ",[87,200,201],{"style":93},"const ",[87,203,204],{"style":101},"adapterCustom ",[87,206,150],{"style":93},[87,208,27],{"style":101},[87,210,156],{"style":93},[87,212,213],{"style":131},"AdapterCustom",[87,215,191],{"style":93},[87,217,218],{"style":97},"({",[87,220,221,224,227,229,232],{"class":89,"style":90},[87,222,223],{"style":97}," ",[87,225,226],{"style":97},"kind",[87,228,184],{"style":93},[87,230,231],{"style":117},"'adapter'",[87,233,234],{"style":93},",",[87,236,237,239,241,243,245,248,250,253,255],{"class":89,"style":90},[87,238,223],{"style":93},[87,240,46],{"style":97},[87,242,184],{"style":93},[87,244,98],{"style":97},[87,246,247],{"style":97},"name",[87,249,184],{"style":93},[87,251,252],{"style":117},"'custom' ",[87,254,175],{"style":97},[87,256,234],{"style":93},[87,258,259,261,263,265,268,271,274,277,280,282,284,286,289,292,295,298,301],{"class":89,"style":90},[87,260,223],{"style":93},[87,262,35],{"style":97},[87,264,184],{"style":93},[87,266,267],{"style":97},"(",[87,269,270],{"style":101},"options",[87,272,273],{"style":97},") ",[87,275,276],{"style":93},"=> ",[87,278,279],{"style":97},"({ ",[87,281,166],{"style":97},[87,283,184],{"style":93},[87,285,270],{"style":101},[87,287,288],{"style":93},".",[87,290,291],{"style":97},"strict ",[87,293,294],{"style":93},"?? ",[87,296,297],{"style":97},"false ",[87,299,300],{"style":97},"})",[87,302,234],{"style":93},[87,304,305,307,309,311,314,316],{"class":89,"style":90},[87,306,223],{"style":93},[87,308,39],{"style":97},[87,310,184],{"style":93},[87,312,313],{"style":97},"() ",[87,315,276],{"style":93},[87,317,218],{"style":97},[87,319,320,323,326,328,331],{"class":89,"style":90},[87,321,322],{"style":97}," ",[87,324,325],{"style":97},"document",[87,327,184],{"style":93},[87,329,330],{"style":97},"null",[87,332,234],{"style":93},[87,334,335,337,340,343,345,348],{"class":89,"style":90},[87,336,322],{"style":93},[87,338,339],{"style":93},"async ",[87,341,342],{"style":131},"parse",[87,344,267],{"style":97},[87,346,347],{"style":101},"_source",[87,349,350],{"style":97},") {",[87,352,353,356],{"class":89,"style":90},[87,354,355],{"style":97}," ",[87,357,359],{"style":358},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F Fill schemas and operations from your spec.",[87,361,362,364,366,369,371,373,375,378,380,383,385,388,390,393,395,398,400],{"class":89,"style":90},[87,363,355],{"style":358},[87,365,201],{"style":93},[87,367,368],{"style":101},"node ",[87,370,150],{"style":93},[87,372,102],{"style":101},[87,374,288],{"style":93},[87,376,377],{"style":97},"factory",[87,379,288],{"style":93},[87,381,382],{"style":131},"createInput",[87,384,279],{"style":97},[87,386,387],{"style":97},"schemas",[87,389,184],{"style":93},[87,391,392],{"style":97},"[]",[87,394,105],{"style":93},[87,396,397],{"style":97},"operations",[87,399,184],{"style":93},[87,401,402],{"style":97},"[] })",[87,404],{"class":89,"style":90},[87,406,407,409,412,414,417,419,421,423,425,427,430,432],{"class":89,"style":90},[87,408,355],{"style":97},[87,410,411],{"style":93},"return ",[87,413,98],{"style":97},[87,415,416],{"style":101},"node",[87,418,105],{"style":93},[87,420,325],{"style":97},[87,422,184],{"style":93},[87,424,330],{"style":97},[87,426,105],{"style":93},[87,428,429],{"style":97},"sources",[87,431,184],{"style":93},[87,433,434],{"style":97},"[] }",[87,436,437,440],{"class":89,"style":90},[87,438,439],{"style":97}," }",[87,441,234],{"style":93},[87,443,444,446,448,451],{"class":89,"style":90},[87,445,322],{"style":93},[87,447,339],{"style":93},[87,449,450],{"style":131},"validate",[87,452,453],{"style":97},"() {",[87,455,456,458],{"class":89,"style":90},[87,457,355],{"style":97},[87,459,460],{"style":358},"\u002F\u002F Throw here when the spec is invalid.",[87,462,463,465,467],{"class":89,"style":90},[87,464,322],{"style":358},[87,466,175],{"style":97},[87,468,234],{"style":93},[87,470,471,473,475],{"class":89,"style":90},[87,472,223],{"style":93},[87,474,300],{"style":97},[87,476,234],{"style":93},[87,478,479],{"class":89,"style":90},[87,480,300],{"style":97},[77,482,485],{"language":79,"filename":483,"code":484,"class":82},"kubb.config.ts","import { defineConfig } from 'kubb\u002Fconfig'\nimport { adapterCustom } from '.\u002FadapterCustom.ts'\n\nexport default defineConfig({\n input: '.\u002Fmy-spec.json',\n output: { path: '.\u002Fsrc\u002Fgen' },\n adapter: adapterCustom({ strict: true }),\n plugins: [],\n})",[18,486,487,119,503,119,518,119,520,119,531,119,545,119,568,119,592,119,605],{"class":85},[87,488,489,491,493,496,498,500],{"class":89,"style":90},[87,490,94],{"style":93},[87,492,98],{"style":97},[87,494,495],{"style":101},"defineConfig ",[87,497,111],{"style":97},[87,499,114],{"style":93},[87,501,502],{"style":117},"'kubb\u002Fconfig'",[87,504,505,507,509,511,513,515],{"class":89,"style":90},[87,506,94],{"style":93},[87,508,98],{"style":97},[87,510,204],{"style":101},[87,512,111],{"style":97},[87,514,114],{"style":93},[87,516,517],{"style":117},"'.\u002FadapterCustom.ts'",[87,519],{"class":89,"style":90},[87,521,522,524,527,529],{"class":89,"style":90},[87,523,198],{"style":93},[87,525,526],{"style":93},"default ",[87,528,66],{"style":131},[87,530,218],{"style":97},[87,532,533,535,538,540,543],{"class":89,"style":90},[87,534,223],{"style":97},[87,536,537],{"style":97},"input",[87,539,184],{"style":93},[87,541,542],{"style":117},"'.\u002Fmy-spec.json'",[87,544,234],{"style":93},[87,546,547,549,552,554,556,559,561,564,566],{"class":89,"style":90},[87,548,223],{"style":93},[87,550,551],{"style":97},"output",[87,553,184],{"style":93},[87,555,98],{"style":97},[87,557,558],{"style":97},"path",[87,560,184],{"style":93},[87,562,563],{"style":117},"'.\u002Fsrc\u002Fgen' ",[87,565,175],{"style":97},[87,567,234],{"style":93},[87,569,570,572,574,576,579,581,583,585,588,590],{"class":89,"style":90},[87,571,223],{"style":93},[87,573,74],{"style":97},[87,575,184],{"style":93},[87,577,578],{"style":131},"adapterCustom",[87,580,279],{"style":97},[87,582,166],{"style":97},[87,584,184],{"style":93},[87,586,587],{"style":97},"true ",[87,589,300],{"style":97},[87,591,234],{"style":93},[87,593,594,596,599,601,603],{"class":89,"style":90},[87,595,223],{"style":93},[87,597,598],{"style":97},"plugins",[87,600,184],{"style":93},[87,602,392],{"style":97},[87,604,234],{"style":93},[87,606,607],{"class":89,"style":90},[87,608,300],{"style":97},[10,610,611,613],{},[18,612,39],{}," returns these members:",[615,616,617,636],"table",{},[618,619,620],"thead",{},[621,622,623,627,630,633],"tr",{},[624,625,626],"th",{},"Member",[624,628,629],{},"Type",[624,631,632],{},"Required",[624,634,635],{},"Purpose",[637,638,639,666,714,749,774,795],"tbody",{},[621,640,641,646,651,654],{},[642,643,644],"td",{},[18,645,325],{},[642,647,648],{},[18,649,650],{},"TDocument | null",[642,652,653],{},"Yes",[642,655,656,657,105,660,662,663,665],{},"Deprecated. The parsed source document of the last ",[18,658,659],{},"parse()",[18,661,330],{}," before parsing. Return it from ",[18,664,342],{}," instead.",[621,667,668,672,677,679],{},[642,669,670],{},[18,671,342],{},[642,673,674],{},[18,675,676],{},"(source: AdapterSource, options?: { signal?: AbortSignal; harness?: Harness }) => { node, document, sources } | Promise\u003C{ node, document, sources }>",[642,678,653],{},[642,680,681,682,684,685,47,687,689,690,693,694,697,698,701,702,705,706,710,711,713],{},"Converts the spec into the AST and returns it as ",[18,683,416],{},", with the ",[18,686,325],{},[18,688,429],{}," that call read. With ",[18,691,692],{},"harness",", read every ",[18,695,696],{},"$ref"," file with ",[18,699,700],{},"harness.read"," and every URL with ",[18,703,704],{},"harness.fetch",", so the ",[14,707,709],{"href":708},"\u002Fdocs\u002F5.x\u002Freference\u002Fsecurity","security rules"," of the run apply. Unset, a ",[18,712,696],{}," reads any file and host.",[621,715,716,720,725,727],{},[642,717,718],{},[18,719,450],{},[642,721,722],{},[18,723,724],{},"(input: string, options?: { throwOnError?: boolean; harness?: Harness }) => Promise\u003Cvoid>",[642,726,653],{},[642,728,729,730,736,737,740,741,743,744,746,747,288],{},"Validates the document at a path or URL. ",[14,731,733],{"href":732},"\u002Fdocs\u002F5.x\u002Freference\u002Fcommands\u002Fvalidate",[18,734,735],{},"kubb validate"," passes ",[18,738,739],{},"throwOnError: true",", so throw on invalid input. ",[18,742,692],{}," limits ",[18,745,696],{}," reads as in ",[18,748,342],{},[621,750,751,756,761,764],{},[642,752,753],{},[18,754,755],{},"settle",[642,757,758],{},[18,759,760],{},"() => Promise\u003Cvoid>",[642,762,763],{},"No",[642,765,766,767,769,770,773],{},"Waits for work ",[18,768,342],{}," left running, such as validation in a worker. Kubb awaits it before ",[18,771,772],{},"kubb:build:end",". Must not reject.",[621,775,776,781,786,788],{},[642,777,778],{},[18,779,780],{},"locate",[642,782,783],{},[18,784,785],{},"(source: string, location: DiagnosticLocation) => { start: number; end: number } | undefined",[642,787,763],{},[642,789,790,791,794],{},"Finds a diagnostic in the source text for a CLI code frame, as zero-based UTF-16 offsets with ",[18,792,793],{},"end"," exclusive.",[621,796,797,801,806,808],{},[642,798,799],{},[18,800,429],{},[642,802,803],{},[18,804,805],{},"Array\u003Cstring>",[642,807,763],{},[642,809,810,811,813,814,665],{},"Deprecated. The files and URLs the last ",[18,812,659],{}," read. Return them from ",[18,815,342],{},[10,817,818,821,822,825,826,829,830,833,834,836],{},[18,819,820],{},"AdapterSource"," is ",[18,823,824],{},"{ type: 'path'; path }"," or ",[18,827,828],{},"{ type: 'data'; data; root? }",", where ",[18,831,832],{},"root"," is the folder relative ",[18,835,696],{},"s resolve from.",[54,838,840,841,843],{"as":839},"important","When the input is invalid, throw from ",[18,842,659],{}," with a clear message.",[845,846,848],"h2",{"id":847},"adapter-naming","Adapter naming",[615,850,851,864],{},[618,852,853],{},[621,854,855,858,861],{},[624,856,857],{},"Surface",[624,859,860],{},"Pattern",[624,862,863],{},"Example",[637,865,866,883,898,913,928],{},[621,867,868,871,879],{},[642,869,870],{},"npm package",[642,872,873,825,876],{},[18,874,875],{},"@\u003Cscope>\u002Fadapter-\u003Cname>",[18,877,878],{},"kubb-adapter-\u003Cname>",[642,880,881],{},[18,882,63],{},[621,884,885,890,893],{},[642,886,887],{},[18,888,889],{},"meta.name",[642,891,892],{},"The spec identifier, in lowercase",[642,894,895],{},[18,896,897],{},"'oas'",[621,899,900,903,908],{},[642,901,902],{},"Factory export",[642,904,905],{},[18,906,907],{},"adapter\u003CName>",[642,909,910],{},[18,911,912],{},"adapterOas",[621,914,915,918,923],{},[642,916,917],{},"Name constant",[642,919,920],{},[18,921,922],{},"adapter\u003CName>Name",[642,924,925],{},[18,926,927],{},"adapterOasName",[621,929,930,935,940],{},[642,931,932,934],{},[18,933,153],{}," alias",[642,936,937],{},[18,938,939],{},"Adapter\u003CName>",[642,941,942],{},[18,943,944],{},"AdapterOas",{"title":946,"searchDepth":947,"depth":947,"links":948},"",5,[949],{"id":847,"depth":950,"text":848},2,"Build a Kubb adapter with defineExtension and kind adapter. It converts an input spec into the universal AST. Covers the Adapter interface.","md",{"layout":954,"title":5,"description":951,"outline":955,"order":947,"navigation":957},"doc",[950,956],3,{"title":958,"icon":959},"Adapters","i-iconoir-link",{"layout":954,"outline":961},[950,956],{"title":958,"icon":959},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fadapters",{"title":5,"description":951},{"loc":963},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fadapters.md","docs\u002F5.x\u002Freference\u002Fkit\u002Fadapters","_mzEUqZ4ZBuHctWcXBeUfxfHnodO5jCCz1c6MIJJFeI",1795989036858,"2e8b4c62-5b8c-4587-97c0-530d08a9bd53"]