Skip to content

v0.7.1

Latest
Compare
Choose a tag to compare
@theganyo theganyo released this 16 Nov 14:21
· 38 commits to master since this release

Issues addressed:

#58, #67, #68, #71

Enhancements:

Added swagger-cors fitting

You can now use fitting/swagger-cors instead fitting/cors of and include your node_modules in fittingsDirs. Simply replace cors in your pipe with swagger-cors.

Optionally include error stack from json_error_handler

Support flag for development and integration environments: includeErrStack

openapi-error: 
  name:                 json_error_handler
  handle500Errors:      true
  includeErrStack:      true

When truthful, the automatic response-body includes the stack as well as any other enumerable attribute on the error.

Allow direct bagpipes execution as controllers

You now have a choice in how to implement controllers. The existing default acts like middleware: operationMethod(req, res, next). Alternatively, you may now chose to write your controllers as a pipe: operationMethod(ctx, next). In this case, the controller is passed with the pipeworks context, which holds a reference to .request and .response. In this model, one should generally not use ctx.response directly for responding to the client, but leave your response body on the ctx.output, the status on ctx.statusCode, and the headers on ctx.headers. The benefit is improved isolation from web-context. You don't have to run a web server to run your tests. You may just pass it a ctx and see what you find on the ctx once the callback is called. In addition, there is also an option to ask swagger-node-runner to deduce the interface from the controller's method signature. If it names 2 parameters - it's a pipe, if it names 3 parameters - it's a middleware.

This directive may be provided in few levels that cascade each other:

  1. The default for the entire server - provided at config/default.yaml as swagger.bagpipes._router.controllersInterface.
  2. If its more comfortable to you to express it in the swagger - you may use in your swagger.yaml the following directive on the root: x-controller-interface.
  3. You may cascade the default for an entire path, suggesting that all methods of the controller that manages this path are implemented this way, using x-controller-interface on the path level.
  4. Finally, you may cascade the directive per operation, using x-controller-interface on the operation level.

The legal values are one of the values: middleware, pipe, auto-detect and these correspond to the behavior described above.