Fork me on GitHub
#reitit
<
2019-05-12
>
joshkh11:05:58

i have a route in which path parameters are coercing to UUIDs just fine, but the optional query parameters aren't. any ideas? 🙂

(defonce router (rf/router routes {:data {:coercion reitit.coercion.spec/coercion}}))

(def routes
  ; apply Spec coercion to all routes
  ["/" {:coercion reitit.coercion.spec/coercion}
   ["clothes" {:name :route/clothes}
    ["/{catalogue/uuid}" {:name        :route/catalogue
                          :parameters  {
                                        ; works like a charm 
                                        :path  {:catalogue/uuid uuid?}
                                        ; this definitely checks that :p is a uuid but i get a string
                                        ; in the controller
                                        :query {(ds/opt :p) uuid?}}
                          :controllers [{:identity identity
                                         :start    (fn [match]
                                                     ; but it comes out as a string in the match
                                                     (js/console.log "is UUID" (-> match :path-params :catalogue/uuid type))
                                                     (js/console.log "is String" (-> match :query-params :p type)))}]}]]])

joshkh11:05:05

ah! i should be looking in the match's :parameters key, not :query-params

👍 1
deva23:05:30

@ikitommi Response coercion middleware coercion/coerce-response-middleware is taking forever, is that normal ?