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 diff --git a/lib/compile/index.js b/lib/compile/index.js index 6c1e82a..504af72 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"], "utf-8"); + 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 }); } }