About to replace MermaidJS with DOT, because it just works: https://github.com/metosin/malli/pull/219
the whole transformer is 69 loc, with most code reusable and could be part of malli.util
(collecting and resolving references).
the actual DOT-transformer is ~30 loc 🙂
Hi I am new to malli Can I use multi with recursive ? I tried this and it does not work
(def map-multi-recursive
[:map
{:registry
{::filter
[:multi
{:dispatch :type}
["in" [:map [:type [:= "in"]] [:value [:vector [:ref ::filter]]]]]
["or" [:map [:type [:= "or"]] [:value [:vector [:ref ::filter]]]]]
["not" [:map [:type [:= "not"]] [:value [:ref ::filter]]]]
["in" [:map [:type [:= "in"]] [:value [:map
[:dimensions dimension]
[:values [:vector string?]]]]]]]}}
:filter ::filter])
@shmuel.buchnic I believe the map entry should be [:filter ::filter]
, e.g. surround with brackets
recursion is a generic solution, unless there are bugs, it works with all Schemas
fixed in https://github.com/metosin/malli/commit/9f105a53e459f9b85bfbd5c07d747fbe5d5d6f65
pushed out [metosin/reitit "0.5.4"]
with the fix in.
@ikitommi thanks for the fast response I tried and it still return an invalid schema . I will try to narrow down the issue .
@ikitommi well it is working with simple validate , but trying to use it as :coercion to body parameters and it fails .
you seem to have two "in"
branches in multi.
will fail-fast in master: https://github.com/metosin/malli/commit/5d54e6b285c3ce440f1310302bdc2ba20a84d508
(m/schema
[:map
{:registry
{::filter
[:multi
{:dispatch :type}
["in" [:map [:type [:= "in"]] [:value [:vector [:ref ::filter]]]]]
["or" [:map [:type [:= "or"]] [:value [:vector [:ref ::filter]]]]]
["not" [:map [:type [:= "not"]] [:value [:ref ::filter]]]]
["in" [:map [:type [:= "in"]] [:value [:map
[:dimensions [:tuple int? int?]]
[:values [:vector string?]]]]]]]}}
[:filter ::filter]])
; => Throws :malli.core/non-distinct-entry-keys {:keys ("in" "or" "not" "in")}
I fixed that the updated looks like this :
(def filter-local-registry
{:registry
{::filter
[:multi
{:dispatch :type}
["and" [:map [:type [:= "and"]] [:value [:vector [:ref ::filter]]]]]
["or" [:map [:type [:= "or"]] [:value [:vector [:ref ::filter]]]]]
["not" [:map [:type [:= "not"]] [:value [:ref ::filter]]]]
["in" [:map [:type [:= "in"]] [:value [:map
[:dimension dimension]
[:values [:vector string?]]]]]]]}})
works now?
no 😞 I fixed it before u wrote forgot to update. validate call is working
but as :coercion it does not work
what version are you using of reitit?
0.5.3 I debug it . It looks like at first he find filter in registry (holds 2 the default one and the local) But on later call I only see the default on the registry and than lookup fail .
Narrowing issue : This is the schema
(def sample-request
[:map {:registry {::age [:and int? [:> 18]]}}
[:age ::age]])
This is the route
(def overview
["/api/v1/overview"
{:swagger {:tags ["Overview"]}
:post {:summary "get an overview data"
:parameters {:body sample-request}
:handler get-overview-data
}}])
The handler and other are just like in :
https://github.com/metosin/reitit/blob/master/examples/ring-malli-swagger/src/example/server.clj
So it is not related to recursive or mutli I guess it is just wrong usage of me with registry I just did not find out what it is 😞I can reproduce this.
Will check this out