malli
malli copied to clipboard
malli.core/schema doesn't work for lists
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))
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.