Fork me on GitHub
#malli
<
2022-08-11
>
ikitommi09:08:27

^:-- if someone can show an real-life example where the value masking is still bad, please share (privately ok too). I guess if one has huge nested maps, masking each irrelevant key separately might still cause large values. Or a list of 100 entries with the last one in failure would cause 99 s, which might not be best. For maps, all the irrelevant keys could be optionally accumulated into single entry on as both key and value and for sequences, a …99 to show how many valids there are.

dangercoder19:08:06

Hi, great work on Malli! I’m trying to figure out how I can use malli without duplicating attributes. Is the “What I want” syntax possible in some way?

;; What I have
[:map
 [::order-id :int]
 [::order-multiplier :int]
 [::order-amount decimal?]]

;; What I want
[:map
 [::order-id]
 [::order-multiplier]
 [::order-amount]]

(m/validate ::order-id "123")
;; => false

valtteri19:08:06

You can define a registry and register your schemas there. Here’s an inline example

(m/validate ::order-id "123" {:registry (merge
                                         (m/default-schemas)
                                         {::order-id :int
                                          ::order-multiplier :int
                                          ::order-amount decimal?})})

valtteri19:08:01

More info how to work with registries here https://github.com/metosin/malli#schema-registry

dangercoder19:08:03

Thanks a lot for the answer, cheers!

👌 1
dangercoder20:08:11

Cool thing. I created a custom “register function”.

(s/register ::api-key [:string {:min 1}])
in IntelliJ/cursive i resolved my function as clojure.spec.alpha/def — this way I can jump to the schema-definition of a namespaced keyword if there is a register call. 😄