I am using plumatic/schema with my compojure-api to validate the input for an endpoint.
I have two keys in my schema: Field1
& Field2
. I want to be able to define a rule for my schema which for example says:
WHEN Field1 = "AA"
THEN Field2 is required-key
ELSE Field2 is optional-key
But, I only seem to only be able to set the key to either require or optional. Is it possible to make a key depended on another key?
(schema/def Field1
(schema/enum "AA" "BB"))
(schema/def Field2
(schema/enum "AAAA" "BBBB" "CCCC"))
(schema/defschema MySchema
{(schema/required-key :field1) Field1
; Here I want some kind of logic to make the key required if
(if (= Field1 "AA")
(schema/required-key :field2) Field2
(schema/optional-key :field) Field2)
})