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