Fork me on GitHub
#reitit
<
2020-05-07
>
markbastian21:05:40

Anyone know how to configure swagger to be able to specify the request accept headers? I've got the following:

(s/def ::mime-types #{"application/json" "text/csv" "text/xml" "text/html"})

(def routes
  ["/foo"
   {:swagger {:tags ["foo"]}}
   ["/get" {:get {:summary    "get some foo"
                  :parameters {:query  {:id string?}
                               :header {:accept ::mime-types}}
                  :handler    handler}}]])
Everything works, including a nice dropdown with my mime types, but then when I invoke the request I get a spec error:
;Part of the problems section:
  "pred": "#{\"text/html\" \"application/json\" \"text/xml\" \"text/csv\"}",
  "val": "application/json, text/html",
It looks like the application is appending my choice onto the accept header rather than just using my choice. Is there an easy way to replace the value rather than appending? Thanks!

markbastian22:05:12

Ok, looks like you can't specify the accept header directly. This is how you do it if anyone is interested:

(def routes
  ["/foo"
   {:swagger {:tags ["foo"]}}
   ["/get" {:get {:summary    "get some foo"
                  :swagger    {:produces ["application/json" "text/csv" "text/xml" "text/html"]}
                  :parameters {:query  {:id string?}}
                  :responses  {200 {:body [{}]}}
                  :handler    handler}}]])

markbastian17:05:23

Realized I'm doing it all wrong and should just use Muuntaja.