In descriptor you can add the object representing the parameters that you need.
app.get('/books', function (req, res) {
res.send("My fantastic book");
}).descriptor({
name : 'Retrieve a fantastic book',
errors : []
});
api.list() : retrieve all the mapped Express APIs.
app.get('/apis', function (req, res) {
res.send(api.list());
}).descriptor({
name : 'Retrieve APIs documentation'
});
api.listByEntity() : retrieve all the mapped Express APIs grouping by entity. There are 2 modes:
- automatic : entities are detected automatically according to restful api concepts
app.get('/api/gardens', function (req, res) {
res.send(api.listByEntity());
}).descriptor({
name : 'Welcome in my garden!',
errors : []
});
app.post('/api/gardens', function (req, res) {
res.send(api.listByEntity());
}).descriptor({
name : 'I need a new garden',
errors : []
});
app.get('/api/gardens/flowers', function (req, res) {
res.send(api.listByEntity());
}).descriptor({
name : 'Look my tulips!',
errors : []
});
- manual : just add the parameter entity in your api
app.get('/api/gardens', function (req, res) {
res.send(api.listByEntity());
}).descriptor({
name : 'Welcome in my garden!',
errors : [],
entity : 'My Garden'
});
app.post('/api/gardens', function (req, res) {
res.send(api.listByEntity());
}).descriptor({
name : 'I need a new garden',
errors : [],
entity : 'My Garden'
});
app.get('/api/gardens/flowers', function (req, res) {
res.send(api.listByEntity());
}).descriptor({
name : 'Look my tulips!',
errors : [],
entity : 'My flowers'
});
The express-api-descriptor module allows to create documentation for Express APIs.
var express = require('express');
var api = require('express-api-descriptor')(express);
var app = express();
app.get('/api', function (req, res) {
res.send(api.list());
}).descriptor({
name : 'My first API documentation'
});
app.listen(8080, function () {
console.log('Example app listening on port 8080!');
});
npm i express-api-descriptor
From Version 1.0.3
- Possibility to group API by entity automatically
ISC