Fork me on GitHub
#reitit
<
2022-12-06
>
DrLjótsson19:12:17

I'm trying to figure out if I can specify a reitit route that takes a vector as query arguments, i.e., :parameters {:query (l/schema {:namespaces [:vector string?]})} , which is called like route?namespaces=foo&namespaces=bar and [:parameters :namespaces] would be ["foo" "bar"] But I can't get it to work, 400 error.

DrLjótsson20:12:34

I found this https://github.com/metosin/reitit/issues/298#issuecomment-1161945435 and tried to add it to my muntaaja coercion but to no avail. the singleton->vector function is never called

DrLjótsson20:12:45

(defn singleton->vector
  [x]
  (println "BOOM!" x)
  (if (vector? x) x [x]))

(def custom-string-type-decoders
  (assoc (malli.transform/-string-decoders) :vector singleton->vector))

(def custom-string-transformer
  (malli.transform/transformer
    {:name     :string
     :decoders custom-string-type-decoders
     :encoders malli.transform/-string-decoders}))

(def muuntaja-instance
  (-> muuntaja/default-options
      (update-in [:formats "application/transit+json"] assoc
                 :encoder-opts {:handlers transit-encoder-handlers}
                 :decoder-opts {:handlers transit-decoder-handlers})
      (assoc-in [:transformers :string :default] custom-string-transformer)
      (muuntaja/create)))