I'm trying to do a validation for key value in a vector using plumatic-schema but the error message is not clear for me, here's what I'm trying to do:
;validating array with maps, it works
(s/validate [{}] [{} {}])
=> [{} {}]
;validating array with key and map (any lenght), not work
(s/validate [s/Int {}] [0 {} 1 {}])
[Int {}] is not a valid sequence schema;
a valid sequence schema consists of zero or more `one` elements, followed by zero or more
`optional` elements, followed by an optional schema that will match the remaining elements.
My question is, do you know what am I doing wrong? And the real meaning of this error?
The goal actually is to use this validation for a function call,
eg:
(s/defn example [items :- [(s/one s/Int "i") (s/one {} "v")]] ...)
;the call should be valid for cases like this
(example [0 {} 1 {} 2 {} 3 {}])
(example [0 {}])
See these docs:
Here is code showing how it works:
If you want to validate arbitrary lengths of alternating int & map, you may have to do a little prep work:
P.S.
I also have some pre-defined schemas (e.g.
KeyMap
,Pair
, etc) that I find very handy in the tupelo.schema namespace.