`allOf` + `if/then/else` break when present at different levels.
See original GitHub issuePrerequisites
- [ x] I have read the documentation;
- [ x] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [ x] Ideally, I’m providing a sample JSFiddle or a shared playground link demonstrating the issue.
Description
I tried to implement multiple if/then/else on nested objects.
While correctly working on nested objects, if I try to add a allOf
on main object, this doesn’t work anymore.
Ex if you try to paste those schemas on the playground
- OK
allOf in nested object
{
"type": "object",
"properties": {
"animal": {
"enum": [
"Cat",
"Fish"
]
},
"venue": {
"type": "object",
"title": "Location",
"properties": {
"space": {
"enum": ["inside", "outside"] ,
"default": "outside"
}
},
"allOf": [
{
"if": {"properties": {"space": {"const": "inside"}}},
"then": {"properties": {"room": {"type": "string", "enum": ["bedroom", "living room"]}}}
},
{
"if": {"properties": {"space": {"const": "outside"}}},
"then": {"properties": {"room": {"type": "string", "enum": ["garden", "terrace"]}}}
}
]
}
}
}
- Still OK
allOf in main object
{
"type": "object",
"properties": {
"animal": {
"enum": [
"Cat",
"Fish"
]
}
},
"allOf": [
{
"if": {
"properties": {
"animal": {
"const": "Cat"
}
}
},
"then": {
"properties": {
"food": {
"type": "string",
"enum": [
"meat",
"grass",
"fish"
]
}
},
"required": [
"food"
]
}
},
{
"if": {
"properties": {
"animal": {
"const": "Fish"
}
}
},
"then": {
"properties": {
"food": {
"type": "string",
"enum": [
"insect",
"worms"
]
},
"water": {
"type": "string",
"enum": [
"lake",
"sea"
]
}
},
"required": [
"food",
"water"
]
}
},
{
"required": [
"animal"
]
}
]
}
- NOT OK
allOf in both main and nested object
{
"type": "object",
"properties": {
"animal": {
"enum": [
"Cat",
"Fish"
]
},
"venue": {
"type": "object",
"title": "Location",
"properties": {
"space": {
"enum": ["inside", "outside"] ,
"default": "outside"
}
},
"allOf": [
{
"if": {"properties": {"space": {"const": "inside"}}},
"then": {"properties": {"room": {"type": "string", "enum": ["bedroom", "living room"]}}}
},
{
"if": {"properties": {"space": {"const": "outside"}}},
"then": {"properties": {"room": {"type": "string", "enum": ["garden", "terrace"]}}}
}
]
}
},
"allOf": [
{
"if": {
"properties": {
"animal": {
"const": "Cat"
}
}
},
"then": {
"properties": {
"food": {
"type": "string",
"enum": [
"meat",
"grass",
"fish"
]
}
},
"required": [
"food"
]
}
},
{
"if": {
"properties": {
"animal": {
"const": "Fish"
}
}
},
"then": {
"properties": {
"food": {
"type": "string",
"enum": [
"insect",
"worms"
]
},
"water": {
"type": "string",
"enum": [
"lake",
"sea"
]
}
},
"required": [
"food",
"water"
]
}
},
{
"required": [
"animal"
]
}
]
}
Food and water doesn’t appear anymore :

Expected behavior
Conditional properties food and water should also appear when nested objects contains allOf
Version
"@rjsf/bootstrap-4": "^3.2.1",
"@rjsf/core": "^4.0.1",
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Validation: if/then/else · Issue #180 · json-schema-org ...
As I've written in some issue the schema with if/then/else: ... can either short-circuit "allOf", etc. or you can check all branches even...
Read more >ifthenelse conditional & macro
What happens here is that TeX reads all of the argument to \ifthenelse with the currently active catcodes: those of a normal LaTeX...
Read more >Ifelse - Amazon QuickSight
ifelse evaluates a set of if, then expression pairings, and returns the value of the then argument for the first if argument that...
Read more >Using If...Then...Else statements (VBA)
The statement following the Else statement runs if the conditions in all of the If and ElseIf statements are False. VB Copy. Function...
Read more >If..Then..Else | CueServer 2 Manual
Since no commands are present after the “Cue 1 Go”, an EndIf is not necessary. ... Then statements, all of the commands after...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The observed behaviour makes sense to me and is not a bug but a feature imho. It will try to “merge” the readOnly property. But since it’s already defined, the value from “then” is ignored / overruled. As an alternative, you still can define the field upfront, but specify the readOnly true/false in either the “then” and “else” sections like so:
Using @rjsf/core 4.2.0, I’m seeing the same error reported for the following schema:
However, if we not define “prazo” beforehand, it works: