This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-10
Channels
- # aleph (3)
- # architecture (3)
- # bangalore-clj (5)
- # beginners (75)
- # boot (75)
- # cider (2)
- # cljs-dev (48)
- # cljsjs (3)
- # cljsrn (17)
- # clojure (125)
- # clojure-belgium (1)
- # clojure-boston (1)
- # clojure-italy (20)
- # clojure-losangeles (2)
- # clojure-spec (73)
- # clojure-uk (34)
- # clojurescript (127)
- # cursive (8)
- # data-science (5)
- # datascript (128)
- # datomic (5)
- # emacs (4)
- # events (3)
- # fulcro (1)
- # jobs (1)
- # jobs-discuss (4)
- # jobs-rus (9)
- # keechma (79)
- # lein-figwheel (2)
- # leiningen (2)
- # lumo (31)
- # om (1)
- # parinfer (61)
- # pedestal (1)
- # planck (1)
- # portkey (31)
- # re-frame (34)
- # reagent (53)
- # ring (3)
- # ring-swagger (13)
- # rum (1)
- # spacemacs (14)
- # testing (1)
- # yada (2)
I’m getting an error with spec conforming my input. When I extract the input and conform it manually, the spec reports no errors. When conformed through the API, I get errors. This is the spec:
(s/def ::input-settings (s/and (s/keys :req-un [::endpoint
::customer-id
::requestor-id]
:opt-un [::from-year
::from-month
::to-year
::to-month
::requestor-email
::requestor-name])
date/validate-to-date
date/validate-from-date
date/validate-both-dates))
The keys are spec’d to be strings or ints. The “validate” functions all return true
when the optional keys are not present.
This is the input, capture before validation:
{"endpoint" "",
"customer-id" "abc",
"requestor-id" "abc",
:customer-id "abc",
:endpoint "",
:requestor-id "abc"}
This is the error:
{
"spec": "(spec-tools.core/spec {:spec (clojure.spec.alpha/and (clojure.spec.alpha/keys :req-un [:futomaki.api.handler/endpoint :futomaki.api.handler/customer-id :futomaki.api.handler/requestor-id] :opt-un [:futomaki.api.handler/from-year :futomaki.api.handler/from-month :futomaki.api.handler/to-year :futomaki.api.handler/to-month :futomaki.api.handler/requestor-email :futomaki.api.handler/requestor-name]) futomaki.date/validate-to-date futomaki.date/validate-from-date futomaki.date/validate-both-dates), :type :map})",
"problems": [
{
"path": [],
"pred": [
"clojure.spec.alpha/and",
[
"clojure.spec.alpha/keys",
"req-un",
[
"futomaki.api.handler/endpoint",
"futomaki.api.handler/customer-id",
"futomaki.api.handler/requestor-id"
],
"opt-un",
[
"futomaki.api.handler/from-year",
"futomaki.api.handler/from-month",
"futomaki.api.handler/to-year",
"futomaki.api.handler/to-month",
"futomaki.api.handler/requestor-email",
"futomaki.api.handler/requestor-name"
]
],
"futomaki.date/validate-to-date",
"futomaki.date/validate-from-date",
"futomaki.date/validate-both-dates"
],
"val": {
"endpoint": "",
"customer-id": "abc",
"requestor-id": "abc"
},
"via": [
"futomaki.api.handler/input-settings"
],
"in": []
}
],
"type": "compojure.api.exception/request-validation",
"coercion": "spec",
"value": {
"endpoint": "",
"customer-id": "abc",
"requestor-id": "abc"
},
"in": [
"request",
"query-params"
]
}
`It’s not parsing it further down than s/and
, so I guess it figures that the entire form is false? But how come it conforms when I run it manually?
So, this spec also fails:
(s/def ::input-settings (s/and (s/keys :req-un [::endpoint
::customer-id
::requestor-id]
:opt-un [::from-year
::from-month
::to-year
::to-month
::requestor-email
::requestor-name])))
This spec works:
(s/def ::input-settings (s/keys :req-un [::endpoint
::customer-id
::requestor-id]
:opt-un [::from-year
::from-month
::to-year
::to-month
::requestor-email
::requestor-name]))
@henrik Sounds odd, have to dig into that. Could you write an issue to Github? might have time later today.
:body s/Any
Or no :body
or :body-params
empty :body-params
says that the endpoint doesn't take any params