microsoft / dev-proxy

Dev Proxy is an API simulator that helps you effortlessly test your app beyond the happy path.
https://aka.ms/devproxy
MIT License
512 stars 60 forks source link

Mock API by pointing to Open API spec #531

Open svrooij opened 9 months ago

svrooij commented 9 months ago

It would be very cool if you could point the dev proxy to some openapi spec url and have it mock that api.

And as an extra feature it should use AI (bring your own key) that checks the object type and tries to mock reasonable data.

So if you mock a /users/{id} endpoint it would generate a reasonable response for a givenName or a mail property.

The generated response should be saved for economic reasons off course.

waldekmastykarz commented 9 months ago

Great idea! We could go about it in two ways:

  1. Build a plugin that takes an OpenAPI spec as input and generates the necessary mock responses when requested. Like you suggested, it caches the generated mocks for subsequent use. Here, we'd also need to consider invalidating the cache when the spec changed.
  2. Build a command that converts an OpenAPI spec into mocks. The benefit here is that you only process the spec once and get a set of mocks which you can reuse without the spec. You can also fine tune the generated mocks to your needs.

Thoughts?

svrooij commented 8 months ago

I'm all for having it done automatically. So you point it to an OpenAPI spec and it should start getting those requests. And if you say "here is my open AI key, please generate mocks for all endpoints". It should do that once. maybe even hash the spec of a single action? That would allow caching the mock on a per request base, which is probably cheaper than regenerating mocks for all requests if only a single request in the openapi spec has changed.

Maybe even do the generating of the mocks on the fly (with a 429 to delay the client 😉) so only request that are tested get (expensive) mocks, and not every request in the spec.