yada

fiddlerwoaroof 2019-03-12T03:42:59.018Z

Is there any way to specify a default value for an optional query parameter to a resource?

borkdude 2019-03-12T09:26:31.018500Z

@fiddlerwoaroof I don’t think this is supported in the Schema itself, so you’d have to do this using normal Clojure is my guess

dominicm 2019-03-12T09:59:46.019Z

Maybe it could be done as part of coercion

malcolmsparks 2019-03-12T10:02:32.020300Z

Possibly. RelaxNG argued that validation and defaulting should remain separate

malcolmsparks 2019-03-12T10:03:18.021600Z

Not sure

ikitommi 2019-03-12T13:56:28.022500Z

schema-tools has a coercion matcher & wrapped type to handle the defaults:

(require '[schema-tools.core :as st])
(require '[schema-tools.coerce :as stc])

(stc/coerce
  {:x nil}
  {:x (st/default s/Int 1)
   :y (st/default s/Int 2)}
  stc/default-matcher)
; => {:x 1, :y 2}

fiddlerwoaroof 2019-03-12T14:44:16.023700Z

does yada provide any way to adjust the coercion that happens? Or would I have to do this, once I get the query parameters back?

dominicm 2019-03-12T14:50:01.024100Z

You can do this with a yada parameter

fiddlerwoaroof 2019-03-12T18:26:28.024300Z

Is there an example of this?

dominicm 2019-03-12T18:34:39.024600Z

I've forgotten the name unfortunately.

dominicm 2019-03-12T18:34:56.024900Z

And I'm not at a keyboard.