mirror of https://github.com/zulip/zulip.git
check-openapi: Add option to automatically fix errors.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
7af2647d64
commit
a08c138c03
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue