Fork me on GitHub
#malli
<
2022-11-30
>
dharrigan09:11:25

I'm wondering, when invoking (mg/generate schema), if the schema contains something like [:enabled {:default true} :boolean], can the generate always use the default value, rather than flipping between true and false?

jeroenvandijk09:11:29

I think you could do [:enabled {:gen/elements [true]}] Maybe I’m wrong, https://github.com/metosin/malli#value-generation

dharrigan09:11:39

oohh.. trying...

dharrigan09:11:24

Yup, that works. ta! 🙂

🚀 1
dharrigan20:11:49

I'm a little confused as to where optional sits in a schema. It's not immediately clear in the documentation. Is this [:map [:name {:optional true} :string] same as [:map [:name [:string {:optional true}]]]?

Chris O’Donnell20:11:59

I don't think so. Pretty sure :optional needs to be a parameter of the map key entry.

Noah Bogart20:11:30

i believe that the position of the {} is supposed to look like metadata on the following object

Noah Bogart20:11:05

so [:map [:name :string]] and then with the optional "metadata"/params [:map [:name {:optional true} :string]]

dharrigan20:11:52

I see, so, [:map [:name {:optional true}]] means the name is optional. Then if I have [:map [:name {:optional true} [:string {:min 1 :max 4}]]], then it's not only optional, but I've also said that the string (if provided) must be between 1 and 4.

dharrigan20:11:07

so the metadata is about the proceeding "thing"

Noah Bogart20:11:11

ah yeah, it would be the previous thing not the following, as you've noted with the {:min 1} example

Noah Bogart20:11:35

{:optional true} means that the key might not be present, whereas [:maybe X] means the value might not be present

👍 1
escherize17:12:46

Think of it like hiccup: [:div {:style "..red"} [:span ...]] the attributes maps apply to the tags immediately before them

👍 1