Skip to content

Commit a2b7060

Browse files
committed
handle more anyOf cases for better-errors
1 parent 9e7f57f commit a2b7060

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ BetterJSONSchemaErrors Output:-
200200
```
201201
Instead of 2 error message it manages to give a single concise error message. For details, see the dedicated [Range documenetation](./documentation/range-handler.md)
202202

203-
### 6. Custom Keywords and Error Handlers
203+
### 7. Custom Keywords and Error Handlers
204204
In order to create the custom keywords and error handlers we need to create and
205205
register two types of handlers: **Normalization Handler** and **Error Handlers**.
206206

src/error-handlers/anyOf.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ const anyOfErrorHandler = async (normalizedErrors, instance, localization) => {
146146
}
147147
// Discriminator identified, but none of the alternatives match
148148
if (discriminatedAlternatives.length === 0) {
149-
// TODO: How do we handle this case?
149+
// TODO: For now, it will use the schema description strategy
150150
}
151+
151152
// Last resort, select the alternative with the most properties matching the instance
152153
const instanceProperties = new Set(Instance.values(instance).map((node) => Instance.uri(node)));
153154
let maxMatches = -1;
@@ -165,8 +166,6 @@ const anyOfErrorHandler = async (normalizedErrors, instance, localization) => {
165166
}
166167
}
167168

168-
// TODO: Handle number alternatives
169-
// TODO: Handle array alternatives
170169
// TODO: Handle alternatives without a type
171170

172171
/** @type string[] */

src/translations/en-US.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ number-description = a number {$constraints}
1919
string-description = a string {$constraints}.
2020
array-description = an array {$constraints}
2121
tuple-description = a tuple with {$numItems} items.
22-
object-description = a object {$constraints}
22+
object-description = an object {$constraints}
2323
2424
# String messages
2525
string-error = Expected a string {$constraints}.

0 commit comments

Comments
 (0)