This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-22
Channels
- # beginners (24)
- # boot (80)
- # braid-chat (11)
- # cider (89)
- # clara (11)
- # cljsfiddle (5)
- # cljsjs (9)
- # cljsrn (63)
- # clojure (114)
- # clojure-austin (1)
- # clojure-berlin (5)
- # clojure-brasil (4)
- # clojure-dusseldorf (5)
- # clojure-hamburg (17)
- # clojure-india (1)
- # clojure-new-zealand (3)
- # clojure-poland (1)
- # clojure-russia (91)
- # clojure-taiwan (1)
- # clojure-uk (54)
- # clojurebridge (3)
- # clojurescript (170)
- # core-matrix (1)
- # cursive (14)
- # datomic (8)
- # emacs (13)
- # hoplon (96)
- # immutant (20)
- # jobs (9)
- # jobs-rus (13)
- # kosmos (3)
- # off-topic (8)
- # om (111)
- # onyx (41)
- # parinfer (116)
- # pedestal (2)
- # proton (4)
- # re-frame (46)
- # reagent (7)
- # ring-swagger (24)
- # slack-help (2)
- # testing (1)
- # untangled (8)
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.
you have to send a request to your app. Either to a hardcoded uri or find the swagger uri from the routing table
He guys is there a to mark a Body on a POST as optional
I have a situation where before we used swagger we would POST to an endpoint with no body.
However we could post a body with optional content.
Once we implemented ring-swagger we are getting an error message if we post without a body even if thebody is empty
Sure one minute
hey ikitommi, where would I use s/maybe. Would I use it in the swagger definition
are you writing the ring-swagger spec by hand? If so, this could work: ... {:parameters {:body (s/maybe {:a s/Str})}}
Ill give it a shot
if it doesnt work I will open an issue. Thanks again for the help
That did not seem to help
I will open a issue
Hey ikitommi I will submit an issue, but I wrote a small piece of middleware in ring to get around the issue:
(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)))))