Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
check-openapi: Add option to automatically fix errors.
Anders Kaseorga08c138c034c
diff --git a/package.json b/package.jsonindex e290cc0fc97..f3bafd6a2c5 100644--- a/package.json+++ b/package.json@@ -126,6 +126,7 @@"webpack-dev-server": "^3.5.1","xvfb": "^0.4.0","yaml": "^2.0.0-8",+ "yargs": "^15.0.2","yarn-deduplicate": "^3.0.0","zulip-js": "^2.0.8"},diff --git a/tools/check-openapi b/tools/check-openapiindex 555549c574b..6ef028dfe5c 100755--- a/tools/check-openapi+++ b/tools/check-openapi@@ -9,6 +9,12 @@ const ExampleValidator = require("openapi-examples-validator");const Prettier = require("prettier");const SwaggerParser = require("swagger-parser");const {Composer, LineCounter, Parser, Scalar, YAMLMap, YAMLSeq, visit} = require("yaml");+const yargs = require("yargs");++const {argv} = yargs.option("fix", {+ type: "boolean",+ description: "Automatically fix some problems",+});async function checkFile(file) {const yaml = await fs.promises.readFile(file, "utf8");@@ -92,6 +98,10 @@ async function checkFile(file) {if (!ok) {process.exitCode = 1;}+ if (reformats.size > 0) {+ console.log("%s: Fixing problems", file);+ await fs.promises.writeFile(file, tokens.map((token) => CST.stringify(token)).join(""));+ }try {await SwaggerParser.validate(file);@@ -112,7 +122,7 @@ async function checkFile(file) {}(async () => {- for (const file of process.argv.slice(2)) {+ for (const file of argv._) {await checkFile(file);}})().catch((error) => {diff --git a/tools/lint b/tools/lintindex 94495d59d8c..c90e6d22d4d 100755--- a/tools/lint+++ b/tools/lint@@ -112,6 +112,7 @@ def run() -> None:["yaml"],description="Validates our OpenAPI/Swagger API documentation ""(zerver/openapi/zulip.yaml) ",+ fix_arg="--fix",)linter_config.external_linter("shellcheck",