This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-09
Channels
- # announcements (17)
- # babashka (8)
- # beginners (68)
- # calva (28)
- # clj-kondo (36)
- # cljsrn (1)
- # clojure (232)
- # clojure-dev (3)
- # clojure-europe (13)
- # clojure-nl (14)
- # clojure-spec (9)
- # clojure-uk (11)
- # clojuredesign-podcast (3)
- # clojurescript (38)
- # core-async (3)
- # cursive (1)
- # datahike (4)
- # datomic (4)
- # fulcro (56)
- # graphql (1)
- # helix (3)
- # honeysql (5)
- # introduce-yourself (1)
- # kaocha (2)
- # lsp (67)
- # malli (7)
- # meander (2)
- # off-topic (1)
- # pathom (9)
- # re-frame (55)
- # reitit (3)
- # releases (8)
- # remote-jobs (12)
- # shadow-cljs (12)
- # sql (3)
- # tools-deps (55)
- # vim (5)
- # xtdb (3)
Hello, I’ve got a question regarding the spec coercion. When I define a value of a parameter as a vector, it gets not coerced and remains a string, which is why there occurs an error when using the route. Let’s assume this spec:
(s/def ::reaction #{:attack :support :neutral})
and this as part of the ring/router
["/foo" {:post doesnt-matter-handler
:parameters {:body {:reaction ::reaction}}}]
When I then curl the route with "attack"
packed in a json request, I get a spec coercion error:
curl -X POST "" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"reaction\": \"attack\"}"
{
"spec": "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$46451/reaction]), :type :map, :leaf? false})",
"problems": [
{
"path": [
"reaction"
],
"pred": "#{:support :neutral :attack}",
"val": "attack",
"via": [
"spec$46451/reaction"
],
"in": [
"reaction"
]
}
],
"type": "reitit.coercion/request-coercion",
"coercion": "spec",
"value": {
"reaction": "attack"
},
"in": [
"request",
"body-params"
]
}
Also, when I post ":attack"
(prefixed with a :
), I get the same error. How can I achieve spec coercion to these three specified values defined in the spec ::reaction
? Thanks for your help 🙂