Fork me on GitHub
#reitit
<
2018-09-23
>
valerauko03:09:48

i saw your comments

valerauko03:09:00

it's weird i can still reproduce it with basically the same code

valerauko04:09:15

same error as above, it dies at compile-time

ikitommi06:09:51

I woulf double-check the imports (`spec-toold.data-spec :as ds`) and try lein clean or similar to flush the possible dirty state.

valerauko07:09:29

(:require [spec-tools.data-spec :as ds]) and lein clean didn't help either...

valerauko07:09:12

it's still validating the parameter definitions with kw-map? which fails for ds/opt

valerauko07:09:58

using 0.2.2 of reitit and 0.7.1 of spec-tools

valerauko10:09:29

could you help me with muuntaja a bit?

valerauko10:09:42

i wanted to add loose content-type matching as documented in its readme

valerauko10:09:56

but when i copy-paste the code in the readme it throws a null pointer exception at me

valerauko10:09:36

kitsune.core=> (require '[muuntaja.core :as muuntaja])
nil
kitsune.core=> (def m
          #_=>   (muuntaja/create
          #_=>     (-> muuntaja/default-options
          #_=>         (assoc-in [:formats "application/json" :matches] #"^application/(.+\+)?json$"))))
#'kitsune.core/m
kitsune.core=> ((:negotiate-content-type m) "application/activity+json")
NullPointerException   kitsune.core/eval32703 (form-init6274978273947769720.clj:1)

valerauko10:09:11

seems :negotiate-content-type is missing?

kitsune.core=> (:negotiate-content-type m)
nil

valerauko10:09:08

mounted on route :muuntaja with that config doesn't seem to work either

ikitommi10:09:30

what content-type are you trying to use?

ikitommi10:09:42

Muuntaja is implemented as reified protocol, so there are no keys (your npe-case).

ikitommi10:09:37

config seems legit, the regex should match things like application/json-patch+json

valerauko10:09:51

it should be able to parse post request bodies that come with content type #{"application/json" "application/activity+json" "application/ld+json"}

valerauko10:09:33

i took that key example from the muuntaja Configuration page...

valerauko10:09:46

i thought making an instance with muuntaja/create (with options) and mounting taht on the routes under :data :muuntaja was the way

ikitommi10:09:12

it is, should work. hmm.

ikitommi10:09:29

It doesn't match at all?

valerauko10:09:21

when the header is "content-type" "application/activity+json", :body comes through as a java.io.ByteArrayInputStream

valerauko10:09:44

when i curl with application/json it's parsed correctly

ikitommi10:09:50

if you can isolate a minimalistic failing example config/code to run in repl, I can look in the evening.

valerauko10:09:11

i'll try putting one together

👍 4
valerauko11:09:37

i had the muuntaja middleware commented out

valerauko11:09:06

i didn't notice because it was still negotiating content types all the same

valerauko11:09:24

also with the body-params specced as string? coercion kept 400ing, only works with any?

valerauko16:09:51

(muuntaja/create
    (-> muuntaja/default-options
        (assoc-in [:formats "application/json" :matches]
                  #"^application/(.+\+)?json$")
        (assoc-in [:formats "application/xml" :matches]
                  #"^application/(.+\+)?xml$")))
why is this telling me application/xml is invalid?

valerauko16:09:01

oh i figure it's because it can't encode/decode it?

valerauko16:09:19

is there a way to just pass it through like plain text strings (charset encoded) and i'll handle the rest?

ikitommi19:09:37

Yes, if you define a format and it matches but there is no decoder, it will fail.

ikitommi19:09:00

To get raw xml, just do not register the format and read the raw format from request. There is m/get-request-format-and-charset to help.

ikitommi19:09:20

(require '[muuntaja.middleware :as middleware])
(require '[muuntaja.core :as m])

(->> {:headers {"content-type" "application/edn; charset=utf-16"
                "accept" "cheese/cake"
                "accept-charset" "cheese-16"}}
     ((middleware/wrap-format identity))
     ((juxt m/get-request-format-and-charset
            m/get-response-format-and-charset)))
;[#FormatAndCharset{:format "application/edn"
;                   :charset "utf-16"
;                   :raw-format "application/edn"}
; #FormatAndCharset{:format "application/json"
;                   :charset "utf-8"
;                   :raw-format "cheese/cake"}]