This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-18
Channels
- # aws (1)
- # aws-lambda (1)
- # beginners (48)
- # boot (15)
- # cider (3)
- # cljs-dev (4)
- # cljsrn (4)
- # clojure (241)
- # clojure-chicago (1)
- # clojure-dusseldorf (12)
- # clojure-greece (41)
- # clojure-italy (3)
- # clojure-russia (16)
- # clojure-spec (7)
- # clojure-uk (34)
- # clojurescript (88)
- # community-development (9)
- # cursive (8)
- # data-science (55)
- # datomic (40)
- # devops (1)
- # emacs (20)
- # fulcro (19)
- # graphql (3)
- # hoplon (46)
- # luminus (11)
- # lumo (4)
- # off-topic (27)
- # onyx (26)
- # other-languages (25)
- # pedestal (2)
- # powderkeg (6)
- # re-frame (11)
- # reagent (4)
- # ring-swagger (17)
- # rum (4)
- # shadow-cljs (103)
- # spacemacs (14)
- # specter (6)
- # unrepl (21)
- # yada (1)
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.
@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}
@jumar - lein new luminus proj-name +swagger +cljs +service +jetty - Sorry I can see where to put the text you kindly included
Not sure If I understand your problem completely, but I'd say you need to return proper map instead of string
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.
I found I needed a schema - but I am now getting: { "errors": "(not (sequential? a-java.lang.String))" }
(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")))