diff --git a/package.json b/package.json index 0975a63ad8..6b2bdbdfdc 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "jquery": "^3.4.1", "jquery-caret-plugin": "^1.5.2", "jquery-validation": "^1.19.0", + "js-yaml": "^3.13.1", "katex": "^0.11.1", "mini-css-extract-plugin": "^0.9.0", "moment": "^2.24.0", diff --git a/tools/check-openapi b/tools/check-openapi index 6a75d25add..787283f772 100755 --- a/tools/check-openapi +++ b/tools/check-openapi @@ -1,5 +1,7 @@ #!/usr/bin/env node +const fs = require('fs'); +const jsyaml = require('js-yaml'); const SwaggerParser = require('swagger-parser'); async function validate_swagger(file) { @@ -13,12 +15,13 @@ async function validate_swagger(file) { } } -// 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 (const file of process.argv.slice(2)) { - // Run the validator only for YAML files inside static/swagger - if (file.startsWith('static/swagger')) { - validate_swagger(file); +(async () => { + // 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 (const file of process.argv.slice(2)) { + if (jsyaml.safeLoad(await fs.promises.readFile(file, 'utf8')).openapi !== undefined) { + await validate_swagger(file); + } } -} +})();