Middleware for routing to controllers using swagger schema's.
Requirements:
- Node >= 6.0.0
- fleek-context
This package is to be used as middleware for Koa2 to bind responses for swagger documentation using ctx.fleek.context defined by fleek-context or an equivalent custom middleware.
npm install --save fleek-responder
For a swagger example, refer to the test swagger json
const Koa = require('koa');
const fleekCtx = require('fleek-context');Â
const fleekResponder = require('fleek-responder');
const SWAGGER = require('./swagger.json');
let app = new Koa();
app.use(fleekCtx(SWAGGER));
app.use(fleekResponder({
strict: true, // Force all responses to validate against the path definitions
camelCase: true, // Convert shortcuts to camelcase
default: {
fallback: 'NotFound'
downstream: true, // Run default response application on the way down the middleware chain
upstream: true // Run default response application on the way up the middleware chain
}
}));
app.use((ctx, next) => {
console.log(ctx.body); // => { code: 404, error: { description: "not found" } }
ctx.fleek.response.success({
data: {
hello: 'world'
}
});
console.log(ctx.body); // => { code: 200, data: { hello: 'world' } }
return next();
});
app.listen(3000);TODO
Built and maintained with by the Hart team.