check-openapi: Restore functionality after OpenAPI definitions moved.

Commit 35577a1f66 (#9406) moved the
OpenAPI definitions to zerver/openapi, and this script was not
updated, so it has been validating nothing for two years.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-03-27 20:42:06 -07:00 committed by Tim Abbott
parent 7bbbc46aad
commit 9620611ec9
2 changed files with 12 additions and 8 deletions

View File

@ -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",

View File

@ -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);
}
}
}
})();