metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.46k stars 208 forks source link

Support for s/keys :req-un style syntax #852

Open jasonjckn opened 1 year ago

jasonjckn commented 1 year ago

New feature to mirror syntax (s/keys :req-un [::a])

At the moment, :map schema type \w qualified keywords won't validate any unqualified keywords, to compensate you have to write [:a ::foo/a], e.g.

(m/validate [:map [:a ::foo/a]] {:a value}) ;; => true

Would it make sense to add a new schema type :map-un such that

(m/validate [:map-un [::foo/a]] {:a value})  ;; => true

( Or perhaps add a new property somewhere, e.g. )

(m/validate [:map {:qualification-optional? true} [::foo/a]] {:a value})  ;; => true

If you go with the :map-un idea, its coercion implementations could transform unqualified keys into qualified keys.

It might seem like a superficial change, why not just write [:a ::foo/a], but it makes rich hickey's philosophy around specifications much more idiomatic. While malli is a superior to clojure.spec in many ways, the philosophy behind it is still state of the art.

Just an idea... feel free to close...

knubie commented 9 months ago

Using a property feels more malli-esque. It would make it easy to update an existing schema to accept unqualified keys.