Fork me on GitHub
#malli
<
2021-11-27
>
ikitommi13:11:00

allowing schema registry to be swapped without compiler/jvm-options: https://github.com/metosin/malli/pull/583. There would be a "strict" mode too, if this is too loose for someone. But might be better for the 90% of cases?

(require '[malli.core :as m]
         '[malli.util :as mu]
         '[malli.registry :as mr]
         '[malli.generator :as mg])

;; look ma, just works
(mr/set-default-registry!
  (mr/composite-registry
    (m/default-schemas)
    (mu/schemas)))

(mg/generate
  [:merge
   [:map [:x :int]]
   [:map [:y :int]]])
; => {:x 0, :y 92}
comments welcome.

馃檹 3
ikitommi13:11:57

your sample could be:

(mr/set-default-registry!
  (mr/composite-registry
    (m/default-schemas)
    (mu/schemas)
    {:e.shopify/address1 [:map [:first_name string?]]
     :e.shopify/address2 [:map [:city string?]]
     :e.shopify/address-full [:merge
                              :e.shopify/address1
                              :e.shopify/address2]}))

(mg/generate :e.shopify/address-full)
;{:first_name "0GiD"
; :city "DMS5wc6mXcN4JCp9lJ"}

ikitommi13:11:40

also, you could inject a mutable-registry as last in the registry-chain and add the schemas using custom register! fn. Mutate like a boss 馃檪

Ivan Fedorov14:11:57

Oh this looks sweet! Thank you, mr Reiman!

pithyless17:11:12

Looking forward to this; I鈥檝e ended up fighting the tooling too often trying to get the compiler options working correctly in a consistent way.

ikitommi18:11:25

merged in master. a blog post and shipping 0.7.0 out.

Karol W贸jcik14:11:55

Will malli support records?

ikitommi14:11:08

what would that look like?

emccue22:11:49

[:and [:fn #(instance? RecordType %)]
      [:map [:x :int] [:y :int]]]
Is a basic way if you just need validation and not generation

emccue22:11:40

i鈥檓 not clever enough to compose the :map generator with map->RecordType but i assume there is a way

Karol W贸jcik08:11:27

I was thinking about something like schema is doing.

ikitommi09:11:22

m/defrecord I presume. I think Malli should have that and m/defproticol too.

Karol W贸jcik14:11:12

Cool. Looking forward to this.