diff --git a/api.js b/api.js index f586dd9c0..d4eaa36dd 100644 --- a/api.js +++ b/api.js @@ -42,12 +42,6 @@ exports.api = function(args, opts) { return; } - if(!file) { - console.log("We couldn't find a Swagger file.".red); - console.log("Run " + "api init".yellow + " to get started."); - process.exit(); - } - var apiId = crypto.randomBytes(15).toString('hex'); if(!swagger['x-api-id']) { diff --git a/lib/validate.js b/lib/validate.js new file mode 100644 index 000000000..d53b32f25 --- /dev/null +++ b/lib/validate.js @@ -0,0 +1,12 @@ +var figures = require('figures'); + +exports.swagger = true; +exports.login = false; +exports.desc = "Validate your Swagger file"; +exports.category = "utility"; + +exports.run = function(config, info) { + console.log(figures.tick.green + " Success!".green + " Valid Swagger file"); + process.exit(); +}; + diff --git a/package.json b/package.json index 57d7a3bef..bbd376f76 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "dependencies": { "base-store": "^0.4.4", "colors": "^1.1.2", + "figures": "^1.7.0", "git-utils": "^4.1.2", "glob": "^7.1.0", "inquirer": "^1.2.1", diff --git a/utils.js b/utils.js index 2650b9cb4..6bb2832a4 100644 --- a/utils.js +++ b/utils.js @@ -1,7 +1,8 @@ var fs = require('fs'); var os = require('os'); var path = require('path'); -var glob = require("glob") +var glob = require('glob') +var figures = require('figures'); var _ = require('lodash'); var git = require('git-utils'); @@ -28,7 +29,33 @@ exports.findSwagger = function(cb, opts) { metadata: true, }).then((generatedSwagger) => { generatedSwagger = JSON.parse(generatedSwagger); - cb(undefined, generatedSwagger, generatedSwagger['x-si-base']); // TODO! We need to fix the file! + + if(!generatedSwagger['x-si-base']) { + console.log("We couldn't find a Swagger file.".red); + console.log("Run " + "api init".yellow + " to get started."); + process.exit(); + } + + swagger.validate(generatedSwagger, function(err, api) { + if(err) { + console.log(""); + console.log("Error validating Swagger!".red); + console.log(""); + if(err.details) { + _.each(err.details, function(detail) { + var at = detail.path && detail.path.length ? " (at " + detail.path.join('.') + ")" : ""; + console.log(" " + figures.cross.red + " " + detail.message + at.grey); + }); + } else { + console.log(figures.cross.red + " " + err.message); + } + console.log(""); + process.exit(); + return; + } + + cb(undefined, generatedSwagger, generatedSwagger['x-si-base']); + }); }); };