Skip to content

Commit

Permalink
Merge pull request RackHD#484 from brianparry/swaggerdoc
Browse files Browse the repository at this point in the history
Swagger documentation generator
  • Loading branch information
Brian Parry authored Oct 10, 2016
2 parents 7c448c0 + 54d0d26 commit 8a27d4e
Show file tree
Hide file tree
Showing 3 changed files with 544 additions and 1,464 deletions.
28 changes: 28 additions & 0 deletions extra/swagger-doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var yaml = require('js-yaml');
var fs = require('fs');
var pdf = require('html-pdf');
var path = require('path');

fs.readFile('static/monorail-2.0.yaml', { encoding: 'utf8'}, function(err, swaggerData) {
if (err) return console.log(err);

var swaggerDef = yaml.safeLoad(swaggerData);
require('bootprint')
.load(require('bootprint-swagger'))
.build('static/monorail-2.0.yaml', 'build/swagger-doc')
.generate()
.done(function(data) {
var html = fs.readFileSync(data[0], 'utf-8');
var options = {
base: 'file://' + path.resolve(data[0]),
format: 'Letter'
};
var pdfFile = 'build/swagger-doc/rackhd-api-' + swaggerDef.info.version + '.pdf';

pdf.create(html, options)
.toFile(pdfFile, function(err, res) {
if (err) return console.log(err);
console.log(res);
});
});
});
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test": "./node_modules/.bin/mocha $(find spec -name '*-spec.js') -R spec --require spec/helper.js",
"install": "./install-web-ui.sh && ./install-swagger-ui.sh",
"apidoc": "./node_modules/.bin/apidoc -i lib/api/1.1/northbound -f '.*\\.js$' -o build/apidoc",
"taskdoc": "./install-task-doc.sh"
"taskdoc": "./install-task-doc.sh",
"swaggerdoc": "node extra/swagger-doc.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -80,7 +81,10 @@
"sinon-as-promised": "^2.0.3",
"sinon-chai": "^2.7.0",
"supertest": "^1.2.0",
"xunit-file": "0.0.6"
"xunit-file": "0.0.6",
"bootprint-swagger": "~0.13.1",
"bootprint": "~0.8.5",
"html-pdf": "~2.1.0"
},
"apidoc": {
"name": "RackHD API Documentation",
Expand Down
Loading

0 comments on commit 8a27d4e

Please sign in to comment.