ring-swagger

ring-swagger & compojure-api
Empperi 2018-07-09T08:30:54.000321Z

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

Empperi 2018-07-09T08:31:20.000240Z

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

Empperi 2018-07-09T08:33:35.000255Z

I guess Muuntaja is my answer

ikitommi 2018-07-09T08:42:57.000041Z

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

ikitommi 2018-07-09T08:44:08.000325Z

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

ikitommi 2018-07-09T08:46:23.000361Z

here's an example of such: https://github.com/metosin/spec-tools/blob/master/src/spec_tools/transform.cljc#L108-L111

Empperi 2018-07-09T08:46:56.000173Z

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 👍

Empperi 2018-07-09T08:55:46.000124Z

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

Empperi 2018-07-09T08:56:19.000026Z

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

ikitommi 2018-07-09T08:58:46.000270Z

for json? It's :decode/json

Empperi 2018-07-09T08:59:53.000206Z

I mean, I have a spec definition such as:

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

Empperi 2018-07-09T09:00:04.000018Z

and that is used deep within my spec definitions

Empperi 2018-07-09T09:00:13.000339Z

still should use :decode/json ?

Empperi 2018-07-09T09:00:30.000104Z

well, I can always try

Empperi 2018-07-09T09:01:18.000106Z

right, so it seems

Empperi 2018-07-09T09:01:36.000096Z

not obvious

Empperi 2018-07-09T09:01:42.000325Z

just a small feedback 🙂

Empperi 2018-07-09T09:10:50.000159Z

anyway, got it working 👍

ikitommi 2018-07-09T09:14:45.000336Z

great! PRs for obvious docs most welcome ;)

Empperi 2018-07-09T09:18:40.000067Z

when I have time 😄

Empperi 2018-07-09T09:19:12.000203Z

Time, that one resource you are always lacking