This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-22
Channels
- # announcements (2)
- # architecture (33)
- # babashka (4)
- # beginners (445)
- # bristol-clojurians (10)
- # calva (23)
- # cider (43)
- # clj-kondo (36)
- # cljs-dev (13)
- # cljsrn (20)
- # clojure (136)
- # clojure-argentina (8)
- # clojure-dev (1)
- # clojure-europe (18)
- # clojure-germany (1)
- # clojure-italy (5)
- # clojure-nl (45)
- # clojure-spec (66)
- # clojure-uk (29)
- # clojurescript (69)
- # conjure (157)
- # cursive (2)
- # datomic (216)
- # emacs (10)
- # exercism (4)
- # figwheel-main (8)
- # fulcro (30)
- # graphql (21)
- # hoplon (5)
- # kaocha (7)
- # leiningen (3)
- # luminus (4)
- # music (1)
- # off-topic (24)
- # pathom (10)
- # re-frame (19)
- # reagent (11)
- # reitit (16)
- # remote-jobs (1)
- # ring-swagger (5)
- # rum (7)
- # shadow-cljs (125)
- # spacemacs (8)
- # sql (9)
- # tools-deps (12)
Can anyone point me in the right direction for coercing a request parameter that has the inst?
spec attached? We’re using json-transformer
and the payload is JSON
Do you have the middleware and coercion in the route data? Then I think you just need to have the request header content-type to "application/json"?
yes, it should just work if you have the coercion configured on. examples
have good starting point with the needed mw configuration (and to test stuff)
hello all. Can't seem to find in the documentation how to declare optional
query parameters by default all parameters are defined as required
{:swagger {:tags ["path"]}
:get {:summary "Forward Path Search"
:parameters {:query {:src string? :dst string? :network string?}
}
:handler (fn [{{{:keys [src dst network]} :query} :parameters}]
(path/path-search-handler src dst network))
}}
I'm trying to learn spec myself as well, it may not be the best solution.
Assuming src
and dst
are required, and network
as optional.
(s/def ::src string?)
(s/def ::dst string?)
(s/def ::network string?)
# Then define parameters as
{:parameters {:query (s/keys :req-un [::src ::dst] :opt-un [::network])}
EDIT:
s
here is
[clojure.spec.alpha :as s]
ahh that worked
"in": "query",
"name": "network",
"description": "",
"type": "string",
"required": false
thanks
you can also use ds/opt
if you use the data-spec syntax, see https://cljdoc.org/d/metosin/spec-tools/CURRENT/doc/data-specs
a doc PR would be awesome to have an example of optional parameter, in both ways. Would anyone have time for that?
@U055NJ5CC I'll review the docs, and see if I can contribute an example. Just for clarification, what do you mean by "in both ways"?
looking forward! with both way, I mean - using data-specs and normal spec1 keys
syntax for optional keys