Fork me on GitHub
#ring-swagger
<
2018-07-09
>
Empperi08:07:54

hmm, trying to find a way to do spec coercion and validation in such a way, that in coming JSON keys would be first transformed

Empperi08:07:20

meaning that "foo_bar" comes in and I want to handle those as :foo-bar

Empperi08:07:35

I guess Muuntaja is my answer

ikitommi08:07:57

@niklas.collin yes, jsonista reade has an example on encoding & decoding mao keys. Sadly, the apidocs don't follow that.

ikitommi08:07:08

Another option is to do a custom map transformer for json in spec-tools.

Empperi08:07:56

CompilerException java.lang.AssertionError: In Muuntaja 0.6.0+ the default JSON formatter has changed
from Cheshire to Jsonita. Changed options:

  :key-fn       => :encode-key-fn & :decode-key-fn
  :bigdecimals? => :bigdecimals
Well this was a nice suprise 👍

Empperi08:07:46

hmm, I thought compojure-api would use automatically the spectools :decode/string under the hood?

Empperi08:07:19

currently failing spec validations since there's a string coming in which should be coerced to a number

ikitommi08:07:46

for json? It's :decode/json

Empperi08:07:53

I mean, I have a spec definition such as:

(s/def ::foo
  (spec/spec
    {:spec integer?
     :decode/string str->integer}))

Empperi09:07:04

and that is used deep within my spec definitions

Empperi09:07:13

still should use :decode/json ?

Empperi09:07:30

well, I can always try

Empperi09:07:18

right, so it seems

Empperi09:07:36

not obvious

Empperi09:07:42

just a small feedback 🙂

Empperi09:07:50

anyway, got it working 👍

ikitommi09:07:45

great! PRs for obvious docs most welcome ;)

Empperi09:07:40

when I have time 😄

Empperi09:07:12

Time, that one resource you are always lacking