mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Fixed dataPath handling for root property when dataPath is empty string
This commit is contained in:
@@ -2425,7 +2425,7 @@ module.exports = {
|
||||
if (options.suggestAvailableFixes) {
|
||||
mismatchObj.suggestedFix = {
|
||||
key: _.split(dataPath, '.').pop(),
|
||||
actualValue: _.get(valueToUse, dataPath, null),
|
||||
actualValue: (dataPath === '' ? valueToUse : _.get(valueToUse, dataPath, null)),
|
||||
suggestedValue: this.getSuggestedValue(fakedValue, valueToUse, ajvError)
|
||||
};
|
||||
}
|
||||
@@ -2457,7 +2457,14 @@ module.exports = {
|
||||
if (dataPath[0] === '.') {
|
||||
dataPath = dataPath.slice(1);
|
||||
}
|
||||
_.set(suggestedValue, dataPath, this.getSuggestedValue(fakedValue, valueToUse, ajvError));
|
||||
|
||||
// for empty string _.set creates new key with empty string '', so separate handling
|
||||
if (dataPath === '') {
|
||||
suggestedValue = this.getSuggestedValue(fakedValue, valueToUse, ajvError);
|
||||
}
|
||||
else {
|
||||
_.set(suggestedValue, dataPath, this.getSuggestedValue(fakedValue, valueToUse, ajvError));
|
||||
}
|
||||
});
|
||||
|
||||
mismatchObj.suggestedFix = {
|
||||
@@ -3408,14 +3415,17 @@ module.exports = {
|
||||
var suggestedValue,
|
||||
tempSuggestedValue,
|
||||
dataPath = ajvValidationErrorObj.dataPath || '',
|
||||
targetActualValue = _.get(actualValue, dataPath, {}),
|
||||
targetFakedValue = _.get(fakedValue, dataPath, {});
|
||||
targetActualValue,
|
||||
targetFakedValue;
|
||||
|
||||
// discard the leading '.' if it exists
|
||||
if (dataPath[0] === '.') {
|
||||
dataPath = dataPath.slice(1);
|
||||
}
|
||||
|
||||
targetActualValue = (dataPath === '' ? actualValue : _.get(actualValue, dataPath, {}));
|
||||
targetFakedValue = (dataPath === '' ? fakedValue : _.get(fakedValue, dataPath, {}));
|
||||
|
||||
switch (ajvValidationErrorObj.keyword) {
|
||||
|
||||
// to do: check for minItems, maxItems
|
||||
@@ -3450,7 +3460,7 @@ module.exports = {
|
||||
|
||||
// Keywords: minLength, maxLength, format, minimum, maximum, type, multipleOf, pattern
|
||||
default:
|
||||
suggestedValue = _.get(fakedValue, dataPath, null);
|
||||
suggestedValue = (dataPath === '' ? fakedValue : _.get(fakedValue, dataPath, null));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user