check-openapi: Use low-level YAML parser.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-09-09 15:18:53 -07:00 committed by Tim Abbott
parent 8854cd7945
commit 7af2647d64
1 changed files with 7 additions and 2 deletions

View File

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