aglio icon indicating copy to clipboard operation
aglio copied to clipboard

Trailing slahes in endpoint URIs are discarded

Open netmikey opened this issue 9 years ago • 3 comments

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: screen shot 2016-01-05 at 10 21 34

netmikey avatar Jan 05 '16 09:01 netmikey

Additionally if you have some API at the root, the documentation looks rather silly since it becomes empty. A slash would be nicer.

aglio-root-path

fgeorgsson avatar Mar 22 '16 10:03 fgeorgsson

@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
});

kr1sp1n avatar Apr 07 '16 11:04 kr1sp1n

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.

mmissire avatar Jul 08 '16 21:07 mmissire