Fork me on GitHub
#ring-swagger
<
2016-12-22
>
singen09:12:40

I’m not interested in async everything and the parts that need it are already async, so that sounds good to me

petr.mensik14:12:45

Hello, I have encountered weird problem during testing, all responses from Peridot (HTTP mock lib based on ring-mock) are returned as java.io.ByteArrayInputStream. I have pretty much standard set up - with my app looking like this

(defapi app {:format [:json-kw :transit-json]
                     :swagger swagger-config} ; copypasta from tutorial
   (middleware [mk-defaults]) ; XSS protection I am using in other projects
  print-routes)
And the mocking part of the test is
(-> (session app)
       (request "/fingerprint/api/register"
                :request-method :post
                :content-type "application/json"
                :headers {"Accept" "application/json"} ; error is the same even without this header
                :body body)
       (:response)))
Strange thing here is that both request and response parts handle the body as InputStream and not as JSON.

petr.mensik14:12:33

The very same thing works for me on other projects based just on Compojure/Luminus so I am not sure where could be a problem (and I am slowly getting desperate here)

petr.mensik14:12:39

btw it returns correct body when I call it from Swagger doc page (and generated curl command works as well)

metametadata19:12:20

@petr.mensik response body can be a stream, use (slurp body) to convert it into a string see Ring spec: https://github.com/ring-clojure/ring/blob/1d137e8b52b0c7ec81559199054e3d6e56128fb2/SPEC#L123

petr.mensik19:12:16

@metametadata got it but why is the result different when using plain curl?

ikitommi19:12:22

@petr.mensik the response should be the same, just packaged into a stream by ring-middleware-format. Ring-adapter can write both streams of string into the response stream and they look the same when viewed over http.

ikitommi19:12:49

so, slurp should give the json to you.

petr.mensik19:12:45

anyway, slurp works so thanks a lot 🙂