I have a requirement to autogerate Json schema with dependencies ( one attribute is required or not based on other attribute value ).
My exact situation has been asked and answered in jsonSchema attribute conditionally required.
However, my requirement doesn't allow manual changes to schema directly. I'm creating schema using POJO's with Jackson annotations. In a nutshell, I need Jackson annotation to achieve this.
{
"type": "object",
"properties": {
"foo": { "type": "string" },
"bar": { "type": "string" }
},
"if": {
"properties": {
"foo": { "const": "bar" }
},
"required": ["foo"]
},
"then": { "required": ["bar"] }
}
(or)
{
"type": "object",
"properties": {
"foo": { "enum": ["bar", "baz"] },
"bar": { "type": "string" },
"baz": { "type": "string" }
},
"anyOf": [
{
"properties": {
"foo": { "const": "bar" }
},
"required": ["bar"]
},
{
"properties": {
"foo": { "const": "baz" }
},
"required": ["baz"]
}
]
}
I have experimented with Jackson annotations like @JsonProperty, @JsonFilter, @JsonSerialize etc. Please do nudge me in right direction.
Thanks.