Skip to content

Commit df33bd1

Browse files
committed
Update swagger-parser
1 parent 1e8cb65 commit df33bd1

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

lib/validate.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,13 @@ var parser = Promise.promisifyAll(require("swagger-parser"));
1212
var yaml = Promise.promisifyAll(require("js-yaml"));
1313
var _ = Promise.promisifyAll(require("lodash"));
1414

15-
1615
function getSpecPromise(file) {
17-
return parser.parseAsync(file)
18-
.spread(function(api, metadata) {
19-
return api;
20-
}).catch(function(e) {
21-
console.error("unable to read swagger file\n"+e)
22-
process.exit(1);
23-
});
16+
return parser.parseAsync(file, {});
2417
}
2518

2619
function getCheckStylePromise(file) {
2720
return fs.readFileAsync(file)
28-
.then(yaml.safeLoad)
29-
.catch(function(e) {
30-
console.error("unable to read checkstyle\n"+e)
31-
process.exit(1);
32-
});
21+
.then(yaml.safeLoad);
3322
}
3423

3524
function getSchema(checkStyle) {
@@ -45,6 +34,7 @@ function getSchema(checkStyle) {
4534
var parameterKeys = {
4635
'in': Joi.string().valid('query', 'header'),
4736
format: Joi.string(),
37+
$ref: Joi.string(),
4838
type: Joi.string(),
4939
description: Joi.string(),
5040
required: Joi.boolean(),
@@ -94,8 +84,8 @@ function validate(checkStyleFile, specFile, callback) {
9484
}).spread(function(spec, schema, callback) {
9585
return Joi.validate(spec, schema);
9686
}).then(function(result) {
97-
callback(result, null);
87+
callback(null, result);
9888
}).catch(function(e) {
99-
callback(null, e);
89+
callback(e);
10090
});
10191
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "swagger-checkstyle",
33
"version": "1.0.0",
44
"description": "Checkstyle on swagger definitions",
5-
"main": "index.js",
5+
"main": "lib/index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "mocha"
88
},
99
"author": "Jason Harmon",
1010
"license": "ISC",
@@ -15,7 +15,7 @@
1515
"js-yaml": "^3.3.1",
1616
"json-mask": "^0.3.4",
1717
"lodash": "^3.9.3",
18-
"swagger-parser": "^2.5.0"
18+
"swagger-parser": "^3.3"
1919
},
2020
"devDependencies": {
2121
"mocha": "^2.2.5",

test/convention_validation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ describe('validate', function(done) {
88
spec = './examples/uber/swagger.yaml';
99
result = null;
1010

11-
swaggerCheckStyle.validate(checkStyle, spec, function(result, err) {
11+
swaggerCheckStyle.validate(checkStyle, spec, function(err, result) {
1212
if (err) throw err;
13-
should.not.exist(result.error)
13+
should.not.exist(result.error && result.error.details)
1414
done();
1515
});
1616
});
1717
it('should not validate bad swagger', function(done) {
1818
checkStyle = './examples/uber/swagger-checkstyle.yaml';
1919
spec = './examples/uber/swagger-errors.yaml';
2020

21-
swaggerCheckStyle.validate(checkStyle, spec, function(result, err) {
21+
swaggerCheckStyle.validate(checkStyle, spec, function(err, result) {
2222
if (err) throw err;
2323
result.error.name.should.eql("ValidationError");
2424
done();

0 commit comments

Comments
 (0)