Add Swagger 2 docs for content repo. Add Swagger 2 CLI validator.
This commit is contained in:
parent
f9710a6e17
commit
caa84c1dc1
2 changed files with 127 additions and 0 deletions
34
api/validator.js
Normal file
34
api/validator.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
var nopt = require("nopt");
|
||||
var parser = require("swagger-parser");
|
||||
var path = require("path");
|
||||
|
||||
var opts = nopt({
|
||||
"help": Boolean,
|
||||
"schema": path
|
||||
}, {
|
||||
"h": "--help",
|
||||
"s": "--schema"
|
||||
});
|
||||
|
||||
if (opts.help) {
|
||||
console.log(
|
||||
"Use swagger-parser to validate against Swagger 2.0\n"+
|
||||
"Usage:\n"+
|
||||
" node validator.js -s <schema_file>"
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
if (!opts.schema) {
|
||||
console.error("No [s]chema specified.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
parser.parse(opts.schema, function(err, api, metadata) {
|
||||
if (!err) {
|
||||
console.log("%s is valid.", opts.schema);
|
||||
return;
|
||||
}
|
||||
console.log(metadata);
|
||||
console.error(err);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue