-
Notifications
You must be signed in to change notification settings - Fork 332
Open
Description
🐛 Bug Report / Feature Request
The errorMessage keyword does not appear to support if / then / else blocks.
What I'm trying to do
I want to define custom error messages for conditional schemas using if / then logic, like this:
{
"if": {
"properties": {
"type": { "const": "business" }
}
},
"then": {
"required": ["businessId"]
},
"errorMessage": {
"if": "Type condition failed",
"then": "Missing businessId when type is 'business'",
"else": "Missing required fields for other types"
}
}I also tried:
"errorMessage": "Custom message for conditional failure"and
"then": {
"required": ["someField"],
"errorMessage": {
"required": "someField must be provided"
}
}Actual Behavior
- The schema validates correctly
- But custom messages in
errorMessageforif,then, orelseare ignored - Instead, it shows the default errors
Expected Behavior
I expected that:
"errorMessage": {
"then": "Missing businessId when type is 'business'"
}…would override the default message when the then clause fails (i.e., businessId is missing).
Minimal Reproducible Schema
{
"$schema": "https://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"type": { "type": "string" },
"businessId": { "type": "string" }
},
"if": {
"properties": {
"type": { "const": "business" }
},
"required": ["type"]
},
"then": {
"required": ["businessId"]
},
"errorMessage": {
"then": "Missing 'businessId' when 'type' is 'business'"
}
}Expected Result
Error message returned should be:
Missing 'businessId' when 'type' is 'business'
Questions
- Is
errorMessageforif/then/elseunsupported? Or am I doing something wrong? - If not supported, would you consider this a useful feature to add?
Metadata
Metadata
Assignees
Labels
No labels