Swagger documentation generator for Epilogue.js
When you implement a relational database - driven application, using Express & Sequelize, you might want to bootstrap the rest api using the Epilogue.js library. In two words it generates CRUD enponts according to your domain and paths that you want, e.g:
epilogue.initialize({ app, sequelize, base: '/api' }); // app is a initialized express instance
const authorResource = epilogue.resource({
model: Author,
endpoints: ['/author', '/author/:id'],
});
will generate next endpoints:
- GET https://host:port/api/author - list/search authors
- GET https://host:port/api/author/{id} - get author by id
- DELETE https://host:port/api/author/{id} - delete author by id
- POST https://host:port/api/author - create new author
- PUT https://host:port/api/author/{id} - update new author
You can read more about Epilogue here.
The idea is that we have a generated api, why we can't generate documentation for it?
(I assume that you are ising express) Define a Sequelize model:
const Author = sequelize.define('Author', {
// some field definition
})
Unit Epilogue resource:
epilogue.initialize({ app, sequelize, base: '/api' });
const authorResource = epilogue.resource({
model: Author,
endpoints: ['/author', '/author/:id'],
});
We are almost done, now we can generate swagger schema for our endpoints:
episwag({
epilogueInstance: epilogue,
resources: [
authorResource,
bookResource,
],
header: { host: req.get('host') },
}))