Fork me on GitHub
#reitit
<
2021-04-26
>
An Li01:04:32

How could I add swagger parameter description to :parameters :query?

"parameters":[{"in":"query","name":"street","description":"","type":"string","required":true},{"in":"query","name":"city","description":"","type":"string","required":true,"enum":["tre","hki"]}
(s/def ::city #{:tre :hki})
(s/def ::address (s/keys :req-un [::street ::city]))

 ["/test"
    {:get {:parameters {:query ::address}
           :handler (fn [] (constantly (ok)))}}]

cjsauer21:04:06

Hello 👋 , I’m new to reitit and have a basic question: how does one integrate format negotiation with request coercion? They seem to be at odds with one another. For example, say I have a PUT endpoint that can accept both application/json in the body, or x-www-form-urlencoded . How does one specify this in the :parameters map so that coercion is applied correctly in both cases? https://cljdoc.org/d/metosin/reitit/0.5.12/doc/ring/pluggable-coercion, the :parameters map forces you to know a priori where the incoming payload is located, e.g. in the :body, or in the :form , etc

jacekschae05:04:58

You would need to specify coercion in both places, here is a small example

:put    {:handler    ...
         :middleware ...
         :parameters {:path {:recipe-id string?}
                      :body {:name string? :prep-time number? :public boolean? :img string?}}
         :responses  ...}
         :summary    "Update recipe"}
The coercion is done with coercion spec. Hope it helps

cjsauer12:04:18

Thanks for the reply. So I think :path and :body parameter sources work fine together as in your example, but it’s specifically :form and :body that appear incompatible. They both source from the body of the request, but with a different assumed encoding.