This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-08
Channels
- # announcements (11)
- # babashka (13)
- # beginners (11)
- # biff (2)
- # calva (17)
- # cider (19)
- # clojure (60)
- # clojure-berlin (1)
- # clojure-dev (20)
- # clojure-europe (48)
- # clojure-nl (1)
- # clojure-norway (98)
- # clojure-spec (7)
- # clojure-uk (5)
- # core-typed (32)
- # cursive (13)
- # datomic (12)
- # dev-tooling (5)
- # emacs (7)
- # figwheel-main (2)
- # graalvm (4)
- # hyperfiddle (4)
- # introduce-yourself (1)
- # malli (14)
- # missionary (32)
- # off-topic (7)
- # overtone (4)
- # pedestal (10)
- # proletarian (4)
- # re-frame (8)
- # releases (11)
- # tools-build (1)
- # tools-deps (4)
- # xtdb (38)
I'm working on retroactively defining specs for Pedestal routes; mostly it's worked well, but I've hit my limit trying to spec a table route.
A table route looks like ["/" :get my-handler :route-name ::my-handler]
The first three parts are straight forward, bit there are these clauses (:route-name <keyword>) and (:constraints <map>) that can optionally follow the fixed part of the table route, in any order.
My initial pass:
(s/def ::table-route
(s/cat
:path ::path
:verb keyword? ;; This should be constrained based on options
:handler ::table-handler
:clauses (s/* ::table-route-clause)))
(s/def ::table-handler
(s/or
:symbol symbol?
:interceptor ::i/interceptor
:interceptors ::i/interceptors))
(s/def ::table-route-clause
(s/or
:route-name ::table-route-name-clause
:interceptors ::table-interceptors-clause))
(s/def ::table-route-name-clause
(s/cat :k #{:route-name}
:route-name ::route-name))
(s/def ::table-interceptors-clause
(s/cat :k #{:interceptors}
:interceptors ::i/interceptors))
But that isn't working, and I get:t
#{[... ... ... :route-name ...]
^^^^^^^^^^^
["/users/:id"
:get
[io.pedestal.http.route-test/view-user]
:route-name
:io.pedestal.http.route-test/view-user
:constraints
{:id #"\d+"}]}
should satisfy
(fn
[%]
(or (nil? %) (sequential? %)))
Any pointers here?(s/def ::table-route
(s/cat
:path ::path
:verb keyword? ;; This should be constrained based on options
:handler ::table-handler
:clauses (s/keys* :opt-un [::route-name ::constraints])))
(s/conform ::specs/table-route
["/users/:id" :get [`view-user] :route-name ::view-user :constraints {:id #"\d+"}])
=>
{:path "/users/:id",
:verb :get,
:handler [:interceptors [io.pedestal.http.route-test/view-user]],
:clauses {:route-name :io.pedestal.http.route-test/view-user, :constraints {:id #"\d+"}}}
1
I think maybe s/alt instead of s/or may also have been a better path
keys* is like "& args" - it allows any number at the end, not sure if that's what you want