"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);
        process.exit(0);
        return;
    }
    console.log(metadata);
    console.error(err);
    process.exit(1);
});
@@ -7,16 +7,40 @@
 trict%22;%0A
+var fs = require(%22fs%22);%0A
 var nopt
@@ -397,16 +397,26 @@
 ema_file
+_or_folder
 %3E%22%0A    )
@@ -533,33 +533,20 @@
 %0A%7D%0A%0A
-parser.parse(opts.schema,
+%0Avar errFn =
  fun
@@ -601,168 +601,1032 @@
     
-console.log(%22%25s is valid.%22, opts.schema);%0A        process.exit(0);%0A        return;%0A    %7D%0A    console.log(metadata);%0A    console.error(err);%0A    process.exit(1);%0A%7D);
+return;%0A    %7D%0A    console.log(metadata);%0A    console.error(err);%0A    process.exit(1);%0A%7D;%0A%0Avar isDir = fs.lstatSync(opts.schema).isDirectory()%0Aif (isDir) %7B%0A    console.log(%22Checking directory %25s for .yaml files...%22, opts.schema);%0A    fs.readdir(opts.schema, function(err, files) %7B%0A        if (err) %7B%0A            console.error(err);%0A            process.exit(1);%0A        %7D%0A        files.forEach(function(f) %7B%0A            if (f.indexOf(%22.yaml%22) %3E 0) %7B%0A                parser.parse(path.join(opts.schema, f), function(err, api, metadata) %7B%0A                    if (!err) %7B%0A                        console.log(%22%25s is valid.%22, f);%0A                    %7D%0A                    else %7B%0A                        errFn(err, api, metadata);%0A                    %7D%0A                %7D);%0A            %7D %0A        %7D);%0A    %7D);%0A%7D%0Aelse%7B%0A    parser.parse(opts.schema, function(err, api, metadata) %7B%0A        if (!err) %7B%0A            console.log(%22%25s is valid%22, opts.schema);%0A        %7D%0A        else %7B%0A            errFn(err, api, metadata);%0A        %7D%0A    %7D);%0A%7D;%0A%0A

Update swagger validator to support directories.