Fork me on GitHub
#ring-swagger
<
2016-03-22
>
trieloff11:03:23

Works perfectly, thank you.

trieloff11:03:23

Is there a good way to call get-spec in my own tests?

trieloff12:03:15

I am trying to generate swagger.json as a file as part of my build, so I can later on deploy it to AWS Gateway.

ikitommi12:03:53

you have to send a request to your app. Either to a hardcoded uri or find the swagger uri from the routing table

ikitommi12:03:51

so (app {:request-method :get, :uri "/swagger.json"}) or

ikitommi12:03:01

(compojure.api.routes/get-routes app) and find the uri for swagger endpoint

ikitommi12:03:28

hope this helps

ikitommi12:03:32

and you can slurp the response body to get the json

john.carnell16:03:39

He guys is there a to mark a Body on a POST as optional

john.carnell16:03:31

I have a situation where before we used swagger we would POST to an endpoint with no body.

john.carnell16:03:39

However we could post a body with optional content.

john.carnell16:03:10

Once we implemented ring-swagger we are getting an error message if we post without a body even if thebody is empty

ikitommi16:03:00

does it help if you wrap the body s/maybe? where do you get the errors from?

john.carnell16:03:20

Sure one minute

john.carnell16:03:16

hey ikitommi, where would I use s/maybe. Would I use it in the swagger definition

ikitommi17:03:07

are you writing the ring-swagger spec by hand? If so, this could work: ... {:parameters {:body (s/maybe {:a s/Str})}}

ikitommi17:03:31

if not, could you write an issue with example?

john.carnell17:03:31

Ill give it a shot

john.carnell17:03:46

if it doesnt work I will open an issue. Thanks again for the help

john.carnell18:03:47

That did not seem to help

john.carnell18:03:50

I will open a issue

john.carnell20:03:29

Hey ikitommi I will submit an issue, but I wrote a small piece of middleware in ring to get around the issue:

john.carnell20:03:30

(defn- is-post? [request] "Determines if the request coming in is a post" (if (= (:request-method request) :post) true false)) (defn- is-empty-post? [request http-body] "Determines whether a request is a post and has a blank body" (and (is-post? request) (blank? http-body))) (defn- handle-empty-body-for-swagger [handler] "Used to fix a bug in swagger where swagger will blow up if a post body is empty. The code below will check to see if the post is empty and then replace it with a empty {} body" (fn [request] (let [http-body (if (nil? (:body request)) "" (slurp (:body request))) ;Suck in the original Request Body. If there is not one then set the body to "" empty-body (merge request {:body (string-input-stream "{}")}) ;Create an empty body orig-body (merge request {:body (string-input-stream http-body)})] ;Maintain the original body in case we need it (if (is-empty-post? request http-body) (handler empty-body) (handler orig-body)))))