Fork me on GitHub
#reitit
<
2023-08-23
>
timo11:08:20

Anyone using multipart-coercion? I am having a hard time using it.

:post {:handler #(views.products/create-product product-repo file-store %)
       :parameters {:multipart ::eprod/create-new-product}}
with
(s/def ::create-new-product (s/keys :req-un [::cultivation-period ::harvest-period
                                             ::category ::type ::name ::unit
                                             ::image ::processing-time]))
it does not validate anything. I can send anything.

timo11:08:59

I am using spec coercion

timo11:08:02

and in other places of the app coercion does work fine

valerauko14:08:00

do you use ring's multipart middleware?

timo14:08:23

yes of course

valerauko14:08:31

does param coercion work for not-multipart parameters?

timo14:08:49

yes, it's fine

timo07:08:06

I'll try to make time to create a reproducible test for it

timo11:08:36

I've been using kit as a template and it ships with ring-defaults which enables multipart-params middleware when setting the multipart config to true. multipart-params is not sufficient when intending to coerce multipart-forms. I needed to activate https://github.com/metosin/reitit/blob/master/modules/reitit-middleware/src/reitit/ring/middleware/multipart.clj .