express-api-doc
v0.0.12
Published
Auto generated express documentation
Downloads
379
Maintainers
Readme
Auto generated express documentation
To create documentation:
create file docs.js:
const Docs = require('express-api-doc');
const app = require('./app'); // your app.js
const docs = new Docs(app);
docs.generate({
path: './public/template.html',
});
run:
node ./docs.js
template.html will be generated in ./public/
Track requests and responses:
If You have coverage tests, you can track responses and requests, and add them to the documentation. in app.js, before routes declaration, add track function, so app.js will look like this:
const Docs = require('express-api-doc');
...
const app = express();
...
const dock = new Docs(app);
dock.track({
path: './public/examples.txt', // responses and requests will save here
});
app.use('/', index);
...
in docs.js file pass examples option to generate function:
docs.generate({
path: './public/template.html',
examples: './public/examples.txt,
});
now you can run tests with documentation generating:
node ./node_modules/.bin/mocha -r should && node ./docs.js
in generated html present list of available routes with search and sendbox, where you can try to send json to your server. Under sendbox present list of examples, where you can see request and response json which has been tracked (for instance during tests).
List of available routes:
Sendbox with example:
you can change and generate your own template using express-api-doc-template project.
to use your template, pass template option to generate function in docs.js:
docs.generate({
path: './public/template.html',
examples: './public/examples.txt,
template: './path/to/your/template.html',
});