Proposal: openapi-msw
library as a lightweight wrapper around MSW
#1372
christoph-fricke
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
@drwpow Since mentioning this idea, I have worked on a solution[^1] and released it to npm. What do you think about mentioning OpenAPI-MSW somewhere in this project, so people using OpenAPI-TS can find it more easily and, in the worst case, won't accidentally implement it twice. :) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Mock Service Worker (MSW) is a popular library for defining HTTP mocks that can be used quite flexibly. It is great for mocking APIs in all kind of tests or during development.
Using
openapi-typescript
andopenapi-fetch
enables use to ensure that our application's API client does not have conflicts with the API specification, which is great. However, while we can address issues with the API client, we have to "manually" remember to fix API mocks since there is no mechanism that warns us about conflicts.Using MSW, we can already provide the generated schemas and have conflicts if a response no longer matches a schema, but nothing warns us about outdated URL paths. Being able to reuse the generated
paths
definition for MSW as well would provide full safety in the application as well as our mocks.In the spirit of this library, I have been thinking about a small wrapper around MSW's
http
(previouslyrest
in MSW v1) methods that can be typed with the generatedpaths
interface. The remaining functionality of MSW would either still be imported frommsw
or re-exported fromopenapi-msw
. This is definitely up for discussion.I would love to try building such wrapper and I am eager for your feedback. Do you prefer to have it in a separate project or are you interested in including it in this workspace?
Beta Was this translation helpful? Give feedback.
All reactions