This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-28
Channels
- # announcements (1)
- # babashka (9)
- # beginners (82)
- # calva (6)
- # cider (3)
- # clj-kondo (69)
- # cljdoc (4)
- # cljs-dev (10)
- # cljsrn (2)
- # clojure (74)
- # clojure-europe (11)
- # clojure-italy (9)
- # clojure-nl (15)
- # clojure-spec (18)
- # clojure-uk (89)
- # code-reviews (8)
- # core-async (42)
- # cursive (22)
- # datomic (26)
- # fulcro (13)
- # graalvm (33)
- # graphql (1)
- # leiningen (20)
- # malli (19)
- # music (1)
- # off-topic (4)
- # pathom (56)
- # re-frame (3)
- # reitit (26)
- # shadow-cljs (40)
- # spacemacs (5)
- # tools-deps (25)
So continuing with coersions problems. Im going through an example in the book "Web Development with Clojure" that seems to fail with a coersion error as well. The thing is it looks good to me so i dont understand where the error is. Im asuming i need to be specific and spec the params as a map-of but i tried that and it did not work for me
{:post {:parameters
{:body
{:login string?
:password string?}}
:responses
{200
{:body
{:identity
{:login string?
:created_at inst?}}}
401
{:body
{:message string?}}}
:handler
(fn [{{{:keys [login password]} :body} :parameters
session :session}]
(if-some [user (auth/authenticate-user login password)]
(->
(response/ok
{:identity user})
(assoc :session (assoc session
:identity
user)))
So its my understanding from what i read here https://metosin.github.io/reitit/coercion/clojure_spec_coercion.html that simple structure should just work. meaning :identity {:login :created_at}
should just work
{
"spec": "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$39136/identity]), :type :map, :leaf? false})",
"problems": [],
"type": "reitit.coercion/response-coercion",
"coercion": "spec",
"value": {
"identity": {
"login": "testuser",
"created_at": "2019-11-28T08:55:33.9774"
}
},
"in": [
"response",
"body"
]
}
@vale you can override how things get printed extending the print-method
multimethod, example here: https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L29-L30
@jstuartmilne glad you got it sorted out. Where is the example of "web development with Clojure"?