Fork me on GitHub
#malli
<
2023-08-23
>
ander18:08:51

I'm trying to write a schema for a map where a few keys are optional. These are coming in through a form post through ring/reitit and coercion is working well. I can get it so that it converts empty strings to nil but I think it'd be nice to dissoc it from the map entirely. I have something like this so far:

(defn omit-blank [s]
  (when-not (str/blank? s)
    s))

(def user (m/schema [:map {:closed true}
                       [:user/email :string]
                       [:user/alias {:decode/string omit-blank
                                     :optional true} [:maybe :string]]]))
I found a similar post here, but I'm not sure where to put the function that was mentioned as a solution: https://clojurians.slack.com/archives/CLDK6MFMK/p1653309841392379