Hello everyone. I have a use-case where if some key in a map is a certain value (it's an enum), then the schema is a certain way, if it's another, then it's another way. Is this something malli can validate? Another question, if a map contains a certain key, then this key must be a key of another, nearby map.
clojure
{:products {:x {:id 1 :wholesale? true} :y {:id 2} :z {:id 3}}
:wholesale-prices {:x 40}} ;; :products must have an :x key and its :wholesale? property must be true
This is a simplified example. It's not possible to just put :price into the products map. Can this be done? Thanks in advanceYes, I believe this is a case of https://github.com/metosin/malli?tab=readme-ov-file#multi-schemas. See also the https://malli.io/?value=%5B%7B%3Atype%20%3Asized%2C%20%3Asize%2010%7D%0A%20%7B%3Atype%20%3Ahuman%2C%20%3Aname%20%22tiina%22%2C%20%3Aaddress%20%7B%3Astreet%20%22kikka%22%7D%7D%5D&schema=%5B%3Avector%0A%20%5B%3Amulti%0A%20%20%7B%3Adispatch%20%3Atype%7D%0A%20%20%5B%3Asized%20%5B%3Amap%20%5B%3Atype%20%5B%3A%3D%20%3Asized%5D%5D%20%5B%3Asize%20int%3F%5D%5D%5D%0A%20%20%5B%3Ahuman%0A%20%20%20%5B%3Amap%0A%20%20%20%20%5B%3Atype%20%5B%3A%3D%20%3Ahuman%5D%5D%0A%20%20%20%20%5B%3Aname%20string%3F%5D%0A%20%20%20%20%5B%3Aaddress%20%5B%3Amap%20%5B%3Astreet%20string%3F%5D%5D%5D%5D%5D%5D%5D.
Very good. Is there any info for the second usecase?
A :fn schema should work to check that :x is in both :products and :wholesale-prices.
You can combine the :fn with another schema using :and.
Thanks!