This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-09
Channels
#reitit2021-07-09
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 🙂