From 9602f73d0599bc9d6be19ac4885afad3ea225bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20Gonz=C3=A1lez?= Date: Fri, 2 Jun 2017 23:12:26 +0200 Subject: [PATCH] lint: Add validation for the Swagger file. --- package.json | 1 + tools/check-swagger | 26 ++++++++++++++++++++++++++ tools/lint | 1 + version.py | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tools/check-swagger diff --git a/package.json b/package.json index 660d985d38..8f575e4850 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "nwmatcher": "1.3.6", "phantomjs-prebuilt": "2.1.14", "svgo": "0.7.2", + "swagger-parser": "3.4.1", "tslint": "5.3.2", "webpack-dev-server": "2.4.1", "xmlhttprequest": "1.5.0" diff --git a/tools/check-swagger b/tools/check-swagger new file mode 100644 index 0000000000..6a2811a0b2 --- /dev/null +++ b/tools/check-swagger @@ -0,0 +1,26 @@ +var SwaggerParser = require('swagger-parser'); + +function validateSwagger(file) { + SwaggerParser.validate(file) + .then(function() { + // The validation passed, no need to say anything + return; + }) + .catch(function(err) { + // There is something wrong. Display the validation errors + console.error('In', file + ':'); + console.error(err.message); + process.exitCode = 1; + }); +} + +// Iterate through the changed files, passed in the arguments. +// The two first arguments are the call to the Node interpreter and this +// script, hence the starting point at 2. +for(var i = 2; i < process.argv.length; i++) { + var file = process.argv[i]; + // Run the validator only for YAML files inside static/swagger + if(file.startsWith('static/swagger')) { + validateSwagger(file); + } +} diff --git a/tools/lint b/tools/lint index f8499a0c74..e92a9fe00a 100755 --- a/tools/lint +++ b/tools/lint @@ -715,6 +715,7 @@ def run(): external_linter('puppet', ['puppet', 'parser', 'validate'], ['pp']) external_linter('templates', ['tools/check-templates'], ['handlebars', 'html']) external_linter('urls', ['tools/check-urls']) + external_linter('swagger', ['node', 'tools/check-swagger'], ['yaml']) # gitlint disabled until we can stabilize it more # if not options.no_gitlint: diff --git a/version.py b/version.py index 19e8ddb050..ab836808ce 100644 --- a/version.py +++ b/version.py @@ -1,2 +1,2 @@ ZULIP_VERSION = "1.5.1+git" -PROVISION_VERSION = '5.3' +PROVISION_VERSION = '5.4'