Open andrewsuzuki opened 4 years ago
Good catch. having a middleware effecting all routes, all defined methods should have the :roles
defined. Reitit creates an :options
route for all routes and it doesn't have the :roles defined.
Good question is, should the generated :options
be validated just like all other endpoints?
the compiled routes for the given app:
(-> ["/api" {:get {:handler identity
:roles #{:admin}}}]
(ring/router)
(r/compiled-routes))
;[["/api"
; {:get {:handler #object[clojure.core$identity], :roles #{:admin}}}
; #Methods{:get #Endpoint{:data {:handler #object[clojure.core$identity],
; :roles #{:admin}},
; :handler #object[clojure.core$identity],
; :path "/api",
; :method :get,
; :middleware []},
; :head nil,
; :post nil,
; :put nil,
; :delete nil,
; :connect nil,
; :options #Endpoint{:data {:no-doc true,
; :handler #object[reitit.ring$fn__4208$fn__4217]},
; :handler #object[reitit.ring$fn__4208$fn__4217],
; :path "/api",
; :method :options,
; :middleware []},
; :trace nil,
; :patch nil}]]
Reference test
If I turn
:opt-un
into:req-un
(as the docs use), the spec fails ("should contain key :roles").It works fine however if
:roles
is placed in any parent map.