aglio
aglio copied to clipboard
Trailing slahes in endpoint URIs are discarded
I want to document an existing API with API Blueprint and generate static HTML using aglio. The API uses trailing slashes on all endpoints, but aglio removes them in the generated documentation. I don't mean to start a discussion whether trailing slashes are a good idea, I just think the API doc-tool shouldn't be opinionated in this regard and just output exacly what I'm telling it ;-)
Example input:
FORMAT: 1A
HOST: http://www.example.com/api
# Example API
## Example Resource [/example/]
### GET
+ Response 200 (application/json)
Generated output:
Additionally if you have some API at the root, the documentation looks rather silly since it becomes empty. A slash would be nicer.
@pcguru
After looking in the aglio-theme-olio source I found a hack for the API-at-the-root-issue.
Because you can overwrite some helper functions via the locals
option you can do the following:
var aglio = require('aglio');
var qs = require('querystring');
var fs = require('fs');
var blueprint = fs.readFileSync(__dirname + '/API.md').toString(); // wherever your API specs are located
var opts = {
themeVariables: 'default',
locals: {
urldec: function (value) {
var unescaped = qs.unescape(value);
if (unescaped === '') unescaped = '/';
return unescaped;
}
}
};
aglio.render(blueprint, opts, function (err, html, warnings) {
if (err) return console.log(err);
if (warnings) console.log(warnings);
console.log(html) // do whatever you want with the html
});
Additionally if you have some API at the root, the documentation looks rather silly since it becomes empty. A slash would be nicer.
I ran into this, and found adding a space after the slash works around it.