Skip to content

Commit b5d764e

Browse files
committed
Fixed issue where composite schema validation mismatch for oneOf were not ignored corectly
1 parent 514c159 commit b5d764e

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

lib/ajValidation/ajvValidation.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,39 @@ function getDraftToUse(localDraft, jsonSchemaDialect) {
5858
* @returns {Array} Filtered mismatches after removing composite schema mismatches for valid data
5959
*/
6060
function filterCompositeSchemaErrors (schema, validationMismatches) {
61-
const compositeSchemaKeywords = ['anyOf', 'oneOf'],
62-
compositeSchemaKeyword = compositeSchemaKeywords[0],
63-
compositeSchemaMismatches = _.filter(validationMismatches, (validationMismatch) => {
61+
_.forEach(['anyOf', 'oneOf'], (compositeSchemaKeyword) => {
62+
const compositeSchemaMismatches = _.filter(validationMismatches, (validationMismatch) => {
6463
return validationMismatch.keyword === compositeSchemaKeyword &&
6564
_.endsWith(validationMismatch.schemaPath, compositeSchemaKeyword);
6665
});
6766

68-
_.forEach(compositeSchemaMismatches, (compositeSchemaMismatch) => {
69-
let compositeSchemaMismatchPath = compositeSchemaMismatch.schemaPath,
70-
schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(compositeSchemaMismatchPath)),
71-
schemaToUse = schemaDataPath ? _.get(schema, schemaDataPath) : schema,
72-
isCompositeSchemaValid = false;
67+
_.forEach(compositeSchemaMismatches, (compositeSchemaMismatch) => {
68+
let compositeSchemaMismatchPath = compositeSchemaMismatch.schemaPath,
69+
schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(compositeSchemaMismatchPath)),
70+
schemaToUse = schemaDataPath ? _.get(schema, schemaDataPath) : schema,
71+
isCompositeSchemaValid = false;
7372

74-
if (!_.isArray(schemaToUse)) {
75-
return false;
76-
}
73+
if (!_.isArray(schemaToUse)) {
74+
return false;
75+
}
7776

78-
for (let index = 0; index < schemaToUse.length; index++) {
79-
const isCurrentElementInvalid = _.some(validationMismatches, (mismatch) => {
80-
return _.startsWith(mismatch.schemaPath, compositeSchemaMismatchPath + `/${index}`);
81-
});
77+
for (let index = 0; index < schemaToUse.length; index++) {
78+
const isCurrentElementInvalid = _.some(validationMismatches, (mismatch) => {
79+
return _.startsWith(mismatch.schemaPath, compositeSchemaMismatchPath + `/${index}`);
80+
});
8281

83-
if (!isCurrentElementInvalid) {
84-
isCompositeSchemaValid = true;
85-
break;
82+
if (!isCurrentElementInvalid) {
83+
isCompositeSchemaValid = true;
84+
break;
85+
}
8686
}
87-
}
8887

89-
if (isCompositeSchemaValid) {
90-
validationMismatches = _.reject(validationMismatches, (mismatch) => {
91-
return _.startsWith(mismatch.schemaPath, compositeSchemaMismatchPath);
92-
});
93-
}
88+
if (isCompositeSchemaValid) {
89+
validationMismatches = _.reject(validationMismatches, (mismatch) => {
90+
return _.startsWith(mismatch.schemaPath, compositeSchemaMismatchPath);
91+
});
92+
}
93+
});
9494
});
9595

9696
return validationMismatches;

0 commit comments

Comments
 (0)