From c7429b680f2890434b13e87dd2a5cd353b8c5ed2 Mon Sep 17 00:00:00 2001 From: Timothy Gibbons Date: Tue, 7 Oct 2025 12:36:11 -0500 Subject: [PATCH 1/3] Fix: Reading json files from project root Previously the OpenAPI compiler attempted to `require()` the config file directly. This caused `MODULE_NOT_FOUND` errors when using `--openapi:config-file` option. This patch: - Changed `require()` to `fs.readFileSync()` with `JSON.parse()`. - Early Return when file does not exists. --- lib/compile/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/compile/index.js b/lib/compile/index.js index 6c1e82a..13ea6e2 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -93,8 +93,14 @@ function toOpenApiOptions(csdl, csn, options = {}) { } if (result["config-file"]) { - if (fs.existsSync(result["config-file"])) { - const fileContent = require(result["config-file"]); + if (!fs.existsSync(result["config-file"])) { + throw new Error("Unable to find openapi config file " + result["config-file"]); + } + + try{ + const fileData = fs.readFileSync(result["config-file"]); + const fileContent = JSON.parse(fileData); + Object.keys(fileContent).forEach((key) => { if (key === "odata-version" && !result["odataVersion"]) { result["odataVersion"] = fileContent[key]; @@ -104,8 +110,8 @@ function toOpenApiOptions(csdl, csn, options = {}) { result[key] = JSON.stringify(fileContent[key]); } }); - } else { - throw new Error("Error while parsing the openapi configuration file " + result["config-file"]); + }catch(err){ + throw new Error("Unable to parse OpenAPI config " + result["config-file"], { cause: err }); } } From 2fb809c61c8b6be7eef2cfa10067a1abffdeeeff Mon Sep 17 00:00:00 2001 From: Timothy Gibbons Date: Thu, 16 Oct 2025 12:17:30 -0500 Subject: [PATCH 2/3] Added 'utf-8' to fs.readFileSync to resolve TSC issues --- lib/compile/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compile/index.js b/lib/compile/index.js index 13ea6e2..504af72 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -98,7 +98,7 @@ function toOpenApiOptions(csdl, csn, options = {}) { } try{ - const fileData = fs.readFileSync(result["config-file"]); + const fileData = fs.readFileSync(result["config-file"], "utf-8"); const fileContent = JSON.parse(fileData); Object.keys(fileContent).forEach((key) => { From 86cb8dd1b76d49d55c9f5cd70093fbe6623c846a Mon Sep 17 00:00:00 2001 From: Timothy Gibbons Date: Tue, 21 Oct 2025 10:14:39 -0500 Subject: [PATCH 3/3] docs: Update Changelog This commit updates change log for the reading json files from project root fix. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e6c19..bb3b41d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ## [Unreleased] +### Fixed +- Reading json from project root ## Version 1.2.3 - 28.05.2025