Fork me on GitHub
#malli
<
2020-07-12
>
ikitommi07:07:54

About to replace MermaidJS with DOT, because it just works: https://github.com/metosin/malli/pull/219

👍 3
ikitommi07:07:45

the whole transformer is 69 loc, with most code reusable and could be part of malli.util (collecting and resolving references).

ikitommi08:07:35

the actual DOT-transformer is ~30 loc 🙂

shmuel buchnik09:07:56

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])

ikitommi10:07:01

@shmuel.buchnic I believe the map entry should be [:filter ::filter], e.g. surround with brackets

ikitommi10:07:58

recursion is a generic solution, unless there are bugs, it works with all Schemas

shmuel buchnik11:07:02

@U055NJ5CC thanks for the fast response I tried and it still return an invalid schema . I will try to narrow down the issue .

shmuel buchnik12:07:20

@U055NJ5CC well it is working with simple validate , but trying to use it as :coercion to body parameters and it fails .

ikitommi13:07:58

you seem to have two "in" branches in multi.

ikitommi13:07:56

(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")}

shmuel buchnik13:07:23

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?]]]]]]]}})

shmuel buchnik13:07:26

no 😞 I fixed it before u wrote forgot to update. validate call is working

shmuel buchnik13:07:53

but as :coercion it does not work

ikitommi14:07:38

what version are you using of reitit?

shmuel buchnik14:07:18

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 .

shmuel buchnik16:07:42

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 😞

ikitommi18:07:52

I can reproduce this.

ikitommi18:07:03

Will check this out

👍 3
ikitommi08:07:09

pushed out [metosin/reitit "0.5.4"] with the fix in.

🚀 3