Skip to content

Commit

Permalink
generate api html doc from multiple raml
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericHeem committed Aug 10, 2016
1 parent 16f5497 commit 737837c
Show file tree
Hide file tree
Showing 7 changed files with 1,008 additions and 13 deletions.
2 changes: 2 additions & 0 deletions client/src/assets/stylus/main.styl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@import 'variables';



// application wide styles and overrides
@import 'global';
@import 'overrides';
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"clean": "gulp clean",
"mock": "node scripts/mock-server.js",
"api-check": "abao src/plugins/users/raml/users.raml --server http://localhost:9000/api/v1",
"doc": "raml2html -i src/plugins/users/raml/users.raml -o build/api.html",
"doc": "node scripts/apidoc.js",
"opendoc": "open build/api.html"
},
"dependencies": {
Expand Down Expand Up @@ -77,7 +77,7 @@
"qs": "6.2.1",
"rabbitmq-pubsub": "0.5.0",
"raml-mocker-server": "0.1.6",
"raml2html": "2.4.0",
"raml2html": "3.0.0",
"redis": "2.6.2",
"run-sequence": "1.2.2",
"sequelize": "3.23.6",
Expand Down
43 changes: 32 additions & 11 deletions server/scripts/apidoc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
var _ = require('lodash');
var raml2html = require('raml2html');
var fs = require('fs');
var path = require('path');
var Promise = require('bluebird');

var configWithDefaultTemplates = raml2html.getDefaultConfig();
console.log('raml2html: ', configWithDefaultTemplates);
//var configWithCustomTemplates = raml2html.getDefaultConfig('my-custom-template.nunjucks', __dirname);
var source = ['./src/plugins/users/user/raml/users.raml']
// source can either be a filename, url, file contents (string) or parsed RAML object
raml2html.render(source, configWithDefaultTemplates).then(function(result) {
// Save the result to a file or do something else with the result
console.log('raml2html done: ', result);
}, function(error) {
// Output error
console.error(error)
});

var sources = [
'api.raml',
'users/raml/users.raml',
'dbSchema/raml/db.explorer.raml'
];

sources = _.map(sources, function(source){
return path.join(__dirname, '/../src/plugins', source)
})

var outputPath = 'build';
console.log('sources: ', sources);
Promise.all(_.map(sources, function(source){
//console.log('raml2html in: ', source);
return raml2html.render(source, configWithDefaultTemplates).then(function(result) {
//console.log('raml2html result: ', result);
var outputFile = path.basename(source, '.raml');
let resultFilename = path.join(outputPath, outputFile + ".html");
console.log('raml2html writing to file: ', resultFilename);
fs.writeFileSync(resultFilename, result);
}, function(error) {
// Output error
console.error(error);
throw error;
});
}))
4 changes: 4 additions & 0 deletions server/src/plugins/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Welcome to the API documentation.

* [Users API](users.html)
* [Database explorer API](db.explorer.html)
9 changes: 9 additions & 0 deletions server/src/plugins/api.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#%RAML 0.8
---
title: Starhackit
baseUri: http://localhost
version: v1
protocols: [ HTTP, HTTPS ]
documentation:
- title: Summary
content: !include api.md
18 changes: 18 additions & 0 deletions server/src/plugins/dbSchema/raml/db.explorer.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#%RAML 0.8
---
title: Starhackit
baseUri: http://localhost:8080/api/v1/db
version: v1
mediaType: application/json
protocols: [ HTTP, HTTPS ]
documentation:
- title: Database Explorer REST API
content: 'Database Explorer REST API documentation'

/schema:
description: Get the database schema
get:
responses:
200:
body:
example: !include db.schema.out.sample.json
Loading

0 comments on commit 737837c

Please sign in to comment.