From 7af2647d64cf11faedb790a9bc7a0dbaf16bd1d1 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 9 Sep 2021 15:18:53 -0700 Subject: [PATCH] check-openapi: Use low-level YAML parser. Signed-off-by: Anders Kaseorg --- tools/check-openapi | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/check-openapi b/tools/check-openapi index c30ed98a81..555549c574 100755 --- a/tools/check-openapi +++ b/tools/check-openapi @@ -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);