This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-05
Channels
- # architecture (23)
- # bangalore-clj (2)
- # beginners (93)
- # cider (27)
- # cljsjs (2)
- # clojure (66)
- # clojure-russia (9)
- # clojure-spec (28)
- # clojure-uk (3)
- # clojurescript (47)
- # cursive (2)
- # data-science (2)
- # datomic (10)
- # editors (9)
- # emacs (4)
- # figwheel (3)
- # figwheel-main (1)
- # hyperfiddle (2)
- # jobs (1)
- # nrepl (59)
- # off-topic (2)
- # onyx (10)
- # pedestal (1)
- # re-frame (13)
- # reagent (9)
- # reitit (17)
- # shadow-cljs (8)
- # tools-deps (4)
- # vim (2)
i have a request header param spec like this
(s/def ::authorization
(s/and string?
#(re-matches #"(?:Bearer|Basic) \S+" %)))
(def auth-header-opt
{:header (s/keys :opt-un [::authorization])})
which i then mount with
:parameters auth-header-opt
this works fine in general, but as soon as i turn on request coercion, it all blows up
In: [:parameters :header] val: #object[clojure.spec.alpha$map_spec_impl$reify__1931 0x68b11d5c "clojure.spec.alpha$map_spec_impl$reify__1931@68b11d5c"] fails spec: :reitit.core.coercion/kw-map at: [:parameters :header] predicate: map?
the header-params might need some middleware to read those under :header-params
for the coercion to pick them up (https://github.com/metosin/reitit/blob/master/modules/reitit-core/src/reitit/coercion.cljc#L41)
I think it would be better the coercion to read them directly from :headers
, but not implemented yet.
i thought that error implied that it has to be a map
and instead i gave it a spec (`s/keys`)
Oh, compojure-api just reads the params from [:request :headers]
, I'll fix that in the evening.
the route: https://github.com/valerauko/kitsune/blob/35d0a988ad6c9d5f6dbb65fc68a47135b5216b34/src/kitsune/routes/oauth.clj#L37-L46 the auth header specs: https://github.com/valerauko/kitsune/blob/35d0a988ad6c9d5f6dbb65fc68a47135b5216b34/src/kitsune/spec/oauth.clj#L32-L37 mounted at https://github.com/valerauko/kitsune/blob/develop/src/kitsune/routes/core.clj (coercion commented out because it won't compile with it on)
@vale so, it’s the route data spec that is too strict:
CompilerException clojure.lang.ExceptionInfo: Invalid route data:
-- On route -----------------------
"/token" :post
In: [:parameters :header] val: #object[clojure.spec.alpha$map_spec_impl$reify__1931 0x5c6d5145 "clojure.spec.alpha$map_spec_impl$reify__1931@5c6d5145"] fails spec: :reitit.core.coercion/kw-map at: [:parameters :header] predicate: map?
should be fixed in master: https://github.com/metosin/reitit/commit/af2d7922907beae572aee6ccc87e0ed01926ba39
will cut out a release next week, need to verify few things first. But you can fix it locally with:
(s/def :reitit.core.coercion/kw-map (s/or :map (s/map-of keyword? any?) :spec s/spec?))