Fork me on GitHub
#ring-swagger
<
2018-10-23
>
petr.mensik13:10:32

How come that this handler is returning body as ByteArrayInputStream instead of plain JSON?

(defroutes users
  (context "/bizzi-test/users" []
    (GET "/" []
      :summary "Gets all users"
      (ok {:message "Get all users"}))))

(def handler
              (api {:swagger
                    {:ui "/docs"
                     :spec "/swagger.json"
                     :data {:info {:title "Bizziapp REST API documentation"
                                   :description "Documentation which describes all REST endpoints provided by Bizziapp"}
                            :produces ["application/json"]
                            :consumes ["application/json"]}}}
                   users
                   (undocumented (route/not-found (not-found {:message "This route had not been found"})))))
I tested it with a ring-mock (handler (mock/request :get "/users")) . Thanks for answer 🙂

ikitommi20:10:53

@petr.mensik c-api uses Muuntaja under the hoods, which return InputStreams by default (can be changed to return byte-arrays or lazy streams instead). You can slurp the body to get the string value.

petr.mensik20:10:05

@ikitommi thanks a lot 🙂 Btw is there an easy way how to generate swagger.json file out of the API docs described with Schema (let's from the code above) ? I am going through ring-swagger and I cannot find any obvious answers there 😕