metosin / compojure-api

Sweet web apis with Compojure & Swagger
http://metosin.github.io/compojure-api/doc/
Eclipse Public License 1.0
1.11k stars 149 forks source link

How do I specify an optional field when accepting multipart-params for a request? #460

Open amokfa opened 4 months ago

amokfa commented 4 months ago

Library Version(s)

2.0.0-alpha31

Problem

(POST "/test-route" request
     :multipart-params [optional_data :- s/Str]
     :middleware [admin-rbac upload/wrap-multipart-params]
     (res/ok "ok"))

In this example, optional_data is not a mandatory argument. How do I tell the framework to accept requests which do not provide this field. I've tried these and they don't work:

...
:multipart-params [optional_data :- s/Str nil]
...
...
:multipart-params [optional_data :- (s/maybe s/Str)]
...