Skip to content

Commit 18e5014

Browse files
authored
fix: Reading json files from project root (#93)
1 parent 1ad0d10 commit 18e5014

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

77
## [Unreleased]
88

9+
### Fixed
10+
- Reading json from project root
911

1012
## Version 1.2.3 - 28.05.2025
1113

lib/compile/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ function toOpenApiOptions(csdl, csn, options = {}) {
9393
}
9494

9595
if (result["config-file"]) {
96-
if (fs.existsSync(result["config-file"])) {
97-
const fileContent = require(result["config-file"]);
96+
if (!fs.existsSync(result["config-file"])) {
97+
throw new Error("Unable to find openapi config file " + result["config-file"]);
98+
}
99+
100+
try{
101+
const fileData = fs.readFileSync(result["config-file"], "utf-8");
102+
const fileContent = JSON.parse(fileData);
103+
98104
Object.keys(fileContent).forEach((key) => {
99105
if (key === "odata-version" && !result["odataVersion"]) {
100106
result["odataVersion"] = fileContent[key];
@@ -104,8 +110,8 @@ function toOpenApiOptions(csdl, csn, options = {}) {
104110
result[key] = JSON.stringify(fileContent[key]);
105111
}
106112
});
107-
} else {
108-
throw new Error("Error while parsing the openapi configuration file " + result["config-file"]);
113+
}catch(err){
114+
throw new Error("Unable to parse OpenAPI config " + result["config-file"], { cause: err });
109115
}
110116
}
111117

0 commit comments

Comments
 (0)