Fork me on GitHub
#ring-swagger
<
2016-08-19
>
dkuykendall14:08:38

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.

dkuykendall14:08:26

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"}))

juhoteperi14:08:41

the problem is not on the route code, it is somewhere else

ikitommi14:08:28

code looks right, should work imo.

ikitommi14:08:48

... but c-api does only validation on the endpoints themselves. Is that htto 400 or 500?

ikitommi14:08:39

Are you running custom schema-validation somewhere else?

dkuykendall14:08:37

No, I'm completely new to clojure web development and was just trying to integrate compojure-api into an otherwise vanilla luminus project

juhoteperi14:08:36

did you generate the project using luminus template's compojure-api options?

dkuykendall14:08:09

no, I didn't. I'm trying to integrate it after the fact

juhoteperi14:08:13

the default version includes middlewares which will clash with compojure-api

juhoteperi14:08:33

wrap-formats specifically

dkuykendall14:08:56

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"

ikitommi14:08:07

hmm.. could you recreate a project with the compojure-api options?

ikitommi14:08:22

I think it's +swagger

ikitommi14:08:07

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.

dkuykendall14:08:44

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.

ikitommi14:08:50

good to hear!

dkuykendall15:08:11

so now I'm just trying to figure out what on earth is different between this example and my current project

dkuykendall15:08:49

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.