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