[{"data":1,"prerenderedAt":911,"buildId":912},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fadapters":3},{"id":4,"title":5,"body":6,"description":893,"extension":894,"frontmatter":895,"heading":900,"meta":902,"navigation":904,"order":889,"path":905,"seo":906,"sitemap":907,"source":908,"stem":909,"__hash__":910},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fadapters.md","Adapters - Turn a spec into the Kubb AST",{"type":7,"value":8,"toc":887},"minimark",[9,53,76,445,573,578,758,779,786,791],[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 return ast.factory.createInput({ schemas: [], operations: [] })\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,399,119,406,119,418,119,425,119,433,119,441],{"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,367,369,371,374,376,379,381,384,386,389,391,394,396],{"class":89,"style":90},[87,363,355],{"style":358},[87,365,366],{"style":93},"return ",[87,368,102],{"style":101},[87,370,288],{"style":93},[87,372,373],{"style":97},"factory",[87,375,288],{"style":93},[87,377,378],{"style":131},"createInput",[87,380,279],{"style":97},[87,382,383],{"style":97},"schemas",[87,385,184],{"style":93},[87,387,388],{"style":97},"[]",[87,390,105],{"style":93},[87,392,393],{"style":97},"operations",[87,395,184],{"style":93},[87,397,398],{"style":97},"[] })",[87,400,401,404],{"class":89,"style":90},[87,402,403],{"style":97}," }",[87,405,234],{"style":93},[87,407,408,410,412,415],{"class":89,"style":90},[87,409,322],{"style":93},[87,411,339],{"style":93},[87,413,414],{"style":131},"validate",[87,416,417],{"style":97},"() {",[87,419,420,422],{"class":89,"style":90},[87,421,355],{"style":97},[87,423,424],{"style":358},"\u002F\u002F Throw here when the spec is invalid.",[87,426,427,429,431],{"class":89,"style":90},[87,428,322],{"style":358},[87,430,175],{"style":97},[87,432,234],{"style":93},[87,434,435,437,439],{"class":89,"style":90},[87,436,223],{"style":93},[87,438,300],{"style":97},[87,440,234],{"style":93},[87,442,443],{"class":89,"style":90},[87,444,300],{"style":97},[77,446,449],{"language":79,"filename":447,"code":448,"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,450,451,119,467,119,482,119,484,119,495,119,509,119,532,119,556,119,569],{"class":85},[87,452,453,455,457,460,462,464],{"class":89,"style":90},[87,454,94],{"style":93},[87,456,98],{"style":97},[87,458,459],{"style":101},"defineConfig ",[87,461,111],{"style":97},[87,463,114],{"style":93},[87,465,466],{"style":117},"'kubb\u002Fconfig'",[87,468,469,471,473,475,477,479],{"class":89,"style":90},[87,470,94],{"style":93},[87,472,98],{"style":97},[87,474,204],{"style":101},[87,476,111],{"style":97},[87,478,114],{"style":93},[87,480,481],{"style":117},"'.\u002FadapterCustom.ts'",[87,483],{"class":89,"style":90},[87,485,486,488,491,493],{"class":89,"style":90},[87,487,198],{"style":93},[87,489,490],{"style":93},"default ",[87,492,66],{"style":131},[87,494,218],{"style":97},[87,496,497,499,502,504,507],{"class":89,"style":90},[87,498,223],{"style":97},[87,500,501],{"style":97},"input",[87,503,184],{"style":93},[87,505,506],{"style":117},"'.\u002Fmy-spec.json'",[87,508,234],{"style":93},[87,510,511,513,516,518,520,523,525,528,530],{"class":89,"style":90},[87,512,223],{"style":93},[87,514,515],{"style":97},"output",[87,517,184],{"style":93},[87,519,98],{"style":97},[87,521,522],{"style":97},"path",[87,524,184],{"style":93},[87,526,527],{"style":117},"'.\u002Fsrc\u002Fgen' ",[87,529,175],{"style":97},[87,531,234],{"style":93},[87,533,534,536,538,540,543,545,547,549,552,554],{"class":89,"style":90},[87,535,223],{"style":93},[87,537,74],{"style":97},[87,539,184],{"style":93},[87,541,542],{"style":131},"adapterCustom",[87,544,279],{"style":97},[87,546,166],{"style":97},[87,548,184],{"style":93},[87,550,551],{"style":97},"true ",[87,553,300],{"style":97},[87,555,234],{"style":93},[87,557,558,560,563,565,567],{"class":89,"style":90},[87,559,223],{"style":93},[87,561,562],{"style":97},"plugins",[87,564,184],{"style":93},[87,566,388],{"style":97},[87,568,234],{"style":93},[87,570,571],{"class":89,"style":90},[87,572,300],{"style":97},[10,574,575,577],{},[18,576,39],{}," returns these members:",[579,580,581,600],"table",{},[582,583,584],"thead",{},[585,586,587,591,594,597],"tr",{},[588,589,590],"th",{},"Member",[588,592,593],{},"Type",[588,595,596],{},"Required",[588,598,599],{},"Purpose",[601,602,603,627,651,686,711,732],"tbody",{},[585,604,605,610,615,618],{},[606,607,608],"td",{},[18,609,325],{},[606,611,612],{},[18,613,614],{},"TDocument | null",[606,616,617],{},"Yes",[606,619,620,621,623,624,288],{},"The parsed source document. ",[18,622,330],{}," before ",[18,625,626],{},"parse()",[585,628,629,633,638,640],{},[606,630,631],{},[18,632,342],{},[606,634,635],{},[18,636,637],{},"(source: AdapterSource, options?: { signal?: AbortSignal; fileRefs?: Array\u003Cstring> }) => InputNode | Promise\u003CInputNode>",[606,639,617],{},[606,641,642,643,646,647,650],{},"Converts the spec into the AST. ",[18,644,645],{},"fileRefs"," sets which folders a ",[18,648,649],{},"$ref"," may read local files from: unset allows any file, an empty list allows none, and a list allows only those folders. Kubb passes the list through, and the adapter enforces it.",[585,652,653,657,662,664],{},[606,654,655],{},[18,656,414],{},[606,658,659],{},[18,660,661],{},"(input: string, options?: { throwOnError?: boolean; fileRefs?: Array\u003Cstring> }) => Promise\u003Cvoid>",[606,663,617],{},[606,665,666,667,673,674,677,678,680,681,683,684,288],{},"Validates the document at a path or URL. ",[14,668,670],{"href":669},"\u002Fdocs\u002F5.x\u002Freference\u002Fcommands\u002Fvalidate",[18,671,672],{},"kubb validate"," passes ",[18,675,676],{},"throwOnError: true",", so throw on invalid input. ",[18,679,645],{}," limits local ",[18,682,649],{}," files as in ",[18,685,342],{},[585,687,688,693,698,701],{},[606,689,690],{},[18,691,692],{},"settle",[606,694,695],{},[18,696,697],{},"() => Promise\u003Cvoid>",[606,699,700],{},"No",[606,702,703,704,706,707,710],{},"Waits for work ",[18,705,342],{}," left running, such as validation in a worker. Kubb awaits it before ",[18,708,709],{},"kubb:build:end",". Must not reject.",[585,712,713,718,723,725],{},[606,714,715],{},[18,716,717],{},"locate",[606,719,720],{},[18,721,722],{},"(source: string, location: DiagnosticLocation) => { start: number; end: number } | undefined",[606,724,700],{},[606,726,727,728,731],{},"Finds a diagnostic in the source text for a CLI code frame, as zero-based UTF-16 offsets with ",[18,729,730],{},"end"," exclusive.",[585,733,734,739,744,746],{},[606,735,736],{},[18,737,738],{},"sources",[606,740,741],{},[18,742,743],{},"Array\u003Cstring>",[606,745,700],{},[606,747,748,749,751,752,755,756,288],{},"The files and URLs the last ",[18,750,626],{}," read, for a tool that watches them. ",[18,753,754],{},"kubb generate --watch"," watches only ",[18,757,501],{},[10,759,760,763,764,767,768,771,772,775,776,778],{},[18,761,762],{},"AdapterSource"," is ",[18,765,766],{},"{ type: 'path'; path }"," or ",[18,769,770],{},"{ type: 'data'; data; root? }",", where ",[18,773,774],{},"root"," is the folder relative ",[18,777,649],{},"s resolve from.",[54,780,782,783,785],{"as":781},"important","When the input is invalid, throw from ",[18,784,626],{}," with a clear message.",[787,788,790],"h2",{"id":789},"adapter-naming","Adapter naming",[579,792,793,806],{},[582,794,795],{},[585,796,797,800,803],{},[588,798,799],{},"Surface",[588,801,802],{},"Pattern",[588,804,805],{},"Example",[601,807,808,825,840,855,870],{},[585,809,810,813,821],{},[606,811,812],{},"npm package",[606,814,815,767,818],{},[18,816,817],{},"@\u003Cscope>\u002Fadapter-\u003Cname>",[18,819,820],{},"kubb-adapter-\u003Cname>",[606,822,823],{},[18,824,63],{},[585,826,827,832,835],{},[606,828,829],{},[18,830,831],{},"meta.name",[606,833,834],{},"The spec identifier, in lowercase",[606,836,837],{},[18,838,839],{},"'oas'",[585,841,842,845,850],{},[606,843,844],{},"Factory export",[606,846,847],{},[18,848,849],{},"adapter\u003CName>",[606,851,852],{},[18,853,854],{},"adapterOas",[585,856,857,860,865],{},[606,858,859],{},"Name constant",[606,861,862],{},[18,863,864],{},"adapter\u003CName>Name",[606,866,867],{},[18,868,869],{},"adapterOasName",[585,871,872,877,882],{},[606,873,874,876],{},[18,875,153],{}," alias",[606,878,879],{},[18,880,881],{},"Adapter\u003CName>",[606,883,884],{},[18,885,886],{},"AdapterOas",{"title":888,"searchDepth":889,"depth":889,"links":890},"",5,[891],{"id":789,"depth":892,"text":790},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":896,"title":5,"description":893,"outline":897,"order":889,"navigation":899},"doc",[892,898],3,{"title":900,"icon":901},"Adapters","i-iconoir-link",{"layout":896,"outline":903},[892,898],{"title":900,"icon":901},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fadapters",{"title":5,"description":893},{"loc":905},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fadapters.md","docs\u002F5.x\u002Freference\u002Fkit\u002Fadapters","FX5e5xA8NFQATxg5VsaHpiFAqqVN7yOw6i2Tpq5Hppw",1795727677571,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]