Skip to content

Commit

Permalink
Fix error with swagger being dereferenced
Browse files Browse the repository at this point in the history
  • Loading branch information
gkoberger committed Mar 22, 2017
1 parent 463c154 commit 995c66d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports.api = function(args, opts) {
}

if(actionObj.swagger) {
utils.findSwagger(function(err, swagger, file) {
utils.findSwagger(info, function(err, swagger, file) {
if(err) {
console.error(err);
return;
Expand Down
16 changes: 12 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require('fs');
var cardinal = require('cardinal');
var os = require('os');
var path = require('path');
var glob = require('glob')
Expand All @@ -22,9 +23,7 @@ exports.config = function(env) {
return config;
};

exports.findSwagger = function(cb, opts) {
opts = opts || {};

exports.findSwagger = function(info, cb) {
swaggerInline('**/*', {
format: '.json',
metadata: true,
Expand All @@ -37,15 +36,24 @@ exports.findSwagger = function(cb, opts) {
process.exit();
}

swagger.validate(generatedSwagger, function(err, api) {
var generatedSwaggerClone = _.clone(generatedSwaggerClone); // Becasue swagger.validate modifies the original JSON
swagger.validate(generatedSwaggerClone, function(err, api) {
if(err) {

// TODO: We should go through the crappy validation stuff
// and try to make it easier to understand

if (!info.v) {
console.log(cardinal.highlight(JSON.stringify(generatedSwagger, undefined, 2)));
}

console.log("");
console.log("Error validating Swagger!".red);
console.log("");
if (info.v) {
console.log("Run with " + "-v".grey + " to see the invalid Swagger");
console.log("");
}
if(err.details) {
_.each(err.details, function(detail) {
var at = detail.path && detail.path.length ? " (at " + detail.path.join('.') + ")" : "";
Expand Down

0 comments on commit 995c66d

Please sign in to comment.