Skip to content

Commit a362ad4

Browse files
fix multipleOf only considers case that fail in allOf (#158)
1 parent 671315b commit a362ad4

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/error-handlers/multipleOf.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ const multipleOfErrorHandler = async (normalizedErrors, instance, localization)
1515
let combinedMultipleOf = null;
1616
/** @type string[] */
1717
const schemaLocations = [];
18+
let hasError = false;
1819

1920
for (const schemaLocation in normalizedErrors["https://json-schema.org/keyword/multipleOf"]) {
20-
if (normalizedErrors["https://json-schema.org/keyword/multipleOf"][schemaLocation]) {
21-
continue;
21+
if (!normalizedErrors["https://json-schema.org/keyword/multipleOf"][schemaLocation]) {
22+
hasError = true;
2223
}
2324

2425
const keyword = await getSchema(schemaLocation);
@@ -28,7 +29,7 @@ const multipleOfErrorHandler = async (normalizedErrors, instance, localization)
2829
schemaLocations.push(schemaLocation);
2930
}
3031

31-
if (combinedMultipleOf !== null) {
32+
if (combinedMultipleOf !== null && hasError) {
3233
errors.push({
3334
message: localization.getMultipleOfErrorMessage(combinedMultipleOf),
3435
instanceLocation: Instance.uri(instance),

src/test-suite/tests/multipleOf.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@
6262
"schemaLocations": ["#/allOf/0/multipleOf", "#/allOf/1/multipleOf"]
6363
}
6464
]
65+
},
66+
{
67+
"description": "multipleOf constraints within allOf are partially satisfied",
68+
"schema": {
69+
"allOf": [
70+
{ "multipleOf": 2 },
71+
{ "multipleOf": 3 }
72+
]
73+
},
74+
"instance": 9,
75+
"errors": [
76+
{
77+
"messageId": "multipleOf-message",
78+
"messageParams": {
79+
"multipleOf": "6"
80+
},
81+
"instanceLocation": "#",
82+
"schemaLocations": ["#/allOf/0/multipleOf", "#/allOf/1/multipleOf"]
83+
}
84+
]
6585
}
6686
]
6787
}

0 commit comments

Comments
 (0)