quick question with regards to properties. I’m trying to put some properties into my schemas, but can’t seem to be getting them back. What am I doing wrong here?
; malli 0.3.0:
; [malli.registry :as registry]
(def registry
(registry/composite-registry
malli/default-registry
{:common/single-line [:re {:bubu :lala} #"^[^\r\n]*$"]}))
(malli/properties :common/single-line {:registry registry})
=> nil
Expected: {:bubu :lala}
@beders oh, that’s not good. registry interally wraps the registered schema instances into :malli.core/schema
, which is an eager reference type. When you pull out an instance schema from a registry, you get the reference back. it mostly a pass-through, e.g. calling -validator
to the reference return the validator of the referenced schema. But: for some reason, the current impl returns the reference properties and options if asked. I think it’s a bad feature, should be changed.
need to think how that effects other things. before that, you m/deref
safely:
(def registry
(mr/composite-registry
m/default-registry
{:common/single-line [:re {:bubu :lala} #"^[^\r\n]*$"]}))
(-> (m/schema :common/single-line {:registry registry})
(doto prn)
(m/deref)
(doto prn)
(m/properties))
;:common/single-line
;[:re {:bubu :lala} #"^[^\r\n]*$"]
;=> {:bubu :lala}
workaround for now:
(def registry
(mr/composite-registry
m/default-registry
{:common/single-line [:re {:bubu :lala} #"^[^\r\n]*$"]}))
(defn schema [?schema]
(m/deref (m/schema ?schema {:registry registry})))
(schema :common/single-line)
; => [:re {:bubu :lala} #"^[^\r\n]*$"]
Thanks for the help and explanation. It would be good to have some documentation around explaining instances vs. Schema. I’m still confused 🙂
comments welcome on how it should work.
Is there a standard body of localized error messages for humanize
?
Only english https://github.com/metosin/malli/blob/master/src/malli/error.cljc
However, the docs do show how to add in other i18n messages
@ikitommi What about making a plugin for malli which inspects clojure.spec specs and emits a malli schema from it? ;) Might help people migrating to malli
@borkdude brilliant idea. Let's do it.
Hi, trying to wrap my mind around how these two examples can/will differ over time when it comes to value generation
(def CDN1
[:map
[:images [:vector string?]]])
(def CDN2
[:map
[:images [:sequential string?]]])
(malli.generator/generate CDN1)
(malli.generator/generate CDN2)
-- i guess the question is - will they defer ? and if so how ? in my testing the generated values are very similar@dviramontes in clojure sequential can also be a list
or lazy-seq
for example, not always a vector, but that should not affect equality semantics
it seems the generator doesn't really generate anything other than vectors at the moment (by experimentation) but it could
gotcha, thanks very much!
TIL, malli also supports keywords as predicates:
(malli.generator/generate [:sequential :int])
I prefer that syntax personallyuser=> (malli.core/validate :int 1)
true