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