mirror of https://github.com/zulip/zulip.git
check-openapi: Use low-level YAML parser.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
8854cd7945
commit
7af2647d64
|
@ -8,12 +8,17 @@ const Diff = require("diff");
|
|||
const ExampleValidator = require("openapi-examples-validator");
|
||||
const Prettier = require("prettier");
|
||||
const SwaggerParser = require("swagger-parser");
|
||||
const {LineCounter, Scalar, YAMLMap, YAMLSeq, parseDocument, visit} = require("yaml");
|
||||
const {Composer, LineCounter, Parser, Scalar, YAMLMap, YAMLSeq, visit} = require("yaml");
|
||||
|
||||
async function checkFile(file) {
|
||||
const yaml = await fs.promises.readFile(file, "utf8");
|
||||
const lineCounter = new LineCounter();
|
||||
const doc = parseDocument(yaml, {lineCounter});
|
||||
const tokens = [...new Parser(lineCounter.addNewLine).parse(yaml)];
|
||||
const docs = [...new Composer().compose(tokens)];
|
||||
if (docs.length !== 1) {
|
||||
return;
|
||||
}
|
||||
const [doc] = docs;
|
||||
if (doc.errors.length > 0) {
|
||||
for (const error of doc.errors) {
|
||||
console.error("%s: %s", file, error.message);
|
||||
|
|
Loading…
Reference in New Issue