what is the difference between :or and :alt ?
found in docs, :alt is for spec inside seq
@ikitommi how to define string constant in map spec? e.g version api is a constant
[:enum "v1.0.0"] ?
is there other ways?
and why sets are not supported as spec definition? I cannot put
[:abc #{1 2 3}]
in map spec[:= "v1.0.0"]
or [:enum "v1.0.0"]
, both work.
#{1 2 3}
doesn’t work as we didn’t want to reserver too much clojure syntax for special purposes. There is a hook to add support for that in the user space, but not documented as it’s not recommended.
also, now I think adding a shortcut syntax for regexps was not a good idea.
why? there is a cljs compiler warning about those, coudn’t fix it, instead of: #"kikka.*"
would have been enough to have [:re #"kikka.*]
or even [:string {:format "kikka.*"}]
I think in 90%+ cases people add anyway properties to the regexps like :error/message
, so the benefit for supporting plain regexps is quite small.
Host regexes don't support error positions. And I don't blame them, because the regex can fail in multiple ways at every character (our seqex schemas heuristically give the error the first longest partial match).
If we can do regex based generators we should theoretically be able to do regex based error reporting No one said it would be easy, or even a good idea. You may not want to expose your regex via error messages
An enhancement of regex error messages could be an indication at which character the match has failed. "Should match regex" isn't terribly helpful for humanized errors
[:= "v1.0.0"]đź‘Ť
Is there a function that would give ":and" instead of ":or"? stricter vs. looser. maybe mu/intersect?
(mu/union [:map [:Event keyword?]] [:map [:Event [:enum :A :B]]])
=> [:map [Event [:or keyword? [:enum :A :B]...
(my set theory skills are rusted on fridays)
Intersection would go with :and
(which is a lattice meet)
any way to get schema name from RefSchema?
e.g. I have [:schema {:registry reg} ::task]
and it’s already a RefSchema
(m/deref schema)
?
(let [schema (schema ?schema options)]
(cond-> schema (satisfies? RefSchema schema) (-deref)))
Looks like just what you need
@ben.sless thanks for the input! This gives something that looks like a keyword but in fact is a :malli.core/schema
and I don’t understand how to get the keyword out
ah, hold on, let's dig some more
What's wrong with just calling m/form
?
Okay, this is right:
(m/form (m/deref S))
You'll get back a keywordwhat you see in m/children is still a schema! but (-> m/form last) cuts it, thanks!