Fork me on GitHub
#reitit
<
2019-01-09
>
kvlt18:01:39

Hey Friends, I'm trying to use reitit's spec funcationality I have something like the following:

(s/def ::display-name string?)
(s/def ::request
  (s/keys :opt-un [::display-name]))

["/groups/:uuid" {:coercion rcs/coercion
                  :name ::groups-by-uuid
                  :middleware [middleware/wrap-internal-error
                               middleware/wrap-formats
                               middleware/wrap-base]
                  :patch {:parameters {:params ::request}
                          :handler (fn [{:keys [path-params session params] :as req}]
                                     (prn "*&^*&^" params)
                                     {:status 200
                                      :body {:total 99}})}}]
However, it doesnt' appear to be applying the spec to my params

kvlt18:01:46

Is it obvious as to what I'm missing? I've seen in the examples https://github.com/metosin/reitit/blob/master/examples/ring-example/src/example/spec.clj that they appear to be using hte body keyword, but I don't see any data inside of (:parameters req)

ikitommi18:01:05

@petr hi. I think you don't have the coercion middleware mounted. The :parameters and :responses are just data and don't do anything by themselves. See https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj for a commented chain of mw.

ikitommi19:01:13

Goal is to enable making the route data validator strict, so here it would complain about extra keys in route data. Cases likes this would fail-fast.

ikitommi19:01:41

btw, working on perf, next iteration of segment-router will be Really Fast.

ikitommi19:01:16

@petr oh, you should define what type of parameters you want to define, the guide is https://metosin.github.io/reitit/ring/coercion.html. hope this helps

kvlt19:01:00

@ikitommi I'll take a look at this. Thank you

kvlt21:01:15

@ikitommi I'm still a little confused - I have added all of the middleware in that example, params is now present but it is always empty. I'm not so much interested in coercion, but more so in running spec validations on the data

kvlt21:01:37

I did also define the coercion, in the route though: as such : {:coercion rcs/coercion... }