apigee-127 / swagger-node-runner

The heart of Swagger-Node
MIT License
102 stars 123 forks source link

Option to enable mocks for all paths by default #118

Closed penx closed 6 years ago

penx commented 6 years ago

As far as I'm aware, in order to enable a mock for a path, I either need to:

I think there may also be a way to enable mocks using x-swagger-pipe on the path/operation too?

Not doing the above results in:

Error: No implementation found for this path. at api-swagger/node_modules/swagger-node-runner/lib/connect_middleware.js:50:21

It would be good to have a way to enable mocks on all paths without having to edit the yaml spec file, e.g. you are provided with a spec and want to quickly fire up a 100% mock of it.

Is there a config setting to do this? If not, is it a reasonable feature request? I may be able to work on this if so - any pointers on how this should be done?

penx commented 6 years ago

My guess, after reading:

https://github.com/theganyo/swagger-node-runner/blob/7f85797e74ee8a182ae9458ac8e2eb4db9c7a6c3/index.js#L133-L142

Is to set defaultPipe: swagger_controllers in config/default.yaml and then update the following:

https://github.com/theganyo/swagger-node-runner/blob/7f85797e74ee8a182ae9458ac8e2eb4db9c7a6c3/fittings/swagger_router.js#L65-L80

To handle controllerName being undefined and proceed to set up a mock.

penx commented 6 years ago

I've created an example project here that works against my proposed fix https://github.com/penx/openapi-mock/tree/initial-example