Fork me on GitHub
#malli
<
2023-01-25
>
grav10:01:05

What's the status of converting json-schemas to malli?

delaguardo10:01:20

404, looks like it is private gist

2
grav11:01:06

@UK0810AQ2 Would you mind sharing what you've got?

Ben Sless14:01:37

I'll fix it when I get home

🙏 2
flowthing12:01:24

Given [:map {:foo {:default :bar}}], does Malli have a API for getting the default value?

ikitommi12:01:25

that’s an empty map with one property :foo :thinking_face:

flowthing12:01:03

Grah, sorry, typo. 🙂

flowthing12:01:44

[:map [:foo {:default :bar} keyword?]]

flowthing12:01:32

Hmm, right, I know about that, but I was wondering whether I could introspect the schema to figure out the default value for a given key. But now that you mention it, using value transformation is probably the better route. 👍 Thanks!

juhoteperi12:01:47

(:default (m/properties (mu/get map-schema :foo))) might work

flowthing12:01:50

I tried that earlier, but it doesn’t seem to:

(malli.core/properties (malli.util/get [:map [:foo {:default :bar} keyword?]] :foo))
;;=> nil

juhoteperi12:01:11

Did you check what just mu/get returns?

flowthing12:01:53

Yeah, it returns keyword?, so it’s not suprise it doesn’t work. I also tried find:

(malli.util/find [:map [:foo {:default :bar} keyword?]] :foo)
;;=> [:foo {:default :bar} keyword?]

(malli.core/properties (malli.util/find [:map [:foo {:default :bar} keyword?]] :foo))
;;=> Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:138).
;;   :malli.core/invalid-schema
but that throws.

juhoteperi12:01:13

Oh right, and the default property is in the map schema key props

flowthing12:01:47

I mean I can get to it using find, but it doesn’t feel quite right. 🙂

ikitommi12:01:45

ideas most welcome for a better api, currently mu/find or m/entries on the map to iterate all entries.

flowthing12:01:49

Good to know, thanks. 👍 I think coercing the map to contain the default values is the right way to go in my case, though.