Skip to content

Commit 1914f42

Browse files
committed
Merge branch 'master' of https://github.com/mtseluiko/OpenAPI
2 parents 4006588 + 8adea95 commit 1914f42

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

reverse_engineering/api.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const validationHelper = require('../forward_engineering/helpers/validationHelpe
99

1010
module.exports = {
1111
reFromFile(data, logger, callback) {
12+
logger.clear();
1213
commonHelper.getFileData(data.filePath).then(fileData => {
1314
return getOpenAPISchema(fileData, data.filePath);
1415
}).then(openAPISchema => {
@@ -26,7 +27,7 @@ module.exports = {
2627
message: "Review the log file for more details.",
2728
openLog: true,
2829
};
29-
logger.log('error', { validationErrors }, '[Warning] Invalid OpenAPI Schema');
30+
logger.log('error', { validationErrors: validationErrors.map(prettifyValidationWarning) }, '[Warning] Invalid OpenAPI Schema');
3031
}
3132

3233
return callback(null, reversedData.hackoladeData, { ...reversedData.modelData, warning }, [], 'multipleSchema');
@@ -89,6 +90,22 @@ const validateSchema = async (openApiSchema) => {
8990
return messages?.filter(error => error?.type !== 'success');
9091
};
9192

93+
const prettifyValidationWarning = warning => {
94+
if (!warning?.context) {
95+
return warning;
96+
}
97+
98+
return {
99+
...warning,
100+
context: '\n' + tab(warning.context || '').replace(/\t/gm, ' '),
101+
}
102+
};
103+
104+
const tab = (text, tab = ' ') => text
105+
.split('\n')
106+
.map(line => tab + line)
107+
.join('\n');
108+
92109
const convertOpenAPISchemaToHackolade = (openAPISchema, fieldOrder) => {
93110
const modelData = dataHelper.getModelData(openAPISchema);
94111
const components = openAPISchema.components;

0 commit comments

Comments
 (0)