This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-12
Channels
- # announcements (32)
- # aws (7)
- # babashka (2)
- # babashka-sci-dev (1)
- # beginners (25)
- # biff (1)
- # calva (1)
- # cider (27)
- # clj-kondo (15)
- # clojure (24)
- # clojure-berlin (1)
- # clojure-czech (4)
- # conjure (9)
- # cursive (7)
- # datalevin (1)
- # emacs (19)
- # events (1)
- # gratitude (1)
- # integrant (1)
- # introduce-yourself (2)
- # java (4)
- # meander (17)
- # membrane (4)
- # podcasts (1)
- # releases (1)
- # remote-jobs (2)
- # ring-swagger (8)
- # shadow-cljs (14)
- # testing (1)
- # tools-build (5)
- # tools-deps (3)
Is there an option to provide optional file spec?
I am using
:require [[reitit.ring.middleware.multipart :as multipart]]
provide middleware multipart/multipart-middleware
and set up parameters as
:parameters {:multipart {:logs multipart/temp-file-part}}
when I tried something like (spec/nilable multipart/temp-file-part)
, it doesn’t work.
So I have to provide two routes instead of one with the ability to pass files optionally
looking at https://cljdoc.org/d/metosin/spec-tools/0.10.5/doc/data-specs, maybe :parameters {(ds/opt :logs) multipart/temp-file-part}
but your answer helped me to find a solution
{:logs (ds/maybe multipart/temp-file-part)}
tried (ds/opt :rules) (ds/maybe multipart/temp-file-part)
output is
{
"spec": "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$28868/logs] :opt-un [:spec$28868/rules]), :type :map, :leaf? false})",
"problems": [
{
"path": [
"rules",
"clojure.spec.alpha/nil"
],
"pred": "nil?",
"val": "",
"via": [
"spec$28868/rules"
],
"in": [
"rules"
]
},
{
"path": [
"rules",
"clojure.spec.alpha/pred"
],
"pred": "clojure.core/map?",
"val": "",
"via": [
"spec$28868/rules"
],
"in": [
"rules"
]
}
],
"type": "reitit.coercion/request-coercion",
"coercion": "spec",
"value": {
"logs": {
"filename": "bugreport-33345431500100001233071f-1.74.52-01-16-2022-11-46-19.zip",
"content-type": "application/zip",
"tempfile": "/var/folders/gm/sgh_2g690cn85ybhmv1phs5c0000gq/T/ring-multipart-1380586888493316976.tmp",
"size": 4644776
},
"rules": ""
},
"in": [
"request",
"multipart-params"
]
}