malli

https://github.com/metosin/malli :malli:
ikitommi 2020-07-12T07:58:54.120100Z

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

1👍
ikitommi 2020-07-12T07:59:45.121Z

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

ikitommi 2020-07-12T08:00:35.121400Z

the actual DOT-transformer is ~30 loc 🙂

shmuel buchnik 2020-07-12T09:32:56.122700Z

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

ikitommi 2020-07-12T10:06:01.124800Z

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

ikitommi 2020-07-12T10:06:58.125900Z

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

ikitommi 2020-07-13T08:11:09.132700Z

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

1🚀
shmuel buchnik 2020-07-12T11:01:02.126200Z

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

shmuel buchnik 2020-07-12T12:59:20.126500Z

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

ikitommi 2020-07-12T13:00:58.126800Z

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

ikitommi 2020-07-12T13:01:38.127Z

will fail-fast in master: https://github.com/metosin/malli/commit/5d54e6b285c3ce440f1310302bdc2ba20a84d508

ikitommi 2020-07-12T13:01:56.127200Z

(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 buchnik 2020-07-12T13:02:23.127400Z

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

ikitommi 2020-07-12T13:02:39.127600Z

works now?

shmuel buchnik 2020-07-12T13:03:26.127800Z

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

shmuel buchnik 2020-07-12T13:03:53.128Z

but as :coercion it does not work

ikitommi 2020-07-12T14:05:38.128200Z

what version are you using of reitit?

shmuel buchnik 2020-07-12T14:07:18.128400Z

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 buchnik 2020-07-12T16:18:42.128700Z

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 😞

ikitommi 2020-07-12T18:22:52.129Z

I can reproduce this.

ikitommi 2020-07-12T18:23:03.129200Z

Will check this out

1👍