Fork me on GitHub
#malli
<
2022-11-16
>
Bart Kleijngeld08:11:35

Is this expected behavior and if so, can someone point out what I'm misunderstanding? Explicitly stating to use the default schemas registry causes an error (and actually every merge I've done so far does):

(m/validate
  [:map
   [:x string?]]
  {:a 1})  ;; => false
(m/validate
  [:map {:registry (merge (m/default-schemas))}
   [:x string?]]
  {:a 1})  ;; => clojure.lang.ExceptionInfo: :malli.core/child-error {:type :enum, :properties nil, :children nil, :min 1, :max nil}
                 {:type :malli.core/child-error, :message :malli.core/child-error, :data {:type :enum, :properties nil, :children nil, :min 1, :max nil}}
Shouldn't this be equivalent?

ikitommi09:11:25

currently, the property-registry doesn’t allow IntoSchema instances, just Schemas. Original idea was that you can only present serializable things. Not sure if this is a good constraint, as you can anyway have non-serializable things in schemas, e.g [:string {:gen/gen …generator-function-here…}]

ikitommi09:11:31

Please write an issue out of this.

Bart Kleijngeld09:11:39

I will. Thanks for the explanation

Bart Kleijngeld09:11:27

See https://github.com/metosin/malli/issues/780 (If you have any title suggestion that will make this issue most findable/descriptive for you let me know)

👍 1
Bart Kleijngeld12:11:55

I'm looking to express something like an :or schema, but instead of enumerating the arguments by hand I'd like to supply a collection of schemas. So something like:

[:any-of schemas-coll]
instead of
[:or schema-1 schema-2 ... schema-n]
Especially nice because registries tend to be regular maps, so you can just pass those in. Of course I can construct the :or schema above from a collection, but I would expect some nice idiom to be present. Is there something like this present? Or should I create a new schema type for this?

ikitommi15:11:55

no idiom, children are currently varargs, not a single collection. But:

(into [:or] [:int :string])
; => [:or :int :string]

gratitude 2
nice 1
ikitommi15:11:11

also, there is the map ast:

(m/ast [:or :int :string])
; => {:type :or, :children [{:type :int} {:type :string}]}

(update *1 :children conj {:type :boolean})
; => {:type :or, :children [{:type :int} {:type :string} {:type :boolean}]}

(m/from-ast *1)
; => [:or :int :string :boolean]