not at the moment. issue welcome.
::m/default
for :multi
merged in master:
(def valid?
(m/validator
[:multi {:dispatch :type}
["object" [:map-of :keyword :string]]
[::m/default :string]]))
(valid? {:type "object", :key "1", :value "100"})
; => true
(valid? "SUCCESS!")
; => true
(valid? :failure)
; => false
Maybe the same could be used for extra keys in maps? (https://github.com/metosin/malli/issues/43)
@ikitommi I was trying (for fun) to write a core.match like thing with malli.
So {:a ?x :b 1}
would match on {:a 2 :b 1}
and parsing would give you back {?x 1}
. This is currently a bit difficult since you cannot change how keys are named in the parsed output from map schemas, can you?
So I would generate a schema like {:b [:= 1] :a :any}
but then the parsed output loses the name ?x
Can I influence how things get parsed using an extra predicate similar to s/and
in spec?
(m/parse [:map [:a [:and :any
[:fn (fn [x]
['x? x])]]]]
{:a 1})
not atm, parsing could have it's own property key for this, e.g. [:map {:parse ...} ...]
. Internally, could be interceptors, so one can do easily pre, post & schema-based parsing with that.
We discussed with @nilern about combining internally parsing, explain and transform. They are now mostly (optimized) duplicates of each other.
map keys -> could done with same mechanism. Add custom parse tags to keys as properties and hook a post-parse fn to rename the keys. Or do, whatever.
ported the plumatic-style inline schemas for 0.3.0, it kinda works, but no tests and not happy with the original (string-based) error reporting. renamed to ns to malli.experimental.schema
as it might not be part of the malli core library. any thoughts on this? add tests, cleanup and ship as experimental add-on?
Replied in https://github.com/metosin/malli/issues/125 . Btw I hope I'm not pestering too much - I simply try to make an educated attempt at improving perceived problems (which can last long - for example I use Schema at work and it kinda hurts to use an outdated tech that turned out to not be the best bet)
the defn
now emits a function schema into malli function registry and it can be configured to validate always, never or based on a dynamic var - at runtime.
what is the validator i can use for 'any collection, no matter the type' ? i don't care whether it's a sequence or vector or set, just that it's a collection. what can i use for this? i wasn't able to find it
@lmergen maybe coll?
i can use that like [:coll pos-int?]
?
trying to figure out the best way to do this 🙂
sadly, it's just the core predicate, so no child type checking. There is no :coll
atm. Would be a oneliner to add
See https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L1858
is there a specific reason why this is not in malli itself? as in, if i would send a PR to add this, would that be useful?
no-one has asked, PR welcome (tests included)!
of course 👍
it spans to generator, json schema, human errors etc. But, good examples :)
thanks, i'll see what i can do
yes it touches a lot of surface
coll?
also matches maps, that has some effects on JSON-Schema implementation at least
good point. I guess there is not a predicate for non-map collection.
I imagine maps also having keys can lead to all sorts of confusion when implementing [:coll pos-int?]
What about :sequential
?
Oh that does not take sets
Can always do [:or [:sequential pos-int?] [:set pos-int?]]
That does not support seqs though... and now I see nothing else does either.
Made some issues about that https://github.com/metosin/malli/issues/393 https://github.com/metosin/malli/issues/394