This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-28
Channels
- # adventofcode (6)
- # beginners (61)
- # boot (1)
- # chestnut (1)
- # cider (18)
- # cljs-dev (1)
- # cljsrn (3)
- # clojure (176)
- # clojure-android (8)
- # clojure-germany (12)
- # clojure-russia (4)
- # clojure-spec (7)
- # clojure-uk (5)
- # clojurescript (28)
- # css (10)
- # cursive (36)
- # datomic (7)
- # devcards (1)
- # docs (8)
- # emacs (17)
- # fulcro (29)
- # hoplon (28)
- # lein-figwheel (3)
- # leiningen (37)
- # lumo (1)
- # off-topic (54)
- # om (6)
- # re-frame (2)
- # reitit (7)
- # ring-swagger (23)
- # shadow-cljs (115)
- # sql (10)
- # uncomplicate (1)
- # unrepl (24)
spec-validation of route data just landed on master! I believe this is actually useful: https://metosin.github.io/reitit/basics/route_data_validation.html
Always surprised that spec validates all fully-qualified keys from s/keys
specs even if they are not defined in the s/keys
. Despite being implicit, here it gives an easy way to extend the models. Just define you own qualified keys, enable spec validation and it works.
to enforce that the key should be present, one can re-define the :spec
for a router.
next up: add support for Middleware/Interceptor :spec
=> they can define their own requirements for a route. Effective spec for a route(data) is s/merge
of ’em all.
(s/def ::role #{:admin :user})
(s/def ::roles (s/and (s/coll-of ::role :into #{}) set?))
(def auth-mw
{:spec (s/keys :opt-un [::roles])
:wrap (fn [handler]
(fn [request]
(handler request)))}]}})
(ring/router
["/api" {:get {:handler identity
:middleware [auth-mw]
:roles #{:adminz}}}]
{:validate rrs/validate-spec!
::rs/explain e/expound-str})
; CompilerException clojure.lang.ExceptionInfo: Invalid route data:
;
; -- On route -----------------------
;
; "/api" :any
;
; -- Spec failed --------------------
;
; {:middleware ..., :handler ..., :roles #{:adminz}}
; ^^^^^^^
;
; should be one of: `:admin`,`:user`