[{"data":1,"prerenderedAt":1960,"buildId":1961},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Fmigrate\u002Ffrom-openapi-typescript":3},{"id":4,"title":5,"body":6,"description":1942,"extension":1943,"frontmatter":1944,"heading":5,"meta":1951,"navigation":1953,"order":1947,"path":1954,"seo":1955,"sitemap":1956,"source":1957,"stem":1958,"__hash__":1959},"docs\u002Fdocs\u002F5.x\u002Fmigrate\u002Ffrom-openapi-typescript.md","Move from openapi-typescript to Kubb",{"type":7,"value":8,"toc":1931},"minimark",[9,22,50,55,189],[10,11,12,13,17,18,21],"p",{},"Start with the types, then replace ",[14,15,16],"code",{},"openapi-fetch"," and ",[14,19,20],{},"openapi-react-query",". You can stop after any step.",[10,23,24,29,30,34,35,39,40,17,42,44,45,49],{},[25,26,28],"a",{"href":27},"https:\u002F\u002Fopenapi-ts.dev","openapi-typescript"," (",[25,31,33],{"href":32},"https:\u002F\u002Fgithub.com\u002Fopenapi-ts\u002Fopenapi-typescript","GitHub",") gets ",[25,36,38],{"href":37},"https:\u002F\u002Fgithub.com\u002Fopenapi-ts\u002Fopenapi-typescript\u002Fissues\u002F2874","no more updates, security fixes included",", and ",[14,41,16],{},[14,43,20],{}," are in ",[25,46,48],{"href":47},"https:\u002F\u002Fgithub.com\u002Fopenapi-ts\u002Fopenapi-typescript\u002Fdiscussions\u002F2559","maintenance mode",". openapi-typescript 7.13.0 also needs TypeScript 5 and fails on TypeScript 7, which Kubb supports.",[51,52,54],"h2",{"id":53},"what-maps-to-what","What maps to what",[56,57,58,70],"table",{},[59,60,61],"thead",{},[62,63,64,67],"tr",{},[65,66,28],"th",{},[65,68,69],{},"Kubb",[71,72,73,86,98,110,129,141,153,165,177],"tbody",{},[62,74,75,81],{},[76,77,78],"td",{},[14,79,80],{},"components['schemas']['Pet']",[76,82,83],{},[14,84,85],{},"Pet",[62,87,88,93],{},[76,89,90],{},[14,91,92],{},"paths['\u002Fpet\u002F{petId}']['get']['parameters']['path']",[76,94,95],{},[14,96,97],{},"GetPetByIdPath",[62,99,100,105],{},[76,101,102],{},[14,103,104],{},"paths['\u002Fpet\u002F{petId}']['get']['responses'][200]['content']['application\u002Fjson']",[76,106,107],{},[14,108,109],{},"GetPetByIdStatus200Json",[62,111,112,117],{},[76,113,114],{},[14,115,116],{},"--enum",[76,118,119,125,126],{},[25,120,122],{"href":121},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-ts\u002Foptions#enumtype",[14,123,124],{},"enum: { type: 'enum' }"," on ",[14,127,128],{},"pluginTs",[62,130,131,136],{},[76,132,133],{},[14,134,135],{},"client.GET('\u002Fpet\u002F{petId}', { params: { path: { petId: 1 } } })",[76,137,138],{},[14,139,140],{},"getPetById({ path: { petId: 1 } })",[62,142,143,148],{},[76,144,145],{},[14,146,147],{},"createClient({ baseUrl })",[76,149,150],{},[14,151,152],{},"client.setConfig({ baseURL })",[62,154,155,160],{},[76,156,157],{},[14,158,159],{},"client.use({ onRequest })",[76,161,162],{},[14,163,164],{},"client.interceptors.request.use()",[62,166,167,172],{},[76,168,169],{},[14,170,171],{},"$api.useQuery('get', '\u002Fpet\u002F{petId}', ...)",[76,173,174],{},[14,175,176],{},"useQuery(getPetByIdQueryOptions(...))",[62,178,179,184],{},[76,180,181],{},[14,182,183],{},"$api.useMutation('post', '\u002Fpet')",[76,185,186],{},[14,187,188],{},"useMutation(addPetMutationOptions())",[190,191,193,197,224,418,425,549,566,656,660,667,787,790,794,801,879,891,990,1006,1381,1392,1448,1455,1459,1477,1552,1565,1907,1911],"steps",{"level":192},"2",[51,194,196],{"id":195},"generate-the-types","Generate the types",[10,198,199,200,203,204,207,208,211,212,215,216,219,220,223],{},"Create this config. It writes every type into ",[14,201,202],{},"src\u002Fgen\u002Ftypes.ts",", like the single ",[14,205,206],{},"schema.d.ts"," from openapi-typescript. ",[14,209,210],{},"integerType: 'number'"," keeps ",[14,213,214],{},"int64"," as ",[14,217,218],{},"number",", as openapi-typescript does. Kubb's default is ",[14,221,222],{},"bigint",".",[225,226,231],"pre",{"language":227,"filename":228,"code":229,"class":230},"typescript","kubb.config.ts","import { defineConfig } from 'kubb\u002Fconfig'\nimport { adapterOas } from '@kubb\u002Fadapter-oas'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\n\nexport default defineConfig({\n input: '.\u002Fopenapi.yaml',\n output: { path: '.\u002Fsrc\u002Fgen' },\n adapter: adapterOas({ integerType: 'number' }),\n plugins: [pluginTs({ output: { path: 'types.ts' } })],\n})","highlights",[14,232,234,261,262,261,278,261,294,261,296,261,311,261,328,261,352,261,380,261,414],{"class":233},"language-typescript",[235,236,239,243,247,251,254,257],"span",{"class":237,"style":238},"line","display: inline",[235,240,242],{"style":241},"color:#d73a49;--hls-dark:#f97583","import ",[235,244,246],{"style":245},"color:#005cc5;--hls-dark:#79b8ff","{ ",[235,248,250],{"style":249},"color:#24292e;--hls-dark:#e1e4e8","defineConfig ",[235,252,253],{"style":245},"} ",[235,255,256],{"style":241},"from ",[235,258,260],{"style":259},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[235,263,264,266,268,271,273,275],{"class":237,"style":238},[235,265,242],{"style":241},[235,267,246],{"style":245},[235,269,270],{"style":249},"adapterOas ",[235,272,253],{"style":245},[235,274,256],{"style":241},[235,276,277],{"style":259},"'@kubb\u002Fadapter-oas'",[235,279,280,282,284,287,289,291],{"class":237,"style":238},[235,281,242],{"style":241},[235,283,246],{"style":245},[235,285,286],{"style":249},"pluginTs ",[235,288,253],{"style":245},[235,290,256],{"style":241},[235,292,293],{"style":259},"'@kubb\u002Fplugin-ts'",[235,295],{"class":237,"style":238},[235,297,298,301,304,308],{"class":237,"style":238},[235,299,300],{"style":241},"export ",[235,302,303],{"style":241},"default ",[235,305,307],{"style":306},"color:#6f42c1;--hls-dark:#b392f0","defineConfig",[235,309,310],{"style":245},"({",[235,312,313,316,319,322,325],{"class":237,"style":238},[235,314,315],{"style":245}," ",[235,317,318],{"style":245},"input",[235,320,321],{"style":241},": ",[235,323,324],{"style":259},"'.\u002Fopenapi.yaml'",[235,326,327],{"style":241},",",[235,329,330,332,335,337,339,342,344,347,350],{"class":237,"style":238},[235,331,315],{"style":241},[235,333,334],{"style":245},"output",[235,336,321],{"style":241},[235,338,246],{"style":245},[235,340,341],{"style":245},"path",[235,343,321],{"style":241},[235,345,346],{"style":259},"'.\u002Fsrc\u002Fgen' ",[235,348,349],{"style":245},"}",[235,351,327],{"style":241},[235,353,354,356,359,361,364,367,370,372,375,378],{"class":237,"style":238},[235,355,315],{"style":241},[235,357,358],{"style":245},"adapter",[235,360,321],{"style":241},[235,362,363],{"style":306},"adapterOas",[235,365,366],{"style":245},"({ ",[235,368,369],{"style":245},"integerType",[235,371,321],{"style":241},[235,373,374],{"style":259},"'number' ",[235,376,377],{"style":245},"})",[235,379,327],{"style":241},[235,381,382,384,387,389,392,394,396,398,400,402,404,406,409,412],{"class":237,"style":238},[235,383,315],{"style":241},[235,385,386],{"style":245},"plugins",[235,388,321],{"style":241},[235,390,391],{"style":245},"[",[235,393,128],{"style":306},[235,395,366],{"style":245},[235,397,334],{"style":245},[235,399,321],{"style":241},[235,401,246],{"style":245},[235,403,341],{"style":245},[235,405,321],{"style":241},[235,407,408],{"style":259},"'types.ts' ",[235,410,411],{"style":245},"} })]",[235,413,327],{"style":241},[235,415,416],{"class":237,"style":238},[235,417,377],{"style":245},[10,419,420,421,424],{},"Install the packages it imports. ",[14,422,423],{},"kubb add"," needs the config to exist, and leaves a plugin that is already in it unchanged:",[426,427,429,460,485,506,527],"code-group",{"sync":428},"package-manager",[225,430,434],{"language":431,"filename":432,"code":433,"class":230},"shell","kubb","npm install -D kubb\nkubb add adapter-oas\nkubb add plugin-ts",[14,435,437,261,445,261,453],{"class":436},"language-shell",[235,438,439,442],{"class":237,"style":238},[235,440,441],{"style":306},"npm ",[235,443,444],{"style":249},"install -D kubb",[235,446,447,450],{"class":237,"style":238},[235,448,449],{"style":306},"kubb ",[235,451,452],{"style":249},"add adapter-oas",[235,454,455,457],{"class":237,"style":238},[235,456,449],{"style":306},[235,458,459],{"style":249},"add plugin-ts",[225,461,464],{"language":431,"filename":462,"code":463,"class":230},"pnpm","pnpm add -D kubb @kubb\u002Fadapter-oas @kubb\u002Fplugin-ts",[14,465,466],{"class":436},[235,467,468,471,474,477,480,482],{"class":237,"style":238},[235,469,470],{"style":306},"pnpm ",[235,472,473],{"style":249},"add -D kubb ",[235,475,476],{"style":249},"@",[235,478,479],{"style":249},"kubb\u002Fadapter-oas ",[235,481,476],{"style":249},[235,483,484],{"style":249},"kubb\u002Fplugin-ts",[225,486,489],{"language":431,"filename":487,"code":488,"class":230},"npm","npm install -D kubb @kubb\u002Fadapter-oas @kubb\u002Fplugin-ts",[14,490,491],{"class":436},[235,492,493,495,498,500,502,504],{"class":237,"style":238},[235,494,441],{"style":306},[235,496,497],{"style":249},"install -D kubb ",[235,499,476],{"style":249},[235,501,479],{"style":249},[235,503,476],{"style":249},[235,505,484],{"style":249},[225,507,510],{"language":431,"filename":508,"code":509,"class":230},"yarn","yarn add -D kubb @kubb\u002Fadapter-oas @kubb\u002Fplugin-ts",[14,511,512],{"class":436},[235,513,514,517,519,521,523,525],{"class":237,"style":238},[235,515,516],{"style":306},"yarn ",[235,518,473],{"style":249},[235,520,476],{"style":249},[235,522,479],{"style":249},[235,524,476],{"style":249},[235,526,484],{"style":249},[225,528,531],{"language":431,"filename":529,"code":530,"class":230},"bun","bun add -d kubb @kubb\u002Fadapter-oas @kubb\u002Fplugin-ts",[14,532,533],{"class":436},[235,534,535,538,541,543,545,547],{"class":237,"style":238},[235,536,537],{"style":306},"bun ",[235,539,540],{"style":249},"add -d kubb ",[235,542,476],{"style":249},[235,544,479],{"style":249},[235,546,476],{"style":249},[235,548,484],{"style":249},[10,550,551,552,555,556,559,560,562,563,565],{},"Change your ",[14,553,554],{},"generate"," script to ",[14,557,558],{},"kubb generate"," and run it. Leave ",[14,561,206],{}," in place until the last step, because ",[14,564,16],{}," reads it. That file stops following the spec once openapi-typescript no longer runs. If you pause before the last step, run both commands in the script:",[426,567,568,615],{},[225,569,573],{"language":570,"filename":571,"code":572,"class":230},"json","Before","{\n \"scripts\": {\n \"generate\": \"openapi-typescript .\u002Fopenapi.yaml -o .\u002Fsrc\u002Fschema.d.ts\"\n }\n}",[14,574,576,261,581,261,592,261,605,261,611],{"class":575},"language-json",[235,577,578],{"class":237,"style":238},[235,579,580],{"style":245},"{",[235,582,583,585,588,590],{"class":237,"style":238},[235,584,315],{"style":245},[235,586,587],{"style":245},"\"scripts\"",[235,589,321],{"style":241},[235,591,580],{"style":245},[235,593,594,597,600,602],{"class":237,"style":238},[235,595,596],{"style":245}," ",[235,598,599],{"style":245},"\"generate\"",[235,601,321],{"style":241},[235,603,604],{"style":259},"\"openapi-typescript .\u002Fopenapi.yaml -o .\u002Fsrc\u002Fschema.d.ts\"",[235,606,607,609],{"class":237,"style":238},[235,608,315],{"style":259},[235,610,349],{"style":245},[235,612,613],{"class":237,"style":238},[235,614,349],{"style":245},[225,616,619],{"language":570,"filename":617,"code":618,"class":230},"After","{\n \"scripts\": {\n \"generate\": \"kubb generate\"\n }\n}",[14,620,621,261,625,261,635,261,646,261,652],{"class":575},[235,622,623],{"class":237,"style":238},[235,624,580],{"style":245},[235,626,627,629,631,633],{"class":237,"style":238},[235,628,315],{"style":245},[235,630,587],{"style":245},[235,632,321],{"style":241},[235,634,580],{"style":245},[235,636,637,639,641,643],{"class":237,"style":238},[235,638,596],{"style":245},[235,640,599],{"style":245},[235,642,321],{"style":241},[235,644,645],{"style":259},"\"kubb generate\"",[235,647,648,650],{"class":237,"style":238},[235,649,315],{"style":259},[235,651,349],{"style":245},[235,653,654],{"class":237,"style":238},[235,655,349],{"style":245},[51,657,659],{"id":658},"replace-the-type-lookups","Replace the type lookups",[10,661,662,663,666],{},"Kubb exports each type by name, named after the schema or the ",[14,664,665],{},"operationId",":",[426,668,669,761],{},[225,670,672],{"language":227,"filename":28,"code":671,"class":230},"import type { components, paths } from '.\u002Fschema'\n\ntype Pet = components['schemas']['Pet']\ntype GetPetByIdParams = paths['\u002Fpet\u002F{petId}']['get']['parameters']['path']",[14,673,674,261,699,261,701,261,727],{"class":233},[235,675,676,678,681,683,686,689,692,694,696],{"class":237,"style":238},[235,677,242],{"style":241},[235,679,680],{"style":249},"type ",[235,682,246],{"style":245},[235,684,685],{"style":249},"components",[235,687,688],{"style":241},", ",[235,690,691],{"style":249},"paths ",[235,693,253],{"style":245},[235,695,256],{"style":241},[235,697,698],{"style":259},"'.\u002Fschema'",[235,700],{"class":237,"style":238},[235,702,703,705,708,711,713,715,718,721,724],{"class":237,"style":238},[235,704,680],{"style":241},[235,706,707],{"style":306},"Pet ",[235,709,710],{"style":241},"= ",[235,712,685],{"style":249},[235,714,391],{"style":245},[235,716,717],{"style":259},"'schemas'",[235,719,720],{"style":245},"][",[235,722,723],{"style":259},"'Pet'",[235,725,726],{"style":245},"]",[235,728,729,731,734,736,739,741,744,746,749,751,754,756,759],{"class":237,"style":238},[235,730,680],{"style":241},[235,732,733],{"style":306},"GetPetByIdParams ",[235,735,710],{"style":241},[235,737,738],{"style":249},"paths",[235,740,391],{"style":245},[235,742,743],{"style":259},"'\u002Fpet\u002F{petId}'",[235,745,720],{"style":245},[235,747,748],{"style":259},"'get'",[235,750,720],{"style":245},[235,752,753],{"style":259},"'parameters'",[235,755,720],{"style":245},[235,757,758],{"style":259},"'path'",[235,760,726],{"style":245},[225,762,764],{"language":227,"filename":69,"code":763,"class":230},"import type { GetPetByIdPath, Pet } from '.\u002Fgen\u002Ftypes'",[14,765,766],{"class":233},[235,767,768,770,772,774,776,778,780,782,784],{"class":237,"style":238},[235,769,242],{"style":241},[235,771,680],{"style":249},[235,773,246],{"style":245},[235,775,97],{"style":306},[235,777,688],{"style":241},[235,779,707],{"style":306},[235,781,253],{"style":245},[235,783,256],{"style":241},[235,785,786],{"style":259},"'.\u002Fgen\u002Ftypes'",[10,788,789],{},"Run your type check and fix the imports it reports.",[51,791,793],{"id":792},"replace-openapi-fetch","Replace openapi-fetch",[10,795,796,797,800],{},"Add ",[14,798,799],{},"@kubb\u002Fplugin-fetch",". It writes one function per operation, and the app needs no client package:",[426,802,803,815,832,848,863],{"sync":428},[225,804,806],{"language":431,"filename":432,"code":805,"class":230},"kubb add plugin-fetch",[14,807,808],{"class":436},[235,809,810,812],{"class":237,"style":238},[235,811,449],{"style":306},[235,813,814],{"style":249},"add plugin-fetch",[225,816,818],{"language":431,"filename":462,"code":817,"class":230},"pnpm add -D @kubb\u002Fplugin-fetch",[14,819,820],{"class":436},[235,821,822,824,827,829],{"class":237,"style":238},[235,823,470],{"style":306},[235,825,826],{"style":249},"add -D ",[235,828,476],{"style":249},[235,830,831],{"style":249},"kubb\u002Fplugin-fetch",[225,833,835],{"language":431,"filename":487,"code":834,"class":230},"npm install -D @kubb\u002Fplugin-fetch",[14,836,837],{"class":436},[235,838,839,841,844,846],{"class":237,"style":238},[235,840,441],{"style":306},[235,842,843],{"style":249},"install -D ",[235,845,476],{"style":249},[235,847,831],{"style":249},[225,849,851],{"language":431,"filename":508,"code":850,"class":230},"yarn add -D @kubb\u002Fplugin-fetch",[14,852,853],{"class":436},[235,854,855,857,859,861],{"class":237,"style":238},[235,856,516],{"style":306},[235,858,826],{"style":249},[235,860,476],{"style":249},[235,862,831],{"style":249},[225,864,866],{"language":431,"filename":529,"code":865,"class":230},"bun add -d @kubb\u002Fplugin-fetch",[14,867,868],{"class":436},[235,869,870,872,875,877],{"class":237,"style":238},[235,871,537],{"style":306},[235,873,874],{"style":249},"add -d ",[235,876,476],{"style":249},[235,878,831],{"style":249},[10,880,881,883,884,887,888,890],{},[14,882,423],{}," adds ",[14,885,886],{},"pluginFetch()"," to ",[14,889,386],{},". With a package manager, add the import and the plugin yourself. Then set its options:",[225,892,894],{"language":227,"filename":228,"code":893,"class":230},"import { pluginFetch } from '@kubb\u002Fplugin-fetch'\n\n\u002F\u002F ...\nplugins: [\n pluginTs({ output: { path: 'types.ts' } }),\n pluginFetch({ baseURL: 'https:\u002F\u002Fpetstore.swagger.io\u002Fv2', throwOnErrorDefault: false }),\n],",[14,895,896,261,912,261,914,261,920,261,928,261,953,261,984],{"class":233},[235,897,898,900,902,905,907,909],{"class":237,"style":238},[235,899,242],{"style":241},[235,901,246],{"style":245},[235,903,904],{"style":249},"pluginFetch ",[235,906,253],{"style":245},[235,908,256],{"style":241},[235,910,911],{"style":259},"'@kubb\u002Fplugin-fetch'",[235,913],{"class":237,"style":238},[235,915,916],{"class":237,"style":238},[235,917,919],{"style":918},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F ...",[235,921,922,924,926],{"class":237,"style":238},[235,923,386],{"style":249},[235,925,321],{"style":241},[235,927,391],{"style":245},[235,929,930,932,934,936,938,940,942,944,946,948,951],{"class":237,"style":238},[235,931,315],{"style":245},[235,933,128],{"style":306},[235,935,366],{"style":245},[235,937,334],{"style":245},[235,939,321],{"style":241},[235,941,246],{"style":245},[235,943,341],{"style":245},[235,945,321],{"style":241},[235,947,408],{"style":259},[235,949,950],{"style":245},"} })",[235,952,327],{"style":241},[235,954,955,957,960,962,965,967,970,972,975,977,980,982],{"class":237,"style":238},[235,956,315],{"style":241},[235,958,959],{"style":306},"pluginFetch",[235,961,366],{"style":245},[235,963,964],{"style":245},"baseURL",[235,966,321],{"style":241},[235,968,969],{"style":259},"'https:\u002F\u002Fpetstore.swagger.io\u002Fv2'",[235,971,688],{"style":241},[235,973,974],{"style":245},"throwOnErrorDefault",[235,976,321],{"style":241},[235,978,979],{"style":245},"false ",[235,981,377],{"style":245},[235,983,327],{"style":241},[235,985,986,988],{"class":237,"style":238},[235,987,726],{"style":245},[235,989,327],{"style":241},[10,991,992,995,996,998,999,1002,1003,1005],{},[14,993,994],{},"throwOnErrorDefault: false"," keeps the ",[14,997,16],{}," behavior: an error status resolves with ",[14,1000,1001],{},"error"," set instead of throwing. Run ",[14,1004,558],{},", then replace each call:",[426,1007,1008,1228],{},[225,1009,1011],{"language":227,"filename":16,"code":1010,"class":230},"import createClient from 'openapi-fetch'\nimport type { paths } from '.\u002Fschema'\n\nconst client = createClient\u003Cpaths>({ baseUrl: 'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' })\nclient.use({\n onRequest({ request }) {\n request.headers.set('Authorization', `Bearer ${token}`)\n return request\n },\n})\n\nconst { data, error } = await client.GET('\u002Fpet\u002F{petId}', { params: { path: { petId: 1 } } })",[14,1012,1013,261,1025,261,1041,261,1043,261,1076,261,1088,261,1103,261,1145,261,1154,261,1162,261,1166,261,1168],{"class":233},[235,1014,1015,1017,1020,1022],{"class":237,"style":238},[235,1016,242],{"style":241},[235,1018,1019],{"style":249},"createClient ",[235,1021,256],{"style":241},[235,1023,1024],{"style":259},"'openapi-fetch'",[235,1026,1027,1029,1031,1033,1035,1037,1039],{"class":237,"style":238},[235,1028,242],{"style":241},[235,1030,680],{"style":249},[235,1032,246],{"style":245},[235,1034,691],{"style":249},[235,1036,253],{"style":245},[235,1038,256],{"style":241},[235,1040,698],{"style":259},[235,1042],{"class":237,"style":238},[235,1044,1045,1048,1051,1053,1056,1059,1061,1064,1066,1069,1071,1074],{"class":237,"style":238},[235,1046,1047],{"style":241},"const ",[235,1049,1050],{"style":249},"client ",[235,1052,710],{"style":241},[235,1054,1055],{"style":249},"createClient",[235,1057,1058],{"style":241},"\u003C",[235,1060,738],{"style":249},[235,1062,1063],{"style":241},">",[235,1065,366],{"style":245},[235,1067,1068],{"style":245},"baseUrl",[235,1070,321],{"style":241},[235,1072,1073],{"style":259},"'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' ",[235,1075,377],{"style":245},[235,1077,1078,1081,1083,1086],{"class":237,"style":238},[235,1079,1080],{"style":249},"client",[235,1082,223],{"style":241},[235,1084,1085],{"style":306},"use",[235,1087,310],{"style":245},[235,1089,1090,1092,1095,1097,1100],{"class":237,"style":238},[235,1091,315],{"style":245},[235,1093,1094],{"style":306},"onRequest",[235,1096,366],{"style":245},[235,1098,1099],{"style":249},"request ",[235,1101,1102],{"style":245},"}) {",[235,1104,1105,1107,1110,1112,1115,1117,1120,1123,1126,1128,1131,1134,1137,1139,1142],{"class":237,"style":238},[235,1106,596],{"style":245},[235,1108,1109],{"style":249},"request",[235,1111,223],{"style":241},[235,1113,1114],{"style":245},"headers",[235,1116,223],{"style":241},[235,1118,1119],{"style":306},"set",[235,1121,1122],{"style":245},"(",[235,1124,1125],{"style":259},"'Authorization'",[235,1127,688],{"style":241},[235,1129,1130],{"style":259},"`Bearer ",[235,1132,1133],{"style":249},"${",[235,1135,1136],{"style":249},"token",[235,1138,349],{"style":249},[235,1140,1141],{"style":259},"`",[235,1143,1144],{"style":245},")",[235,1146,1147,1149,1152],{"class":237,"style":238},[235,1148,596],{"style":245},[235,1150,1151],{"style":241},"return ",[235,1153,1109],{"style":249},[235,1155,1156,1158,1160],{"class":237,"style":238},[235,1157,315],{"style":249},[235,1159,349],{"style":245},[235,1161,327],{"style":241},[235,1163,1164],{"class":237,"style":238},[235,1165,377],{"style":245},[235,1167],{"class":237,"style":238},[235,1169,1170,1172,1174,1177,1179,1182,1184,1186,1189,1191,1193,1196,1198,1200,1202,1204,1207,1209,1211,1213,1215,1217,1220,1222,1225],{"class":237,"style":238},[235,1171,1047],{"style":241},[235,1173,246],{"style":245},[235,1175,1176],{"style":249},"data",[235,1178,688],{"style":241},[235,1180,1181],{"style":249},"error ",[235,1183,253],{"style":245},[235,1185,710],{"style":241},[235,1187,1188],{"style":241},"await ",[235,1190,1080],{"style":249},[235,1192,223],{"style":241},[235,1194,1195],{"style":306},"GET",[235,1197,1122],{"style":245},[235,1199,743],{"style":259},[235,1201,688],{"style":241},[235,1203,246],{"style":245},[235,1205,1206],{"style":245},"params",[235,1208,321],{"style":241},[235,1210,246],{"style":245},[235,1212,341],{"style":245},[235,1214,321],{"style":241},[235,1216,246],{"style":245},[235,1218,1219],{"style":245},"petId",[235,1221,321],{"style":241},[235,1223,1224],{"style":245},"1 ",[235,1226,1227],{"style":245},"} } })",[225,1229,1231],{"language":227,"filename":69,"code":1230,"class":230},"import { client } from '.\u002Fgen\u002F.kubb\u002Fclient'\nimport { getPetById } from '.\u002Fgen\u002Fclients\u002FgetPetById'\n\nclient.interceptors.request.use((request) => {\n request.headers['Authorization'] = `Bearer ${token}`\n return request\n})\n\nconst { data, error, status } = await getPetById({ path: { petId: 1 } })",[14,1232,1233,261,1248,261,1264,261,1266,261,1296,261,1325,261,1333,261,1337,261,1339],{"class":233},[235,1234,1235,1237,1239,1241,1243,1245],{"class":237,"style":238},[235,1236,242],{"style":241},[235,1238,246],{"style":245},[235,1240,1050],{"style":249},[235,1242,253],{"style":245},[235,1244,256],{"style":241},[235,1246,1247],{"style":259},"'.\u002Fgen\u002F.kubb\u002Fclient'",[235,1249,1250,1252,1254,1257,1259,1261],{"class":237,"style":238},[235,1251,242],{"style":241},[235,1253,246],{"style":245},[235,1255,1256],{"style":249},"getPetById ",[235,1258,253],{"style":245},[235,1260,256],{"style":241},[235,1262,1263],{"style":259},"'.\u002Fgen\u002Fclients\u002FgetPetById'",[235,1265],{"class":237,"style":238},[235,1267,1268,1270,1272,1275,1277,1279,1281,1283,1286,1288,1291,1294],{"class":237,"style":238},[235,1269,1080],{"style":249},[235,1271,223],{"style":241},[235,1273,1274],{"style":245},"interceptors",[235,1276,223],{"style":241},[235,1278,1109],{"style":245},[235,1280,223],{"style":241},[235,1282,1085],{"style":306},[235,1284,1285],{"style":245},"((",[235,1287,1109],{"style":249},[235,1289,1290],{"style":245},") ",[235,1292,1293],{"style":241},"=> ",[235,1295,580],{"style":245},[235,1297,1298,1300,1302,1304,1306,1308,1310,1313,1315,1317,1319,1321,1323],{"class":237,"style":238},[235,1299,315],{"style":245},[235,1301,1109],{"style":249},[235,1303,223],{"style":241},[235,1305,1114],{"style":245},[235,1307,391],{"style":245},[235,1309,1125],{"style":259},[235,1311,1312],{"style":245},"] ",[235,1314,710],{"style":241},[235,1316,1130],{"style":259},[235,1318,1133],{"style":249},[235,1320,1136],{"style":249},[235,1322,349],{"style":249},[235,1324,1141],{"style":259},[235,1326,1327,1329,1331],{"class":237,"style":238},[235,1328,315],{"style":259},[235,1330,1151],{"style":241},[235,1332,1109],{"style":249},[235,1334,1335],{"class":237,"style":238},[235,1336,377],{"style":245},[235,1338],{"class":237,"style":238},[235,1340,1341,1343,1345,1347,1349,1351,1353,1356,1358,1360,1362,1365,1367,1369,1371,1373,1375,1377,1379],{"class":237,"style":238},[235,1342,1047],{"style":241},[235,1344,246],{"style":245},[235,1346,1176],{"style":249},[235,1348,688],{"style":241},[235,1350,1001],{"style":249},[235,1352,688],{"style":241},[235,1354,1355],{"style":249},"status ",[235,1357,253],{"style":245},[235,1359,710],{"style":241},[235,1361,1188],{"style":241},[235,1363,1364],{"style":306},"getPetById",[235,1366,366],{"style":245},[235,1368,341],{"style":245},[235,1370,321],{"style":241},[235,1372,246],{"style":245},[235,1374,1219],{"style":245},[235,1376,321],{"style":241},[235,1378,1224],{"style":245},[235,1380,950],{"style":245},[10,1382,1383,1384,1387,1388,1391],{},"Like the middleware, the interceptor sends the header on every request. To send it only to operations that declare a security scheme, set ",[14,1385,1386],{},"auth"," instead. It gets each scheme, and its return value goes where that scheme says, such as the ",[14,1389,1390],{},"api_key"," header, so return the right credential per scheme:",[225,1393,1395],{"language":227,"code":1394,"class":230},"client.setConfig({ auth: (scheme) => (scheme.type === 'apiKey' ? apiKey : token) })",[14,1396,1397],{"class":233},[235,1398,1399,1401,1403,1406,1408,1410,1412,1414,1417,1419,1421,1423,1425,1427,1429,1432,1435,1438,1441,1443,1445],{"class":237,"style":238},[235,1400,1080],{"style":249},[235,1402,223],{"style":241},[235,1404,1405],{"style":306},"setConfig",[235,1407,366],{"style":245},[235,1409,1386],{"style":245},[235,1411,321],{"style":241},[235,1413,1122],{"style":245},[235,1415,1416],{"style":249},"scheme",[235,1418,1290],{"style":245},[235,1420,1293],{"style":241},[235,1422,1122],{"style":245},[235,1424,1416],{"style":249},[235,1426,223],{"style":241},[235,1428,680],{"style":245},[235,1430,1431],{"style":241},"=== ",[235,1433,1434],{"style":259},"'apiKey' ",[235,1436,1437],{"style":241},"? ",[235,1439,1440],{"style":249},"apiKey ",[235,1442,321],{"style":241},[235,1444,1136],{"style":249},[235,1446,1447],{"style":245},") })",[10,1449,1450,1454],{},[25,1451,1453],{"href":1452},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fconfigure-requests","Configure requests"," covers both.",[51,1456,1458],{"id":1457},"replace-openapi-react-query","Replace openapi-react-query",[10,1460,796,1461,1467,1468,1471,1472,1474,1475,666],{},[25,1462,1464],{"href":1463},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-react-query",[14,1465,1466],{},"@kubb\u002Fplugin-react-query",". With a package manager, also add ",[14,1469,1470],{},"pluginReactQuery()"," after ",[14,1473,959],{}," in ",[14,1476,386],{},[426,1478,1479,1491,1507,1522,1537],{"sync":428},[225,1480,1482],{"language":431,"filename":432,"code":1481,"class":230},"kubb add plugin-react-query",[14,1483,1484],{"class":436},[235,1485,1486,1488],{"class":237,"style":238},[235,1487,449],{"style":306},[235,1489,1490],{"style":249},"add plugin-react-query",[225,1492,1494],{"language":431,"filename":462,"code":1493,"class":230},"pnpm add -D @kubb\u002Fplugin-react-query",[14,1495,1496],{"class":436},[235,1497,1498,1500,1502,1504],{"class":237,"style":238},[235,1499,470],{"style":306},[235,1501,826],{"style":249},[235,1503,476],{"style":249},[235,1505,1506],{"style":249},"kubb\u002Fplugin-react-query",[225,1508,1510],{"language":431,"filename":487,"code":1509,"class":230},"npm install -D @kubb\u002Fplugin-react-query",[14,1511,1512],{"class":436},[235,1513,1514,1516,1518,1520],{"class":237,"style":238},[235,1515,441],{"style":306},[235,1517,843],{"style":249},[235,1519,476],{"style":249},[235,1521,1506],{"style":249},[225,1523,1525],{"language":431,"filename":508,"code":1524,"class":230},"yarn add -D @kubb\u002Fplugin-react-query",[14,1526,1527],{"class":436},[235,1528,1529,1531,1533,1535],{"class":237,"style":238},[235,1530,516],{"style":306},[235,1532,826],{"style":249},[235,1534,476],{"style":249},[235,1536,1506],{"style":249},[225,1538,1540],{"language":431,"filename":529,"code":1539,"class":230},"bun add -d @kubb\u002Fplugin-react-query",[14,1541,1542],{"class":436},[235,1543,1544,1546,1548,1550],{"class":237,"style":238},[235,1545,537],{"style":306},[235,1547,874],{"style":249},[235,1549,476],{"style":249},[235,1551,1506],{"style":249},[10,1553,1554,1555,1557,1558,17,1561,1564],{},"The plugin writes query and mutation options per operation. Run ",[14,1556,558],{},", then replace each ",[14,1559,1560],{},"$api.useQuery",[14,1562,1563],{},"$api.useMutation"," call:",[426,1566,1567,1764],{},[225,1568,1570],{"language":227,"filename":20,"code":1569,"class":230},"import createFetchClient from 'openapi-fetch'\nimport createClient from 'openapi-react-query'\nimport type { paths } from '.\u002Fschema'\n\nconst $api = createClient(createFetchClient\u003Cpaths>({ baseUrl: 'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' }))\n\nconst { data } = $api.useQuery('get', '\u002Fpet\u002F{petId}', { params: { path: { petId: 1 } } })\nconst { mutate } = $api.useMutation('post', '\u002Fpet')\nmutate({ body: { name: 'Rex', photoUrls: [] } })",[14,1571,1572,261,1583,261,1594,261,1610,261,1612,261,1645,261,1647,261,1700,261,1732],{"class":233},[235,1573,1574,1576,1579,1581],{"class":237,"style":238},[235,1575,242],{"style":241},[235,1577,1578],{"style":249},"createFetchClient ",[235,1580,256],{"style":241},[235,1582,1024],{"style":259},[235,1584,1585,1587,1589,1591],{"class":237,"style":238},[235,1586,242],{"style":241},[235,1588,1019],{"style":249},[235,1590,256],{"style":241},[235,1592,1593],{"style":259},"'openapi-react-query'",[235,1595,1596,1598,1600,1602,1604,1606,1608],{"class":237,"style":238},[235,1597,242],{"style":241},[235,1599,680],{"style":249},[235,1601,246],{"style":245},[235,1603,691],{"style":249},[235,1605,253],{"style":245},[235,1607,256],{"style":241},[235,1609,698],{"style":259},[235,1611],{"class":237,"style":238},[235,1613,1614,1616,1619,1621,1623,1625,1628,1630,1632,1634,1636,1638,1640,1642],{"class":237,"style":238},[235,1615,1047],{"style":241},[235,1617,1618],{"style":249},"$api ",[235,1620,710],{"style":241},[235,1622,1055],{"style":306},[235,1624,1122],{"style":245},[235,1626,1627],{"style":249},"createFetchClient",[235,1629,1058],{"style":241},[235,1631,738],{"style":249},[235,1633,1063],{"style":241},[235,1635,366],{"style":245},[235,1637,1068],{"style":245},[235,1639,321],{"style":241},[235,1641,1073],{"style":259},[235,1643,1644],{"style":245},"}))",[235,1646],{"class":237,"style":238},[235,1648,1649,1651,1653,1656,1658,1660,1663,1665,1668,1670,1672,1674,1676,1678,1680,1682,1684,1686,1688,1690,1692,1694,1696,1698],{"class":237,"style":238},[235,1650,1047],{"style":241},[235,1652,246],{"style":245},[235,1654,1655],{"style":249},"data ",[235,1657,253],{"style":245},[235,1659,710],{"style":241},[235,1661,1662],{"style":249},"$api",[235,1664,223],{"style":241},[235,1666,1667],{"style":306},"useQuery",[235,1669,1122],{"style":245},[235,1671,748],{"style":259},[235,1673,688],{"style":241},[235,1675,743],{"style":259},[235,1677,688],{"style":241},[235,1679,246],{"style":245},[235,1681,1206],{"style":245},[235,1683,321],{"style":241},[235,1685,246],{"style":245},[235,1687,341],{"style":245},[235,1689,321],{"style":241},[235,1691,246],{"style":245},[235,1693,1219],{"style":245},[235,1695,321],{"style":241},[235,1697,1224],{"style":245},[235,1699,1227],{"style":245},[235,1701,1702,1704,1706,1709,1711,1713,1715,1717,1720,1722,1725,1727,1730],{"class":237,"style":238},[235,1703,1047],{"style":241},[235,1705,246],{"style":245},[235,1707,1708],{"style":249},"mutate ",[235,1710,253],{"style":245},[235,1712,710],{"style":241},[235,1714,1662],{"style":249},[235,1716,223],{"style":241},[235,1718,1719],{"style":306},"useMutation",[235,1721,1122],{"style":245},[235,1723,1724],{"style":259},"'post'",[235,1726,688],{"style":241},[235,1728,1729],{"style":259},"'\u002Fpet'",[235,1731,1144],{"style":245},[235,1733,1734,1737,1739,1742,1744,1746,1749,1751,1754,1756,1759,1761],{"class":237,"style":238},[235,1735,1736],{"style":306},"mutate",[235,1738,366],{"style":245},[235,1740,1741],{"style":245},"body",[235,1743,321],{"style":241},[235,1745,246],{"style":245},[235,1747,1748],{"style":245},"name",[235,1750,321],{"style":241},[235,1752,1753],{"style":259},"'Rex'",[235,1755,688],{"style":241},[235,1757,1758],{"style":245},"photoUrls",[235,1760,321],{"style":241},[235,1762,1763],{"style":245},"[] } })",[225,1765,1767],{"language":227,"filename":69,"code":1766,"class":230},"import { useMutation, useQuery } from '@tanstack\u002Freact-query'\nimport { addPetMutationOptions } from '.\u002Fgen\u002Fhooks\u002FuseAddPet'\nimport { getPetByIdQueryOptions } from '.\u002Fgen\u002Fhooks\u002FuseGetPetById'\n\nconst { data } = useQuery(getPetByIdQueryOptions({ path: { petId: 1 } }))\nconst { mutate } = useMutation(addPetMutationOptions())\nmutate({ body: { name: 'Rex', photoUrls: [] } })",[14,1768,1769,261,1789,261,1805,261,1821,261,1823,261,1859,261,1881],{"class":233},[235,1770,1771,1773,1775,1777,1779,1782,1784,1786],{"class":237,"style":238},[235,1772,242],{"style":241},[235,1774,246],{"style":245},[235,1776,1719],{"style":249},[235,1778,688],{"style":241},[235,1780,1781],{"style":249},"useQuery ",[235,1783,253],{"style":245},[235,1785,256],{"style":241},[235,1787,1788],{"style":259},"'@tanstack\u002Freact-query'",[235,1790,1791,1793,1795,1798,1800,1802],{"class":237,"style":238},[235,1792,242],{"style":241},[235,1794,246],{"style":245},[235,1796,1797],{"style":249},"addPetMutationOptions ",[235,1799,253],{"style":245},[235,1801,256],{"style":241},[235,1803,1804],{"style":259},"'.\u002Fgen\u002Fhooks\u002FuseAddPet'",[235,1806,1807,1809,1811,1814,1816,1818],{"class":237,"style":238},[235,1808,242],{"style":241},[235,1810,246],{"style":245},[235,1812,1813],{"style":249},"getPetByIdQueryOptions ",[235,1815,253],{"style":245},[235,1817,256],{"style":241},[235,1819,1820],{"style":259},"'.\u002Fgen\u002Fhooks\u002FuseGetPetById'",[235,1822],{"class":237,"style":238},[235,1824,1825,1827,1829,1831,1833,1835,1837,1839,1842,1844,1846,1848,1850,1852,1854,1856],{"class":237,"style":238},[235,1826,1047],{"style":241},[235,1828,246],{"style":245},[235,1830,1655],{"style":249},[235,1832,253],{"style":245},[235,1834,710],{"style":241},[235,1836,1667],{"style":306},[235,1838,1122],{"style":245},[235,1840,1841],{"style":306},"getPetByIdQueryOptions",[235,1843,366],{"style":245},[235,1845,341],{"style":245},[235,1847,321],{"style":241},[235,1849,246],{"style":245},[235,1851,1219],{"style":245},[235,1853,321],{"style":241},[235,1855,1224],{"style":245},[235,1857,1858],{"style":245},"} }))",[235,1860,1861,1863,1865,1867,1869,1871,1873,1875,1878],{"class":237,"style":238},[235,1862,1047],{"style":241},[235,1864,246],{"style":245},[235,1866,1708],{"style":249},[235,1868,253],{"style":245},[235,1870,710],{"style":241},[235,1872,1719],{"style":306},[235,1874,1122],{"style":245},[235,1876,1877],{"style":306},"addPetMutationOptions",[235,1879,1880],{"style":245},"())",[235,1882,1883,1885,1887,1889,1891,1893,1895,1897,1899,1901,1903,1905],{"class":237,"style":238},[235,1884,1736],{"style":306},[235,1886,366],{"style":245},[235,1888,1741],{"style":245},[235,1890,321],{"style":241},[235,1892,246],{"style":245},[235,1894,1748],{"style":245},[235,1896,321],{"style":241},[235,1898,1753],{"style":259},[235,1900,688],{"style":241},[235,1902,1758],{"style":245},[235,1904,321],{"style":241},[235,1906,1763],{"style":245},[51,1908,1910],{"id":1909},"remove-openapi-typescript","Remove openapi-typescript",[10,1912,1913,1914,688,1916,1918,1919,1921,1922,1924,1925,688,1927,39,1929,223],{},"Once nothing imports ",[14,1915,206],{},[14,1917,16],{},", or ",[14,1920,20],{},", delete ",[14,1923,206],{}," and uninstall ",[14,1926,28],{},[14,1928,16],{},[14,1930,20],{},{"title":1932,"searchDepth":1933,"depth":1933,"links":1934},"",5,[1935,1937,1938,1939,1940,1941],{"id":53,"depth":1936,"text":54},2,{"id":195,"depth":1936,"text":196},{"id":658,"depth":1936,"text":659},{"id":792,"depth":1936,"text":793},{"id":1457,"depth":1936,"text":1458},{"id":1909,"depth":1936,"text":1910},"Replace openapi-typescript, openapi-fetch, and openapi-react-query with Kubb. Generate the same types, then swap the client and hooks one step at a time.","md",{"layout":1945,"title":5,"description":1942,"outline":1946,"order":1947,"navigation":1948},"doc",[1936,1947],3,{"title":1949,"icon":1950},"Move from openapi-typescript","i-iconoir-git-fork",{"layout":1945,"outline":1952},[1936,1947],{"title":1949,"icon":1950},"\u002Fdocs\u002F5.x\u002Fmigrate\u002Ffrom-openapi-typescript",{"title":5,"description":1942},{"loc":1954},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Fmigrate\u002Ffrom-openapi-typescript.md","docs\u002F5.x\u002Fmigrate\u002Ffrom-openapi-typescript","CxngYRhwnMF7s05Q4b_myorY4RYdOqmoJw1wy4vjFuU",1795727674576,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]