This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-22
Channels
- # 100-days-of-code (1)
- # beginners (51)
- # carry (1)
- # cider (10)
- # clojure (71)
- # clojure-conj (4)
- # clojure-dev (9)
- # clojure-italy (3)
- # clojure-nl (2)
- # clojure-russia (8)
- # clojure-uk (16)
- # clojurescript (42)
- # cursive (4)
- # datomic (2)
- # emacs (8)
- # figwheel-main (7)
- # fulcro (20)
- # hyperfiddle (5)
- # jobs (2)
- # off-topic (16)
- # om-next (4)
- # onyx (9)
- # powderkeg (1)
- # re-frame (8)
- # reagent (17)
- # reitit (41)
- # robots (6)
- # rum (1)
- # shadow-cljs (54)
- # testing (3)
- # tools-deps (19)
not sure if i've asked this before...
how to do query-params properly? currently, while path and body params are key-indexed, query params are string indexed. also, they don't seem to get type-cast: i have a param specced as pos-int?
but it still comes through as a string
am i missing some setting or something somewhere?
actually my problem still stands: i'm coercing my query params like
(s/def ::page pos-int?)
;; ...
{:query (s/keys :opt-un [::page])}
this fails every request with the page set to anything because it's passed as a string, not as a number. how can this be resolved?@vale all coercible specs need to be wrapped, the two ways to do it:
1) use data-spec syntax: {:query {:page pos-int?}}
, it just works
2) wrap it manually:
(s/def ::page (spec-tools.core/spec pos-int?))
;; or
(s/def ::page spec-tools.spec/pos-int?)
(I think we could merge the spec-tools & spec-coerce approaches and make all the simple specs to coerce without any wrapping too)
In: [:parameters :query #spec_tools.data_spec.OptionalKey{:k :page} 0] val: #spec_tools.data_spec.OptionalKey{:k :page} fails spec: :reitit.core.coercion/kw-map at: [:parameters :query :map 0] predicate: keyword?
i tried the ds/opt way but it seems to fail its own spec? am i missing something?yeah like
{:get {:summary "List of accounts following the user"
:responses {200 {:body any?}}
:parameters {:query (ds/spec ::opt-page {(ds/opt :page) pos-int?})}
:handler user/followers}}]]]
maps are turned into data-specs automatically: https://github.com/metosin/reitit/blob/master/modules/reitit-spec/src/reitit/coercion/spec.cljc#L46-L54
https://metosin.github.io/reitit/basics/name_based_routing.html found what i was looking for~
routers are effectively immutable once created. compiled-routes
can be used for extensions, for example the swagger docs are created from those. We'll mark on changelog if the interals change for some reason.
currently, there is no validation, but one could do that using the route data and reitit.coercion
. maybe there should be a helper for it?