re-implemented the schema visitor using walker: m/accept
is now a postwalk and and there is new m/find-first
to do lazy scanning for schemas. Though of doing a prewalk too, but coudn’t find any valid use case for such and would be more complex for schema extenders to add support for it. Not sure how useful the m/find-first
is and should merge this: https://github.com/metosin/malli/pull/216
should the m/accept
be just m/walk
in the future? or m/post-walk
?
(deftest find-first-test
(let [schema [:map
[:x int?]
[:y [:vector [:tuple
[:maybe int?]
[:or [:and {:salaisuus "turvassa"} boolean?] int?]
[:schema {:salaisuus "vaarassa"} false?]]]]
[:z [:string {:salaisuus "piilossa"}]]]]
(let [walked-properties (atom [])]
(is (= "turvassa" (m/find-first
schema
(fn [s _in _options]
(some->> s m/properties (swap! walked-properties conj))
(some-> s m/properties :salaisuus)))))
(is (= [{:salaisuus "turvassa"}] @walked-properties)))
(let [walked-properties (atom [])]
(is (= "vaarassa" (m/find-first
schema
(fn [s _in _options]
(some->> s m/properties (swap! walked-properties conj))
(some-> s m/properties :salaisuus #{"vaarassa"})))))
(is (= [{:salaisuus "turvassa"}
{:salaisuus "vaarassa"}] @walked-properties)))))
Hi all! Is there a possibility to merge definitions declaratively - for example in an edn definition given that the definitions to merge are defined in a registry?
I see I can do
[:and
[:ref :test/object]
[:ref :test/annotated]
[:map ....]]
but sadly this would test for all to be true rather than that later definitions override definitions from the former. Basically, I'm asking if there is something like mu/merge
in a declarative way@alpox nothing just now, but sounds like a good idea. Could you write an issue of that?
@ikitommi Done: https://github.com/metosin/malli/issues/217 thanks for the response!
what's the idiomatic way to specify a nonempty string in a schema? should I actually use a custom registry as in the README?
currently I'm doing this
(def nonempty-string
[:and
string?
[:fn {:error/message "should be nonempty string"}
(fn [x] (pos? (count x)))]])
one minor problem with that is that malli/explain
gives me two error messages: "should be string" and "should be nonempty string". I tried to set the :error/message
in the :and
instead to get only one error, but that didn't work
(I'm using the malli version that reitit 0.5.2 requires, i.e. 0.0.1-20200525.162645-15, if that matters)
I'm happy to upgrade to any version that is compatible with reitit 0.5.2
@euccastro [:string {:min 1}]
, will need to release new version to work with reitit
thank you!
@ikitommi is there any chance you can release a new version of reitit
with the latest malli
?
another option for early adopters would be to release cutting-edge versions of malli under a separate namespace and artifact id (e.g., malli.pre-alpha
) so we can use that for our own code without fear of breaking reitit. that would also reduce the pressure to update reitit unless new malli functionality is actually needed there
please ignore this if it sounds like too much of a hassle 🙂