This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-25
Channels
- # aleph (2)
- # announcements (7)
- # babashka (6)
- # beginners (53)
- # calva (17)
- # cider (5)
- # clj-kondo (137)
- # cljs-dev (19)
- # cljsrn (14)
- # clojure (74)
- # clojure-conj (9)
- # clojure-europe (13)
- # clojure-houston (1)
- # clojure-italy (16)
- # clojure-nl (21)
- # clojure-spec (3)
- # clojure-uk (9)
- # clojuredesign-podcast (24)
- # clojurescript (85)
- # cursive (11)
- # datomic (28)
- # duct (3)
- # emacs (6)
- # figwheel-main (1)
- # fulcro (68)
- # graalvm (19)
- # graphql (3)
- # joker (32)
- # kaocha (10)
- # lambdaisland (1)
- # malli (50)
- # off-topic (13)
- # other-languages (7)
- # pathom (2)
- # pedestal (14)
- # re-frame (53)
- # reitit (8)
- # shadow-cljs (57)
- # specter (2)
Can anybody help we with a problem getting spec coercion working with ring? I've missed something. Following https://github.com/metosin/reitit/blob/master/doc/ring/coercion.md,
• I've added a :middleware
key to the options map passed to reitit.ring/ring-handler
with the coercion middleware from reitit.ring.coercion
• I've added a spec for the path param in my route (`::invitation-id` is a spec for a uuid, I got this from https://github.com/metosin/reitit/blob/master/doc/coercion/clojure_spec_coercion.md)
• I've also specified a :coercion
key at the top of my routes.
(s/def ::invitation-id ::invite/id)
(defn app
[]
(rr/ring-handler
(rr/router
["" {:coercion rspec/coercion}
["/invitations"
["/:invitation-id" {:parameters {:path (s/keys :req-un [::invitation-id])}
:delete delete-invite}]]])
(rr/create-default-handler)
{:middleware [rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware
rrc/coerce-response-middleware]}))
The :parameters
map in my request remains empty. I've seen examples where the router has an options map with a :data
key that contains the coercion type and middleware (https://github.com/metosin/reitit/blob/master/examples/ring-spec-swagger/src/example/server.clj). I think I must have put something in the wrong place?maybe this middleware should be passed to the router options instead of the ring-handler options? the ring-handler
function is destructuring a key called :middleware
from its options though
@conan you should put the coercion mw inside the router. Either under [:data :middleware]
on router opts (gets merged to all routes) or to route data.