Fork me on GitHub
#malli
<
2021-04-10
>
ikitommi17:04:52

Some breaking changes coming to the extender-api, moving -type and -type-properties from Schema to IntoSchema. And some new methods so that we can describe the Malli schemas with Malli:

(defprotocol IntoSchema
  (-type [this] "returns type of the schema")
  (-type-properties [this] "returns schema type properties")
  (-properties-schema [this] "maybe returns :map schema describing schema properties")
  (-children-schema [this] "maybe returns sequence schema describing schema children")
  (-into-schema [this properties children options] "creates a new schema instance"))

ikitommi18:04:23

also, much better print presentations now:

(m/-enum-schema)
; => #IntoSchema{:type :enum}

(m/schema [*1 "A" "B"])
; => [:enum "A" "B"]

(type *1)
; => :malli.core/schema

Hankstenberg20:04:53

If I want to generate valid malli schemas of the form: [:map [:key1 int?] [:key2 int?] .... [:keyn int?]] using another malli schema - a meta-schema so to speak - what would that meta-schema look like? I've tried: [:tuple [:= :map] [:+ [:tuple simple-keyword? [:= :int]]]]) But it has a flaw: it e.g. generates: [:map [[:key1 int?] [:key2 int?] .... [:keyn int?]]] one pair of square brackets too much around the key-value-tuples. Does anybody know how to solve this using malli?

ikitommi21:04:57

@roseneck it’s a sequence:

(mg/generate
  [:cat {:gen/fmap vec}
   [:= :map]
   [:* [:tuple :keyword :int]]]
  {:size 42, :seed 200})
;[:map
; [:IjPg2 -5908]
; [:E+:H9l* 287044292]
; [:*vCe._5z 10637946460]
; [:kLq67 -125]
; [:J9?D+FY4G 718]
; [:*_1*Rc+A -908]
; [:?qi 1523]
; [:x.+ -1]
; [:D4*5 -13]
; [:.C4 -80]
; [:r-A 3161894]
; [:rcC 1118]
; [:Q*._k*w8iG 194253522]
; [:o!dfA 21159377159]
; [:nx!h 973119]
; [:C:!Rw 109221]
; [:?N38.*3? -11854145]
; [:lb5Z?9V?_v* -42]
; [:i!M.l?D+ 2026049]
; [:++k43x -141680]
; [:U- -8]
; [:*x 1491554935632]
; [:heX2 1957851783]
; [:_PZ?q3+! -83]
; [:*H*x8N:.! 1452]
; [:k_Oy2+LXD -864224065]
; [:p 55]
; [:*o+1ul*5?? -1766412]
; [:W7:-61 -17174129950]
; [:qv79TTj_+ 21380662]
; [:h -30089]]

3
Hankstenberg21:04:31

Thanks a lot! 🙂