-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
welcome :string schema #205
Conversation
ikitommi
commented
Jun 8, 2020
Any chance for adding an option along the lines of |
|
I specifically want to avoid situations where user inputs |
I use a version of |
Just chiming in that a |
Thanks for explaining. There are two things here:
the latter can be done using a (new) transformer, the first would be currently: [:and :string [:fn (complement str/blank?)]] agree it's not pretty. |
JSON Schema has https://json-schema.org/understanding-json-schema/reference/string.html#built-in-formats |
example trimmer: (require '[malli.transform :as mt])
(require '[malli.core :as m])
(defn str-transformer []
(mt/transformer
{:decoders {:string {:compile (fn [schema _]
(let [{:string/keys [trim]} (m/properties schema)]
(when trim #(cond-> % (string? %) str/trim))))}}}))
(m/decode [:string {:min 1}] " " (str-transformer))
; => " "
(m/decode [:string {:string/trim true, :min 1}] " " (str-transformer))
; => ""
(m/decoder :string (mt/str-transformer))
; => #object[clojure.core$identity] (no-op) |
Happy to take of a tested and lean string-trimmer PR with all the trims, pads etc. |
@pithyless could you write an separate issue of the trim-validated thing? Will merge this now. |
Post-merge review: the user guide -style example in the README is good, but a reference style documentation that lists the possible options would be also needed. |