swagger-express-middleware icon indicating copy to clipboard operation
swagger-express-middleware copied to clipboard

Regarding the mock behavior for resources with "example" and "default" schema descriptions

Open Sigma-90 opened this issue 5 years ago • 0 comments

I'm currently quite stumped at the behavior of the middleware when it comes to requesting resources that have an example specified in the schema definition. I expected a request to a non-existent resource to return a 404, but instead it serves the example data. Why exactly is this behavior assigned to both "example" and "default", instead of "default" only, at least when custom resources are available?

I understand that the goal of the mock was to simulate a functional API that serves data even without forcing a developer to manually add dummy resources, so the response data is taken from both "default" and "example" to ensure there is at least something there from the get-go. That is perfectly fine. But what I don't get is why there is no intelligent functionality attached to that, which dynamically inspects the dataStore and limits this behavior to "default" definitions only as soon as the first manually created resource gets added. From that point on it should be safe to assume that the server is now meant to operate only with the added dummy data, so there is no more need to fake additional responses using the example data (whereas default responses might still be viable, as per definition of the word "default").

Alternatively, a config option for the mock server to ignore example data might be very useful, but that should then be configurable by resource type, not globally, otherwise enabling it would force devs to add custom dummy data to every resource type, even when they only need it for a few of them.

Or is there already a similar option hidden somewhere and I just didn't find it?

Sigma-90 avatar Apr 02 '19 16:04 Sigma-90