Fork me on GitHub

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


code looks right, should work imo.


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


Are you running custom schema-validation somewhere else?


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"


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


I think it's +swagger


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.


good to hear!


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.