Fork me on GitHub
#yada
<
2017-04-17
>
borkdude14:04:52

How to deal with defaults for optional query parameters in Yada? In Compojure-API we used that letk syntax. Now I’m doing it like this:

{:swagger/tags [“articles”]
   :methods
   {:get
    {:parameters
     {:query {(s/optional-key :source) s/Bool
              (s/optional-key :annotation) s/Bool
              (s/optional-key :skip-classification) s/Bool}}
     :swagger/summary “Get an article by GUID”
     :response (fn [ctx]
                 (let [parameters (-> ctx :parameters :query)
                       {:keys [source annotation skip-classification]
                        :or {source false
                             annotation false
                             skip-classification false}}
                       parameters]
                   ))}}}

lmergen16:04:27

@borkdude you can also use select-keys, and then merge those into some default values

lmergen16:04:36

i think it’s a matter of taste, though

lmergen16:04:09

(as usual, there is too much choice here)

lmergen16:04:27

another approach would be to go all-in on schema and solve the problem on that level

ikitommi16:04:14

Schema doesn’t handle defaults by default either, but there is a helper for those in schema-tools (https://github.com/metosin/schema-tools/blob/master/test/schema_tools/core_test.cljc#L235-L242)

borkdude17:04:33

OK, just checking if I didn’t miss anything that Yada maybe provided out of the box.