Fork me on GitHub
#reitit
<
2019-06-21
>
mitchelkuijpers09:06:43

Is it possible to set a maximum number with schema-tools and swagger support?

vlad_poh14:06:55

Howdy fam! how do i add http header to the following

["/upload"
         {:post {:summary "upload a file"
                 :parameters {:multipart {:file multipart/temp-file-part}}
                 :responses {200 {:body {:name string?, :size int?}}}
                 :handler (fn [{{{:keys [file]} :multipart} :parameters}]
                            {:status 200
                             :body {:name (:filename file)
                                    :size (:size file)}})}}]

vlad_poh15:06:23

when i try :parameters

{:header "custom-header" "custom-value"}
I get spec errors like
Request coercion failed: #reitit.coercion.CoercionError{:spec #Spec{:form (clojure.spec.alpha/keys :req-un [:spec$2980/custom-header])

manutter5115:06:37

I think if it were me I’d make the handler fn take the request object directly, and then pull out the parts that I wanted. The :headers key is in the request at the same level as the :parameters key so if you do what to do destructuring, I think it would have to look something like this

(fn [{{{:keys [file]} :multipart} :parameters
      {custom-value "custom-header"} :headers}]
  {:status 200
   :custom-header custom-value
   :body {:name (:filename file)
          :size (:size file)}})

vlad_poh15:06:00

None of these seem to work. {:post {:headers ...} or {:post {:parameters {:headers .. } or {:post {:parameters {:header .. } the last one at least shows up in the swagger window but i still get spec coercion errors

ikitommi15:06:54

@kbosompem maybe {:parameters {:header {:custom-header string?}}}

ikitommi15:06:59

@mitchelkuijpers I think so, you can have something like (s/constrained s/Int #(< % 10)) to add guard for the validation and add :swagger/maximum 10 to get the swagger docs too

metal 4
vlad_poh19:06:30

after a few hours of battling it. the parameters are case sensitive and keys remain strings unlike form, query and body params which become clojure keywords. I miss intellisense.