malli

Pavel Filipenco 2024-09-26T18:20:35.199309Z

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 advance

Pavel Filipenco 2024-09-26T20:22:13.469959Z

Very good. Is there any info for the second usecase?

2024-09-26T22:52:37.081989Z

A :fn schema should work to check that :x is in both :products and :wholesale-prices.

👍 1
2024-09-26T22:53:40.835459Z

You can combine the :fn with another schema using :and.

Pavel Filipenco 2024-09-27T14:41:32.702549Z

Thanks!