This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-19
Channels
- # admin-announcements (2)
- # beginners (25)
- # boot (93)
- # cider (2)
- # clara (2)
- # cljs-dev (63)
- # cljsjs (3)
- # cljsrn (38)
- # clojure (142)
- # clojure-austin (1)
- # clojure-brasil (2)
- # clojure-czech (1)
- # clojure-dev (7)
- # clojure-greece (1)
- # clojure-russia (170)
- # clojure-spec (11)
- # clojure-uk (65)
- # clojurescript (46)
- # clojurex (1)
- # code-reviews (3)
- # cursive (11)
- # datomic (35)
- # euroclojure (6)
- # events (2)
- # flambo (2)
- # hoplon (115)
- # instaparse (11)
- # jobs (21)
- # jobs-rus (3)
- # lambdaisland (2)
- # off-topic (17)
- # om (35)
- # onyx (161)
- # planck (1)
- # protorepl (7)
- # random (1)
- # re-frame (31)
- # reagent (19)
- # ring-swagger (21)
- # rum (5)
- # spacemacs (3)
- # specter (25)
- # test-check (20)
- # testing (7)
- # untangled (2)
- # yada (50)
I just posted this in the main clojure channel and was referred here. I'm trying to use compojure-api to auto-generate documentation for an api I'm building, and it works as long as the endpoint doesn't have a :return. However, if it does, the response fails any validation I give it with (not ({whatever predicate} a-java.io.BufferedInputStream)). I've since found that ring defaults to sending an inputstream as the body of a response. I can get a string instead of an inputstream, but I'm trying to return a map which is converted into a json object. Deraen said I may be bumping into a duplicate middleware, but I haven't been able to find which one is causing this behavior.
The code triggering this behavior is (POST "/login" [] |~ 3 :return {:token String} |~ 2 :body-params [username :- s/Str password :- s/Str] |~ 1 :summary "Returns an authentication token." |~ 0 (ok {:token "token"}))
the problem is not on the route code, it is somewhere else
... but c-api does only validation on the endpoints themselves. Is that htto 400 or 500?
No, I'm completely new to clojure web development and was just trying to integrate compojure-api into an otherwise vanilla luminus project
did you generate the project using luminus template's compojure-api options?
no, I didn't. I'm trying to integrate it after the fact
the default version includes middlewares which will clash with compojure-api
wrap-formats
specifically
I tried unwrapping that when you said something about duplicate middleware on the other channel, the error changes to "Cannot JSON encode object of class: class java.io.BufferedInputStream: java.io.BufferedInputStream"
btw, we are about to replace the ring-middleware-format
with new a lib we have been developing. Much faster, supports async, and can be double-chained without problems. Coming out within few weeks.
I generated a new project with the swagger options. wrap-formats is identical in each, so the problem doesn't look to be there, but the new one does work if I replace one of the examples in services.clj to return a map.
so now I'm just trying to figure out what on earth is different between this example and my current project
I found the problem. I was trying to nest defapi calls like defroutes. Things work fine if the defapi contains a collection of routes instead of apis. Thank you both for all the help.