Fork me on GitHub
#reitit
<
2019-10-26
>
y.khmelevskii10:10:05

Hi everybody. I generated swagger with help of reitit. Usually body params it’s json but for some routes it should be just text/html. So, I don’t understand how I change expected content type of payload for route.I tried to do something like this:

:headers      {"Content-Type" "text/html"}
          :parameters {:query {:test string?}
                       :body  string?}
but it doesn’t work. In swagger UI I always can see Parameter content type: application/json

y.khmelevskii10:10:29

I use the following interceptors

(muuntaja/format-negotiate-interceptor)
   (muuntaja/format-response-interceptor)
   (muuntaja/format-request-interceptor)
   (coercion/coerce-response-interceptor)
   (coercion/coerce-request-interceptor)

ikitommi10:10:58

@y.khmelevskii if you just need to hint the swagger-ui, you can put :swagger {:produces ["text/plain"]} into route data. All data under :swagger is merged to the swagger spec.

ikitommi10:10:07

for the actual endpoint, add :headers {"Content-Type" "text/html"} to the response map

y.khmelevskii10:10:19

thank you @ikitommi! I need to set content type for request body, not response. But it’s work

:data   {:swagger      {:consumes ["application/json" "text/plain"]}
...
if you can suggest how I can do it for the actual endpoint, it would be great.

ikitommi11:10:15

you could add a new format to Muuntaja (see https://cljdoc.org/d/metosin/muuntaja/0.6.5/doc/creating-new-formats) for text/plain or just remove the body parameter requirement and parse the request body in an handler or middleware yourself. You should be able to slurp the body and get the string out.

y.khmelevskii11:10:58

I see, thank you. Going to read muunaja doc