Skip to content

Update swagger-parser to fix swagger 2.0 parsing issue #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,13 @@ var parser = Promise.promisifyAll(require("swagger-parser"));
var yaml = Promise.promisifyAll(require("js-yaml"));
var _ = Promise.promisifyAll(require("lodash"));


function getSpecPromise(file) {
return parser.parseAsync(file)
.spread(function(api, metadata) {
return api;
}).catch(function(e) {
console.error("unable to read swagger file\n"+e)
process.exit(1);
});
return parser.parseAsync(file, {});
}

function getCheckStylePromise(file) {
return fs.readFileAsync(file)
.then(yaml.safeLoad)
.catch(function(e) {
console.error("unable to read checkstyle\n"+e)
process.exit(1);
});
.then(yaml.safeLoad);
}

function getSchema(checkStyle) {
Expand All @@ -45,6 +34,7 @@ function getSchema(checkStyle) {
var parameterKeys = {
'in': Joi.string().valid('query', 'header'),
format: Joi.string(),
$ref: Joi.string(),
type: Joi.string(),
description: Joi.string(),
required: Joi.boolean(),
Expand All @@ -61,11 +51,11 @@ function getSchema(checkStyle) {
version: Joi.string()
}),
host: joiRegex(checkStyle.host),
scheme: joiRegex(checkStyle.schemes),
scheme: joiRegex(checkStyle.scheme),
basePath: joiRegex(checkStyle.basePath),
produces: Joi.array().items(joiRegex(checkStyle.produces)),
consumes: Joi.array().items(joiRegex(checkStyle.consumes)),
schemes: Joi.array().items(joiRegex(checkStyle.schemes)),
schemes: Joi.array().items(joiRegex(checkStyle.scheme)),
paths: Joi.object().pattern(pathConvention,
Joi.object().pattern(verbs, Joi.object().keys({
summary: Joi.any(),
Expand Down Expand Up @@ -94,8 +84,8 @@ function validate(checkStyleFile, specFile, callback) {
}).spread(function(spec, schema, callback) {
return Joi.validate(spec, schema);
}).then(function(result) {
callback(result, null);
callback(null, result);
}).catch(function(e) {
callback(null, e);
callback(e);
});
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "swagger-checkstyle",
"version": "1.0.0",
"description": "Checkstyle on swagger definitions",
"main": "index.js",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},
"author": "Jason Harmon",
"license": "ISC",
Expand All @@ -15,7 +15,7 @@
"js-yaml": "^3.3.1",
"json-mask": "^0.3.4",
"lodash": "^3.9.3",
"swagger-parser": "^2.5.0"
"swagger-parser": "^3.3"
},
"devDependencies": {
"mocha": "^2.2.5",
Expand Down
4 changes: 2 additions & 2 deletions test/convention_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('validate', function(done) {
spec = './examples/uber/swagger.yaml';
result = null;

swaggerCheckStyle.validate(checkStyle, spec, function(result, err) {
swaggerCheckStyle.validate(checkStyle, spec, function(err, result) {
if (err) throw err;
should.not.exist(result.error)
done();
Expand All @@ -18,7 +18,7 @@ describe('validate', function(done) {
checkStyle = './examples/uber/swagger-checkstyle.yaml';
spec = './examples/uber/swagger-errors.yaml';

swaggerCheckStyle.validate(checkStyle, spec, function(result, err) {
swaggerCheckStyle.validate(checkStyle, spec, function(err, result) {
if (err) throw err;
result.error.name.should.eql("ValidationError");
done();
Expand Down