From cc47f34afd5407fbb01eb56f344346c8a9ed5edc Mon Sep 17 00:00:00 2001 From: Tomohiko Ozawa Date: Thu, 31 Mar 2022 22:41:35 +0900 Subject: [PATCH] throw error if json path depth exceeds --- src/ref.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ref.js b/src/ref.js index 0575216..5741c90 100644 --- a/src/ref.js +++ b/src/ref.js @@ -2,6 +2,7 @@ // https://github.com/OAI/OpenAPI-Specification/tree/master/versions const FIELD_PATTERN = "([a-zA-Z0-9\\-_]|[^\x01-\x7E\uFF61-\uFF9F])+"; +const MAX_JSON_PATH_DEPTH = 100; const REF_TYPES = { parameters: (path) => { @@ -68,7 +69,10 @@ function getRefType(path) { return k; } } - console.log(`unknown component type at "${path}". fallback to include.`); + console.warn(`could not infer $ref type at "${path}". fallback to include.`); + if (path.split(".").length > MAX_JSON_PATH_DEPTH) { + throw new Error(`JSON path depth exceeds ${MAX_JSON_PATH_DEPTH}, aborting...`); + } return "unknown"; }