Fork me on GitHub
#malli
<
2021-11-02
>
dakra16:11:10

I have a beginner question: I validate incoming JSONs by first stripping extra keys, then validating against a malli schema and then output avro. How can I keep/specify the type of floats/doubles? E.g.

(-> [:map [:score double?]]
      (m/encode {:score 0} mt/strip-extra-keys-transformer)
      :score
      type)
;; => java.lang.Long
While I want double.

Ben Sless16:11:47

Should you use a string transformers first?

dakra16:11:22

This seems to work when it's a string. So

(-> [:map [:score double?]]
      (m/decode {:score "0"} mt/string-transformer)
      :score
      type)
;; => java.lang.Double
works.. but I get {:score 0} as input and then it's still Long.

dakra16:11:54

But this lead me to look at the other transformers and decode with json-transformer seems to do the trick 🙂

Ben Sless16:11:46

Hang on, decode is when reading, encode is when writing

Ben Sless16:11:15

If the json is incoming you should decode

dakra16:11:17

Apparently I got that mixed up. But when I only use strip-extra-keys-transformer I can use encode or decode.. In both cases the extra keys got stripped. But for my (new) use-case where I want to have a double where the schema is double I have to use decode like you said.

Ben Sless17:11:04

Yes, where are you getting data in from? Http?

dakra17:11:50

I write with jackdaw a kstreams app that validates the incoming JSON events, does some simple transformations and outputs to multiple different topics depending on the event content.

Paul Santa Clara22:11:42

Hey there. I was just wondering if there were plans to expand malli to include support for openapi 3? Or should i just stick to spec-tools for the immediate future?

Hukka06:11:13

There's an issue for that where somebody was going to work on it, but I haven't got a reply last month. That said, I heard a rumour that someone else would tackle it by Christmas. Might be that I need it sooner and might have a look too. Didn't seem terribly difficult, considering that the jsonschema support is already there. At least a simple version that is valid openapi3. Perhaps something that handles all the refs etc. would be more complex.

Paul Santa Clara13:11:14

that's great to hear that it's tentatively on the roadmap! I'll keep a close eye on things and switch over ASAP. Thanks!