2019-08-07 23:18:05 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2017-06-26 22:09:07 +02:00
|
|
|
var SwaggerParser = require('swagger-parser'),
|
|
|
|
_ = require('underscore');
|
2017-06-02 23:12:26 +02:00
|
|
|
|
2017-06-26 22:09:07 +02:00
|
|
|
function check_duplicate_operationids(api) {
|
|
|
|
var operation_ids = [];
|
|
|
|
|
|
|
|
_.each(api.paths, function(endpoint) {
|
|
|
|
_.each(endpoint, function(value) {
|
|
|
|
var operation_id = value.operationId;
|
|
|
|
if(operation_id !== undefined) {
|
|
|
|
if(operation_ids.indexOf(operation_id) >= 0) {
|
|
|
|
console.error('In', file + ':');
|
|
|
|
console.error('Duplicate operationId:', operation_id);
|
|
|
|
process.exitCode = 1;
|
|
|
|
} else {
|
|
|
|
operation_ids.push(operation_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function validate_swagger(file) {
|
2017-06-02 23:12:26 +02:00
|
|
|
SwaggerParser.validate(file)
|
2017-06-26 22:09:07 +02:00
|
|
|
.then(function(api) {
|
|
|
|
// Let's make sure that there aren't any duplicate operationids,
|
|
|
|
// until this issue is fixed:
|
|
|
|
// https://github.com/BigstickCarpet/swagger-parser/issues/68
|
|
|
|
check_duplicate_operationids(api);
|
2017-06-02 23:12:26 +02:00
|
|
|
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')) {
|
2017-06-26 22:09:07 +02:00
|
|
|
validate_swagger(file);
|
2017-06-02 23:12:26 +02:00
|
|
|
}
|
|
|
|
}
|