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