Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quicktype for automated mocks? #479

Open
andrewluetgers opened this issue Jun 5, 2023 · 1 comment
Open

quicktype for automated mocks? #479

andrewluetgers opened this issue Jun 5, 2023 · 1 comment
Labels
stage: needs investigation Needs further investigation

Comments

@andrewluetgers
Copy link

andrewluetgers commented Jun 5, 2023

Is your feature request related to a problem? Please describe.
I have been working on creating mock APIS (full CRUD support) in my own implementations with MSW for a few years and have been wondering how much can I automate this and I would like to share a couple thoughts and hear if any of this makes sense for mocks-server.

Describe the solution you'd like
I have been following Miragejs and MSW/Data for a while and have recently stumbled upon quicktype and Zod-Mock. Quicktype is amazing. Whereas Miragejs and MSW/Data core value IMHO is in data modeling such that you can produce an interactive mocked API I believe this should be automated. Ideally we should be able to just look at network activity and infer the data model. This is exactly what quicktype enables. Further its does codegen, so we can generate zod code and leverage zod-mock to dynamically respond with faker-js mocked data that passes the type validation of the inferred type.

Additional context
Beyond just automatically mocking the data with a type-valid shape I can foresee this enabling monitoring network traffic on the fly in (certainly in dev but perhaps in other contexts) to gen types on the fly and watch for type changes as more routes are seen. Quicktype can make a single type that incorporates multiple examples.

There is probably a path towards automating the transformation/mutation bits as well but thats a deeper discussion and I just want to introduce this idea in its simplest form first.

@javierbrea
Copy link
Member

Hi @andrewluetgers , very interesting. Thank you!

Maybe this could be implemented in a plugin somehow. A separated process could previously look at the network activity and generate the routes for the Mocks Server, or even the plugin could create a "proxy", so all of the traffic to the original API goes through it in a previous iteration, which would make easier to it to collect the needed information to generate the routes. So, the sequence would be as simpler as:

  • "start the Mocks Server with the routesGenerator plugin enabled in proxy mode"
  • "use the original API through the Mocks Server proxy"
  • "request the Mocks Server plugin to generate routes from collected data"
  • "stop the server"
  • "start it again. Now you have the mock API available"

Sounds great! 😃

@javierbrea javierbrea added the stage: needs investigation Needs further investigation label Jun 14, 2023
@javierbrea javierbrea moved this to To do in Backlog May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigation Needs further investigation
Projects
Status: To do
Development

No branches or pull requests

2 participants