@@ -21,8 +21,8 @@ You can install OpenAPI-MSW with this shell command:
2121npm i -D openapi-msw
2222```
2323
24- This package has a peer- dependency to MSW ** v2** . There is no plan to provide
25- backwards compatibility for MSW v1.
24+ This package has a peer dependency on MSW ** v2** , which you must install as
25+ well. There are no plans to provide backward compatibility for MSW v1.
2626
2727## Usage Guide
2828
@@ -46,7 +46,7 @@ type-safety and editor suggestion benefits:
4646 current path
4747- ** Request Body:** Automatically typed with the request-body schema of the
4848 current path
49- - ** Response:** Automatically forced to match an specified status-code,
49+ - ** Response:** Automatically forced to match a specified status-code,
5050 content-type, and response-body schema of the current path
5151
5252``` typescript
@@ -81,6 +81,19 @@ const otherHandler = http.get("/unknown", () => {
8181});
8282```
8383
84+ Just like regular MSW handlers, the handlers you define with OpenAPI-MSW are
85+ ` HttpHandler ` instances. They can be used with any MSW functionality that
86+ requires ` HttpHandlers ` as arguments. For example, you can use your handlers
87+ with ` setupServer ` :
88+
89+ ``` typescript
90+ import { setupServer } from " msw/node" ;
91+
92+ // Use the handlers defined above
93+ const server = setupServer (getHandler , postHandler );
94+ server .listen ();
95+ ```
96+
8497### Provide a Base URL for Paths
8598
8699You can provide an optional base URL to ` createOpenApiHttp ` , which is prepended
@@ -216,7 +229,7 @@ To align with this assumption, OpenAPI-MSW only allows matching `"4XX"` and
216229const http = createOpenApiHttp <paths >();
217230
218231const handler = http .get (" /wildcard-status-code-example" , ({ response }) => {
219- // Error: A wildcards is used but no status code provided
232+ // Error: A wildcard is used but no status code is provided
220233 const invalidRes = response (" 5XX" ).text (" Fatal Error" );
221234
222235 // Error: Provided status code does not match the used wildcard
@@ -225,10 +238,10 @@ const handler = http.get("/wildcard-status-code-example", ({ response }) => {
225238 // Error: Provided status code is not defined in RFC 9110
226239 const invalidRes = response (" 5XX" ).text (" Fatal Error" , { status: 520 });
227240
228- // No Error : Provided status code matches the used wildcard
241+ // Valid : Provided status code matches the used wildcard
229242 const validRes = response (" 5XX" ).text (" Fatal Error" , { status: 503 });
230243
231- // No Error: "default" wildcard allows 5XX and 4XX status codes
244+ // Valid: The "default" wildcard allows 5XX and 4XX status codes
232245 const validRes = response (" default" ).text (" Fatal Error" , { status: 507 });
233246});
234247```
@@ -282,4 +295,4 @@ type ResponseBody = ResponseBodyFor<typeof http.get, "/tasks">;
282295
283296## License
284297
285- This package is published under the [ MIT license] ( ./LICENSE ) .
298+ This package is licensed under the [ MIT license] ( ./LICENSE ) .
0 commit comments