This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-25
Channels
- # announcements (9)
- # babashka (38)
- # beginners (41)
- # biff (1)
- # clojure (19)
- # clojure-europe (7)
- # clojure-uk (2)
- # clojurescript (3)
- # code-reviews (30)
- # conjure (4)
- # cursive (8)
- # datomic (32)
- # docker (2)
- # emacs (7)
- # etaoin (2)
- # fulcro (37)
- # graphql (2)
- # jobs (1)
- # jobs-discuss (8)
- # leiningen (10)
- # lsp (36)
- # meander (4)
- # missionary (4)
- # nbb (12)
- # off-topic (1)
- # other-languages (10)
- # pathom (11)
- # re-frame (5)
- # reitit (4)
- # remote-jobs (3)
- # shadow-cljs (13)
- # sql (1)
- # tools-build (4)
- # tools-deps (31)
- # xtdb (2)
I am failing to get actual malli coercion behavior and I'm rather at a loss as to why. I'm following the examples almost line for line and yet the compiled coercer doesn't showup in the :result
key as shown in the docs. I just get nil, and the result is no coercion happens (`coerce` just returns nil
). Code in the replies.
I'll summarize then. We generate a set of routes that looks like this:
(def expected-api
[[(str "/test-model")
{:coercion reitit.coercion.malli/coercion}
["/" {:get {:responses {200 [TestModel]}}
:post {:parameters {:body TestModel}
:responses {200 TestModel}}}]
[(str "/:id")
{:get {:parameters {:path [:id :int]}
:responses {200 TestModel}}
:patch {:parameters {:path [:id :int]
:body TestModel}
:responses {200 TestModel}}
:delete {:parameters {:path [:id :int]}
:responses {200 "OK"}}}]]])
Turn it into a router like so:
(def router (ring/router generated-api
{:validate rrs/validate
:compile coercion/compile-request-coercers}))
Now according to the docs, if I match on one of these paths I should get a coercer under the :result
key in the match but ... I don't.
(r/match-by-path router "/test-model/4")
{:template "/test-model/:id",
:data
{:coercion #Coercion{:name :malli},
:get
{:parameters {:path [:id :int]},
:responses {200 [:map [:id :int] [:name :string] [:cat? :boolean] [:datetime [:or :string :int]]]}},
:patch
{:parameters
{:path [:id :int], :body [:map [:id :int] [:name :string] [:cat? :boolean] [:datetime [:or :string :int]]]},
:responses {200 [:map [:id :int] [:name :string] [:cat? :boolean] [:datetime [:or :string :int]]]}},
:delete {:parameters {:path [:id :int]}, :responses {200 "OK"}}},
:result nil,
:path-params {:id "4"},
:path "/test-model/4"}
So calling coerce!
just returns nil
and I do not understand why.