From 77a9daccece0d2111d7d6559350861f26bf3ced6 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 13 Nov 2017 12:11:11 +0900 Subject: [PATCH] Validation that operationId is present Signed-off-by: Alexey Rusakov --- api/validator.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/validator.js b/api/validator.js index 0d76c09d..cfc24b53 100644 --- a/api/validator.js +++ b/api/validator.js @@ -34,6 +34,17 @@ var errFn = function(err, api) { process.exit(1); }; +var checkOperationId = function(api) { + Object.keys(api.paths).forEach(function(endpoint) { + var operationsMap = api.paths[endpoint]; + Object.keys(operationsMap).forEach(function(verb) { + if (!operationsMap[verb]["operationId"]) + errFn("operationId is missing in " + endpoint + ", verb " + verb, api); + }) + }); + return ""; +}; + var isDir = fs.lstatSync(opts.schema).isDirectory() if (isDir) { console.log("Checking directory %s for .yaml files...", opts.schema); @@ -46,6 +57,9 @@ if (isDir) { var suffix = ".yaml"; if (f.indexOf(suffix, f.length - suffix.length) > 0) { parser.validate(path.join(opts.schema, f), function(err, api, metadata) { + if (!err) { + checkOperationId(api); + } if (!err) { console.log("%s is valid.", f); } @@ -60,6 +74,9 @@ if (isDir) { } else{ parser.validate(opts.schema, function(err, api) { + if (!err) { + checkOperationId(api); + } if (!err) { console.log("%s is valid", opts.schema); }