[{"data":1,"prerenderedAt":909,"buildId":910},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-msw\u002Foptions":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":908,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-msw\u002Foptions.md",{},"Options",{"type":8,"value":9,"toc":895},"minimark",[10,25,30,232,236,240,246,277,327,339,341,347,384,430,596,598,600,637,683,690,737,744,765,769,777,804],[11,12,13,14,18,19,24],"p",{},"Pass these options to ",[15,16,17],"code",{},"pluginMsw()",". Shared options link to ",[20,21,23],"a",{"href":22},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options","Shared plugin options",", and this page gives only their default here.",[26,27,29],"h2",{"id":28},"options-overview","Options overview",[31,32,33,49],"table",{},[34,35,36],"thead",{},[37,38,39,43,46],"tr",{},[40,41,42],"th",{},"Option",[40,44,45],{},"Purpose",[40,47,48],{},"Default",[50,51,52,71,87,102,124,142,157,175,192,215],"tbody",{},[37,53,54,63,66],{},[55,56,57],"td",{},[20,58,60],{"href":59},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options#output",[15,61,62],{},"output",[55,64,65],{},"Where files are written.",[55,67,68],{},[15,69,70],{},"{ path: 'handlers', barrel: { type: 'named' } }",[37,72,73,81,84],{},[55,74,75],{},[20,76,78],{"href":77},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options#group",[15,79,80],{},"group",[55,82,83],{},"Split output by tag or path.",[55,85,86],{},"None",[37,88,89,97,100],{},[55,90,91],{},[20,92,94],{"href":93},"#baseurl",[15,95,96],{},"baseURL",[55,98,99],{},"Base URL prepended to every handler's path.",[55,101,86],{},[37,103,104,112,119],{},[55,105,106],{},[20,107,109],{"href":108},"#handlers",[15,110,111],{},"handlers",[55,113,114,115,118],{},"Write a ",[15,116,117],{},"handlers.ts"," that exports every handler.",[55,120,121],{},[15,122,123],{},"false",[37,125,126,134,137],{},[55,127,128],{},[20,129,131],{"href":130},"#parser",[15,132,133],{},"parser",[55,135,136],{},"Source of the response body each handler returns.",[55,138,139],{},[15,140,141],{},"'data'",[37,143,144,152,155],{},[55,145,146],{},[20,147,149],{"href":148},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options#include",[15,150,151],{},"include",[55,153,154],{},"Keep only operations that match.",[55,156,86],{},[37,158,159,167,170],{},[55,160,161],{},[20,162,164],{"href":163},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options#exclude",[15,165,166],{},"exclude",[55,168,169],{},"Skip operations that match.",[55,171,172],{},[15,173,174],{},"[]",[37,176,177,185,188],{},[55,178,179],{},[20,180,182],{"href":181},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options#override",[15,183,184],{},"override",[55,186,187],{},"Apply different options per pattern.",[55,189,190],{},[15,191,174],{},[37,193,194,202,210],{},[55,195,196],{},[20,197,199],{"href":198},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options#resolver",[15,200,201],{},"resolver",[55,203,204,205,209],{},"Customize generated names and file paths. See ",[20,206,208],{"href":207},"#resolver-members","resolver members",".",[55,211,212],{},[15,213,214],{},"resolverMsw",[37,216,217,225,228],{},[55,218,219],{},[20,220,222],{"href":221},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options#macros",[15,223,224],{},"macros",[55,226,227],{},"Rewrite AST nodes before printing.",[55,229,230],{},[15,231,174],{},[26,233,235],{"id":234},"option-details","Option details",[237,238,96],"h3",{"id":239},"baseurl",[11,241,242,243,209],{},"Base URL prepended to the path each handler matches. Without it, a handler matches the operation's relative path. Leave off the trailing slash, because operation paths start with ",[15,244,245],{},"\u002F",[31,247,248,256],{},[34,249,250],{},[37,251,252,254],{},[40,253],{},[40,255],{},[50,257,258,268],{},[37,259,260,263],{},[55,261,262],{},"Type",[55,264,265],{},[15,266,267],{},"string",[37,269,270,273],{},[55,271,272],{},"Required",[55,274,275],{},[15,276,123],{},[31,278,279,289],{},[34,280,281],{},[37,282,283,286],{},[40,284,285],{},"Value",[40,287,288],{},"Handler matches",[50,290,291,301,313],{},[37,292,293,296],{},[55,294,295],{},"None (default)",[55,297,298],{},[15,299,300],{},"\u002Fpets\u002F:petId",[37,302,303,308],{},[55,304,305],{},[15,306,307],{},"'https:\u002F\u002Fpetstore.dev'",[55,309,310],{},[15,311,312],{},"https:\u002F\u002Fpetstore.dev\u002Fpets\u002F:petId",[37,314,315,320],{},[55,316,317],{},[15,318,319],{},"'${process.env.API_URL}'",[55,321,322,323,326],{},"The value of ",[15,324,325],{},"API_URL"," when the handler is created",[11,328,329,330,333,334,209],{},"To set the base URL at runtime, pass ",[15,331,332],{},"{ baseURL }"," as a handler's second argument or to ",[20,335,336],{"href":108},[15,337,338],{},"createHandlers",[237,340,111],{"id":111},[11,342,343,344,346],{},"Writes a ",[15,345,117],{}," with every handler in operation order.",[31,348,349,357],{},[34,350,351],{},[37,352,353,355],{},[40,354],{},[40,356],{},[50,358,359,368,376],{},[37,360,361,363],{},[55,362,262],{},[55,364,365],{},[15,366,367],{},"boolean",[37,369,370,372],{},[55,371,272],{},[55,373,374],{},[15,375,123],{},[37,377,378,380],{},[55,379,48],{},[55,381,382],{},[15,383,123],{},[31,385,386,396],{},[34,387,388],{},[37,389,390,393],{},[40,391,392],{},"Export",[40,394,395],{},"What it is",[50,397,398,417],{},[37,399,400,404],{},[55,401,402],{},[15,403,111],{},[55,405,406,407,409,410,413,414,209],{},"Every handler with the configured ",[15,408,96],{},", for ",[15,411,412],{},"setupServer(...handlers)"," or ",[15,415,416],{},"setupWorker(...handlers)",[37,418,419,424],{},[55,420,421],{},[15,422,423],{},"createHandlers(options?)",[55,425,426,427,429],{},"Builds the same list with a ",[15,428,96],{}," passed at runtime.",[431,432,437],"pre",{"language":433,"filename":434,"code":435,"class":436},"typescript","src\u002Fgen\u002Fhandlers\u002Fhandlers.ts","import { getPetHandler } from '.\u002FgetPetHandler'\nimport { addPetHandler } from '.\u002FaddPetHandler'\n\nexport function createHandlers(options?: { baseURL?: string }) {\n return [getPetHandler(undefined, options), addPetHandler(undefined, options)] as const\n}\n\nexport const handlers = createHandlers()","highlights",[15,438,440,467,468,467,484,467,486,467,522,467,571,467,576,467,578],{"class":439},"language-typescript",[441,442,445,449,453,457,460,463],"span",{"class":443,"style":444},"line","display: inline",[441,446,448],{"style":447},"color:#d73a49;--hls-dark:#f97583","import ",[441,450,452],{"style":451},"color:#005cc5;--hls-dark:#79b8ff","{ ",[441,454,456],{"style":455},"color:#24292e;--hls-dark:#e1e4e8","getPetHandler ",[441,458,459],{"style":451},"} ",[441,461,462],{"style":447},"from ",[441,464,466],{"style":465},"color:#032f62;--hls-dark:#9ecbff","'.\u002FgetPetHandler'","\n",[441,469,470,472,474,477,479,481],{"class":443,"style":444},[441,471,448],{"style":447},[441,473,452],{"style":451},[441,475,476],{"style":455},"addPetHandler ",[441,478,459],{"style":451},[441,480,462],{"style":447},[441,482,483],{"style":465},"'.\u002FaddPetHandler'",[441,485],{"class":443,"style":444},[441,487,488,491,494,497,500,503,506,509,511,513,516,519],{"class":443,"style":444},[441,489,490],{"style":447},"export ",[441,492,493],{"style":447},"function ",[441,495,338],{"style":496},"color:#6f42c1;--hls-dark:#b392f0",[441,498,499],{"style":451},"(",[441,501,502],{"style":455},"options",[441,504,505],{"style":455},"?",[441,507,508],{"style":447},": ",[441,510,452],{"style":451},[441,512,96],{"style":451},[441,514,515],{"style":455},"?: ",[441,517,518],{"style":496},"string ",[441,520,521],{"style":451},"}) {",[441,523,524,527,530,533,536,538,541,544,546,549,551,554,556,558,560,562,565,568],{"class":443,"style":444},[441,525,526],{"style":451}," ",[441,528,529],{"style":447},"return ",[441,531,532],{"style":451},"[",[441,534,535],{"style":496},"getPetHandler",[441,537,499],{"style":451},[441,539,540],{"style":451},"undefined",[441,542,543],{"style":447},", ",[441,545,502],{"style":455},[441,547,548],{"style":451},")",[441,550,543],{"style":447},[441,552,553],{"style":496},"addPetHandler",[441,555,499],{"style":451},[441,557,540],{"style":451},[441,559,543],{"style":447},[441,561,502],{"style":455},[441,563,564],{"style":451},")] ",[441,566,567],{"style":447},"as ",[441,569,570],{"style":447},"const",[441,572,573],{"class":443,"style":444},[441,574,575],{"style":451},"}",[441,577],{"class":443,"style":444},[441,579,580,582,585,588,591,593],{"class":443,"style":444},[441,581,490],{"style":447},[441,583,584],{"style":447},"const ",[441,586,587],{"style":455},"handlers ",[441,589,590],{"style":447},"= ",[441,592,338],{"style":496},[441,594,595],{"style":451},"()",[237,597,133],{"id":133},[11,599,136],{},[31,601,602,610],{},[34,603,604],{},[37,605,606,608],{},[40,607],{},[40,609],{},[50,611,612,621,629],{},[37,613,614,616],{},[55,615,262],{},[55,617,618],{},[15,619,620],{},"'data' | 'faker'",[37,622,623,625],{},[55,624,272],{},[55,626,627],{},[15,628,123],{},[37,630,631,633],{},[55,632,48],{},[55,634,635],{},[15,636,141],{},[638,639,640,659],"field-group",{},[641,642,643,644,647,648,651,652,655,656,658],"field",{"name":141},"Returns the data you pass, typed with the ",[15,645,646],{},"@kubb\u002Fplugin-ts"," types. Without ",[15,649,650],{},"data",", the handler sends the first example of the success response, when the spec has one. Pass ",[15,653,654],{},"null"," to send a ",[15,657,654],{}," body.",[641,660,662,663,666,667,669,670,413,672,674,675,678,679,682],{"name":661},"'faker'","Falls back to a ",[15,664,665],{},"@kubb\u002Fplugin-faker"," value when ",[15,668,650],{}," is ",[15,671,540],{},[15,673,654],{}," and the success response has a schema. Other falsy values, such as ",[15,676,677],{},"0",", are sent as the body. Register ",[15,680,681],{},"pluginFaker()"," next to this plugin.",[11,684,685,686,209],{},"See ",[20,687,689],{"href":688},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-msw\u002Fguides\u002Fmock-api#examples-from-the-spec","Examples from the spec",[691,692,693,712],"code-group",{},[431,694,697],{"language":433,"filename":695,"code":696,"class":436},"'data' (default)","return getPetHandlerResponse200(data)",[15,698,699],{"class":439},[441,700,701,703,706,708,710],{"class":443,"style":444},[441,702,529],{"style":447},[441,704,705],{"style":496},"getPetHandlerResponse200",[441,707,499],{"style":451},[441,709,650],{"style":455},[441,711,548],{"style":451},[431,713,715],{"language":433,"filename":661,"code":714,"class":436},"return getPetHandlerResponse200(data ?? createGetPetResponse())",[15,716,717],{"class":439},[441,718,719,721,723,725,728,731,734],{"class":443,"style":444},[441,720,529],{"style":447},[441,722,705],{"style":496},[441,724,499],{"style":451},[441,726,727],{"style":455},"data ",[441,729,730],{"style":447},"?? ",[441,732,733],{"style":496},"createGetPetResponse",[441,735,736],{"style":451},"())",[11,738,739,740,743],{},"Each handler file also exports one response helper per status code, such as ",[15,741,742],{},"getPetHandlerResponse404(data)",". Return a helper from the callback to mock that status:",[431,745,748],{"language":433,"filename":746,"code":747,"class":436},"test-server.ts","getPetHandler(() => getPetHandlerResponse404())",[15,749,750],{"class":439},[441,751,752,754,757,760,763],{"class":443,"style":444},[441,753,535],{"style":496},[441,755,756],{"style":451},"(() ",[441,758,759],{"style":447},"=> ",[441,761,762],{"style":496},"getPetHandlerResponse404",[441,764,736],{"style":451},[26,766,768],{"id":767},"resolver-members","Resolver members",[11,770,771,773,774,776],{},[15,772,201],{}," takes one patch or an array of patches. An array merges over ",[15,775,214],{}," from left to right.",[11,778,779,780,782,783,785,786,543,789,792,793,796,797,543,801,803],{},"Members you leave out of a ",[15,781,201],{}," patch keep ",[15,784,214],{},". Besides the shared ",[15,787,788],{},"name",[15,790,791],{},"file",", and ",[15,794,795],{},"imports"," members of ",[20,798,799],{"href":198},[15,800,201],{},[15,802,214],{}," has these:",[431,805,808],{"language":433,"filename":806,"code":807,"class":436},"Partial override","type ResolverMswPatch = {\n handler?: {\n name?(node: OperationNode): string \u002F\u002F → 'getPetHandler'\n listName?(): string \u002F\u002F → 'handlers'\n }\n}",[15,809,810,467,823,467,836,467,866,467,885,467,891],{"class":439},[441,811,812,815,818,820],{"class":443,"style":444},[441,813,814],{"style":447},"type ",[441,816,817],{"style":496},"ResolverMswPatch ",[441,819,590],{"style":447},[441,821,822],{"style":451},"{",[441,824,825,827,830,832,834],{"class":443,"style":444},[441,826,526],{"style":451},[441,828,829],{"style":451},"handler",[441,831,505],{"style":455},[441,833,508],{"style":447},[441,835,822],{"style":451},[441,837,838,841,843,845,847,850,852,855,857,859,862],{"class":443,"style":444},[441,839,840],{"style":451}," ",[441,842,788],{"style":455},[441,844,505],{"style":447},[441,846,499],{"style":451},[441,848,849],{"style":455},"node",[441,851,508],{"style":455},[441,853,854],{"style":496},"OperationNode",[441,856,548],{"style":451},[441,858,508],{"style":455},[441,860,861],{"style":496},"string ",[441,863,865],{"style":864},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F → 'getPetHandler'",[441,867,868,870,873,875,877,879,882],{"class":443,"style":444},[441,869,840],{"style":864},[441,871,872],{"style":455},"listName",[441,874,505],{"style":447},[441,876,595],{"style":451},[441,878,508],{"style":455},[441,880,881],{"style":496},"string ",[441,883,884],{"style":864},"\u002F\u002F → 'handlers'",[441,886,887,889],{"class":443,"style":444},[441,888,526],{"style":864},[441,890,575],{"style":451},[441,892,893],{"class":443,"style":444},[441,894,575],{"style":451},{"title":896,"searchDepth":897,"depth":897,"links":898},"",5,[899,901,907],{"id":28,"depth":900,"text":29},2,{"id":234,"depth":900,"text":235,"children":902},[903,905,906],{"id":239,"depth":904,"text":96},3,{"id":111,"depth":904,"text":111},{"id":133,"depth":904,"text":133},{"id":767,"depth":900,"text":768},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-msw\u002Foptions",1795727681750,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]