JSON Schema validation: IF/THEN/ELSE question using $ref #563
-
I have this JSON: {
"ActionSet": {
"A1.2": {
"ID": "A1.2",
"AID": "AID-001-02",
"ActionProperty": {
"$ref": "#/PC-Properties/rb6_cls_in_scope"
},
"SetValue": "In scope",
"Comment": ""
},
"A1.3": {
"ID": "A1.3",
"AID": "AID-001-03",
"ActionProperty": {
"$ref": "#/PC-Properties/rb6_cls_in_scope"
},
"SetValue": "Not in scope",
"Comment": ""
},
"A2.1": {
"ID": "A2.1",
"AID": "AID-002-01",
"ActionProperty": {
"$ref": "#/PC-Properties/rb6_CoC__div_process"
},
"SetValue": 2,
"Comment": "Set to 'Ongoing'"
}
}
} And I have this JSON-Schema: {
"properties": {
"ID": {
"type": "string",
"pattern": "^A\\d+\\.\\d+$"
},
"AID": {
"type": "string",
"pattern": "^AID-\\d{3}-\\d{2}$"
},
"ActionProperty": {
"type": "object"
},
"SetValue": {
"type": [
"integer",
"string"
]
},
"Comment": {
"type": "string"
}
},
"if": {
"properties": {
"ActionProperty": {
??? ===> "$ref": "#/PC-Properties/rb6_CoC__div_process" <=====???
}
}
},
"then": {
"properties": {
"SetValue": {
"type": "integer",
"const": 99
}
}
}
} I want to validate, that if ActionProperty has this value (or reference): "ActionProperty": {
"$ref": "#/PC-Properties/rb6_CoC__div_process"
}, The SetValue must be a integer with constant value 99. What shall I use here?: "if": {
"properties": {
"ActionProperty": {
??? ===> "$ref": "#/PC-Properties/rb6_CoC__div_process" <=====???
}
}
} Your help is so much appreciated. Thank you. |
Beta Was this translation helpful? Give feedback.
Answered by
jdesrosiers
Jan 2, 2024
Replies: 2 comments 1 reply
-
You can use "if": {
"properties": {
"ActionProperty": {
"const": { "$ref": "#/PC-Properties/rb6_CoC__div_process" }
}
},
"required": ["ActionProperty"]
}, |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dlukacic
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
const
.const
takes any type of value including objects.