You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `anyOf` keyword is a powerful but complex JSON Schema feature. **Better-JSON-Schema-Errors** intelligently simplifies its output by providing clear, consolidated error messages that are easier to debug. For detailed examples, see the dedicated [**anyOf** documentation](./docs/anyOf.md).
125
+
The `anyOf` keyword is a powerful but complex JSON Schema feature. **Better-JSON-Schema-Errors** intelligently simplifies its output by providing clear, consolidated error messages that are easier to debug.
Instead of 2 error message it manage to give single concise error message. For details, see the dedicated [Range documenetation](./documentation/range-handler.md)
204
+
205
+
### 6. Custom Keywords and Error Handlers
206
+
In order to create the custom keywords and error handlers we need create and register two types of handler: **Normalization Handler** and **Error Handlers**
207
+
208
+
1. Normalization: This phase takes the raw, often deeply nested, error tree from the validator and converts it into a NormalizedOutput (can check type of normalizedOutput in the index.d.ts file).
209
+
210
+
2. Error Handling: This phase takes the normalized data and uses it to generate the final error messages. This is the job of the Error Handlers.
211
+
212
+
Fist step -: Creating the keywordHandler
213
+
```Js
214
+
/**
215
+
* @import { KeywordHandler } from "@hyperjump/better-json-schema-errors"
When an instance fails all enum or const options in an anyOf, the library merges them into one clear error message, avoiding multiple errors and even suggesting close matches in many cases.
"message": "Unexpected value 2. Expected one of: 'a', 'b', 'c' or 1 ."
147
+
}
148
+
]
149
+
}
150
+
151
+
```
152
+
153
+
#### 5. anyOf with a Discriminator
154
+
155
+
When `anyOf` uses a discriminator, the library leverages it to give precise errors, matching the instance to the intended alternative via a specific property (e.g., `"type"`, `"const"`).
0 commit comments