[{"data":1,"prerenderedAt":387},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-msw":3},{"id":4,"title":5,"body":6,"description":368,"extension":376,"frontmatter":377,"heading":5,"meta":378,"navigation":379,"order":380,"path":381,"seo":382,"sitemap":383,"source":4,"stem":384,"__hash__":385,"hasPopups":386},"extensions\u002Fextensions\u002Fkubb-labs\u002Fplugin-msw\u002Findex.md","MSW",{"type":7,"value":8,"toc":367},"minimark",[9,13,25,30,114,135,139,173,177,214,222,226,232],[10,11,12],"p",{},"The MSW plugin generates a typed MSW request handler for each operation in your OpenAPI spec.",[10,14,15,16,20,21,24],{},"Each handler returns the data you pass to it. With ",[17,18,19],"code",{},"parser: 'faker'",", a handler called without data returns mock data from ",[17,22,23],{},"@kubb\u002Fplugin-faker",". Only operations with a success response schema get mock data.",[26,27,29],"h2",{"id":28},"installation","Installation",[31,32,34,63,80,98],"code-group",{"sync":33},"package-manager",[35,36,41],"pre",{"language":37,"filename":38,"code":39,"class":40},"shell","bun","bun add -d @kubb\u002Fplugin-msw","shiki shiki-themes github-light github-dark dark:github-dark",[17,42,44],{"class":43},"language-shell",[45,46,49,52,56,60],"span",{"class":47,"style":48},"line","display: inline",[45,50,38],{"style":51},"color:#6F42C1;--shiki-dark:#B392F0",[45,53,55],{"style":54},"color:#032F62;--shiki-dark:#9ECBFF"," add",[45,57,59],{"style":58},"color:#005CC5;--shiki-dark:#79B8FF"," -d",[45,61,62],{"style":54}," @kubb\u002Fplugin-msw",[35,64,67],{"language":37,"filename":65,"code":66,"class":40},"pnpm","pnpm add -D @kubb\u002Fplugin-msw",[17,68,69],{"class":43},[45,70,71,73,75,78],{"class":47,"style":48},[45,72,65],{"style":51},[45,74,55],{"style":54},[45,76,77],{"style":58}," -D",[45,79,62],{"style":54},[35,81,84],{"language":37,"filename":82,"code":83,"class":40},"npm","npm install --save-dev @kubb\u002Fplugin-msw",[17,85,86],{"class":43},[45,87,88,90,93,96],{"class":47,"style":48},[45,89,82],{"style":51},[45,91,92],{"style":54}," install",[45,94,95],{"style":58}," --save-dev",[45,97,62],{"style":54},[35,99,102],{"language":37,"filename":100,"code":101,"class":40},"yarn","yarn add -D @kubb\u002Fplugin-msw",[17,103,104],{"class":43},[45,105,106,108,110,112],{"class":47,"style":48},[45,107,100],{"style":51},[45,109,55],{"style":54},[45,111,77],{"style":58},[45,113,62],{"style":54},[10,115,116,117,120,121,126,127,130,131,134],{},"Or run ",[17,118,119],{},"kubb add plugin-msw"," to install the version the ",[122,123,125],"a",{"href":124},"\u002Fregistry","Kubb registry"," pins and add ",[17,128,129],{},"pluginMsw()"," to ",[17,132,133],{},"kubb.config.ts",".",[26,136,138],{"id":137},"setup","Setup",[140,141,142,150,166],"ul",{},[143,144,145,146,149],"li",{},"Add ",[17,147,148],{},"@kubb\u002Fplugin-ts"," for the request and response types.",[143,151,145,152,154,155,157,158,161,162,165],{},[17,153,23],{}," when you set ",[17,156,19],{},", and install ",[17,159,160],{},"@faker-js\u002Ffaker"," v10. The default ",[17,163,164],{},"data"," parser does not need it.",[143,167,168,169,172],{},"Install ",[17,170,171],{},"msw"," v2 in the app that uses the generated code.",[26,174,176],{"id":175},"options-worth-knowing","Options worth knowing",[140,178,179,191,208],{},[143,180,181,184,185,187,188,134],{},[17,182,183],{},"parser"," sets where the response body comes from: ",[17,186,164],{}," (default) or ",[17,189,190],{},"faker",[143,192,193,196,197,200,201,204,205,134],{},[17,194,195],{},"handlers"," writes a ",[17,198,199],{},"handlers.ts"," file that exports every handler, ready to spread into ",[17,202,203],{},"setupServer"," or ",[17,206,207],{},"setupWorker",[143,209,210,213],{},[17,211,212],{},"baseURL"," is prepended to the path each handler matches.",[10,215,216,217,221],{},"See ",[122,218,220],{"href":219},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-msw\u002Foptions","Options"," for every option and its default.",[26,223,225],{"id":224},"example","Example",[10,227,228,229,231],{},"The config below generates one handler per operation and a ",[17,230,199],{}," file that exports them all.",[35,233,236],{"language":234,"filename":133,"code":235,"class":40},"typescript","import { defineConfig } from 'kubb\u002Fconfig'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\nimport { pluginMsw } from '@kubb\u002Fplugin-msw'\n\nexport default defineConfig({\n  input: '.\u002FpetStore.yaml',\n  output: { path: '.\u002Fsrc\u002Fgen' },\n  plugins: [\n    pluginTs(),\n    pluginMsw({ output: { path: 'handlers', mode: 'directory' }, handlers: true }),\n  ],\n})",[17,237,239,255,256,255,268,255,280,255,282,255,296,255,307,255,318,255,323,255,331,255,357,255,362],{"class":238},"language-typescript",[45,240,241,245,249,252],{"class":47,"style":48},[45,242,244],{"style":243},"color:#D73A49;--shiki-dark:#F97583","import",[45,246,248],{"style":247},"color:#24292E;--shiki-dark:#E1E4E8"," { defineConfig } ",[45,250,251],{"style":243},"from",[45,253,254],{"style":54}," 'kubb\u002Fconfig'","\n",[45,257,258,260,263,265],{"class":47,"style":48},[45,259,244],{"style":243},[45,261,262],{"style":247}," { pluginTs } ",[45,264,251],{"style":243},[45,266,267],{"style":54}," '@kubb\u002Fplugin-ts'",[45,269,270,272,275,277],{"class":47,"style":48},[45,271,244],{"style":243},[45,273,274],{"style":247}," { pluginMsw } ",[45,276,251],{"style":243},[45,278,279],{"style":54}," '@kubb\u002Fplugin-msw'",[45,281],{"class":47,"style":48},[45,283,284,287,290,293],{"class":47,"style":48},[45,285,286],{"style":243},"export",[45,288,289],{"style":243}," default",[45,291,292],{"style":51}," defineConfig",[45,294,295],{"style":247},"({",[45,297,298,301,304],{"class":47,"style":48},[45,299,300],{"style":247},"  input: ",[45,302,303],{"style":54},"'.\u002FpetStore.yaml'",[45,305,306],{"style":247},",",[45,308,309,312,315],{"class":47,"style":48},[45,310,311],{"style":247},"  output: { path: ",[45,313,314],{"style":54},"'.\u002Fsrc\u002Fgen'",[45,316,317],{"style":247}," },",[45,319,320],{"class":47,"style":48},[45,321,322],{"style":247},"  plugins: [",[45,324,325,328],{"class":47,"style":48},[45,326,327],{"style":51},"    pluginTs",[45,329,330],{"style":247},"(),",[45,332,333,336,339,342,345,348,351,354],{"class":47,"style":48},[45,334,335],{"style":51},"    pluginMsw",[45,337,338],{"style":247},"({ output: { path: ",[45,340,341],{"style":54},"'handlers'",[45,343,344],{"style":247},", mode: ",[45,346,347],{"style":54},"'directory'",[45,349,350],{"style":247}," }, handlers: ",[45,352,353],{"style":58},"true",[45,355,356],{"style":247}," }),",[45,358,359],{"class":47,"style":48},[45,360,361],{"style":247},"  ],",[45,363,364],{"class":47,"style":48},[45,365,366],{"style":247},"})",{"title":368,"searchDepth":369,"depth":369,"links":370},"",5,[371,373,374,375],{"id":28,"depth":372,"text":29},2,{"id":137,"depth":372,"text":138},{"id":175,"depth":372,"text":176},{"id":224,"depth":372,"text":225},"md",{},{},true,null,"\u002Fextensions\u002Fkubb-labs\u002Fplugin-msw",{"title":5},{"loc":381},"extensions\u002Fkubb-labs\u002Fplugin-msw\u002Findex","V_y6H37H5Kn7-iPOow1UWtDloYqxRjLDhcPMuwLbXqA",false,1792364731144]