Fork me on GitHub
#reitit
<
2018-08-05
>
valerauko13:08:01

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

valerauko13:08:19

this works fine in general, but as soon as i turn on request coercion, it all blows up

valerauko13:08:10

In: [:parameters :header] val: #object[clojure.spec.alpha$map_spec_impl$reify__1931 0x68b11d5c "[email protected]"] fails spec: :reitit.core.coercion/kw-map at: [:parameters :header] predicate: map?

ikitommi13:08:19

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)

ikitommi13:08:47

I think it would be better the coercion to read them directly from :headers, but not implemented yet.

valerauko13:08:59

i thought that error implied that it has to be a map and instead i gave it a spec (`s/keys`)

ikitommi13:08:23

I think the error is that there is no data in [:request :header-params].

ikitommi13:08:03

Oh, compojure-api just reads the params from [:request :headers], I'll fix that in the evening.

valerauko13:08:16

it's dying at compile-time, not on request

ikitommi13:08:31

oh. could you make a minimalistic sample, I'll check that out when at computer

ikitommi19:08:38

@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 "[email protected]"] fails spec: :reitit.core.coercion/kw-map at: [:parameters :header] predicate: map?

ikitommi19:08:02

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?))

ikitommi19:08:39

thanks to the mutable core of clojure.spec….

ikitommi20:08:52

fixed also the source for the :header-params, now read directly from :headers, not :header-params.

ikitommi20:08:41

… both changes now in the [metosin/reitit "0.2.0-SNAPSHOT"] if you have time to test.