Fork me on GitHub
#malli
<
2024-02-01
>
Ryan Martin09:02:52

How do I know what properties a type can have? The readme shows :min and :max for strings, :optional for maps, but I can't find other examples or the full list of valid properties. Can we also define custom properties?

ikitommi07:02:39

Quick answer: no easy way to know these, there is a mechanism to describe the allowed props using malli schemas, source = where info lives now, you can add any custom properties and many support namespaces use those, .e.g generators use :gen/…. , transformers use :decode/… etc.

Noah Bogart14:02:33

is it possible to get the name of a schema from a schema object? i have a function that's passed different schemas and does validation on objects with them, and i'd like to be able to log the schema name

ikitommi07:02:50

depends, references are like Vars - if you pass the reference, you can ask it’s name - if you ask for the value behind the reference, you can’t.

ikitommi07:02:32

… but, you can attach names to the schemas ahead of time / in the registry.

Ryan18:02:45

if I have a regex schema, is there any way I can annotate it so that schemas including it can be generated (cljs, so no option to generate out of the box I think) or even better, can I supply a generator fn to the schema?

ikitommi07:02:02

this should work: [#"kikka" {:gen/schema :string}], also [#"kikka" {:gen/gen …test-check-generator-goes-here…}], README has all properties that can be used.

Ryan18:02:30

in this case, its for phone numbers, storing E.164 with no optional + prefix (e.g.: 1235551212, 4408001123456)

ikitommi08:02:39

:gen/fmap might be usefull here