metosin / malli

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

malli.core/schema doesn't work for lists #950

Open bsless opened 10 months ago

bsless commented 10 months ago

While schema literals will most likely be written in vector forms, when building schemas programatically there's a chance the schema won't be a vector

Minimal case: (malli.core/schema (list :int)) vs (malli.core/schema (vector :int))

ikitommi commented 10 months ago

That is true. But Map-syntax is better anyway for programmatically creating schemas?

Bit related:

Had an idea to misuse the list + symbol syntax as a "malli-lite2" syntax, but buried the idea as too-many-syntaxes. this:

[:map
 [:id :int]
 [:size [:maybe [:set [:enum "s" "m" "l"]]]]]

... could be represented as:

'(map
  [:id :int]
  [:size (maybe (set (enum "s" "m" "l")))])

... with auto-converting list+symbol into vector+keyword.

But I think it's better to have functional explicit dsl instead:

(require '[malli.dsl :as md])

(md/map
 :id :int
 :size (md/maybe (md/set (md/enum "s" "m" "l"))))

... which allows proper static analysis by tools like cursive & clj-kondo on arguments.