Fork me on GitHub
#luminus
<
2017-10-18
>
mmer12:10:08

Can anyone point me to a place where I can get a service to return JSON. I am using Swagger to expose the definition of the service an a return of String does not seem to work as I would expect - i.e. I want JSON to be returned and displayed in the swagger ui.

jumar13:10:02

@mmer how did you generate your luminus project? Luminus template usually creates middleware.clj which contains JSON marshalling stuff. All you need to return from your api is ring reponse ala {:status 200 :headers ... :body clojure-map}

mmer13:10:57

@jumar - lein new luminus proj-name +swagger +cljs +service +jetty - Sorry I can see where to put the text you kindly included

jumar13:10:10

Not sure If I understand your problem completely, but I'd say you need to return proper map instead of string

jumar13:10:38

afaik luminus uses muuntaja library which has application/json as a default format

ikitommi13:10:41

Muuntaja would be happy if you returned a JSON String and IF the response content-type is also set. But if you define a response schema for swagger, you need to return data in that format. By default, the response data is validated to conform the defined schema.

mmer16:10:39

I found I needed a schema - but I am now getting: { "errors": "(not (sequential? a-java.lang.String))" }

mmer16:10:50

Any ideas: My page set up is:

mmer16:10:35

(s/defschema Messages [{:?message s/Str}]) (defapi service-routes {:swagger {:ui "/swagger-ui" :spec "/swagger.json" :data {:info {:version "1.0.0" :title "Validator API" :description "Validates "}}}} (context "/api" [] :tags ["Validation"] (POST "/validate" [] :return Messages :body-params [server :- String, object :- String] :summary "Validates 'object' from 'server'" (-> (str (apply-rules server object)) ok (content-type "application/json")))

mmer16:10:09

I am not sure the middleware is not set correctly

ikitommi17:10:12

@mmer you apply-rules creates JSON manually? Just return a list of messages and it should work.