metosin / reitit

A fast data-driven routing library for Clojure/Script

Home Page:https://cljdoc.org/d/metosin/reitit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docs/Tutorial: Explain how to automatically fill default values

samhedin opened this issue · comments

(From #reitit on slack clojurians)
I recently had a question about documenting and filling in default values when using Malli.
I found this example code

["/plus"
         {[..]
          :post {:summary "plus with malli body parameters"
                 :parameters {:body [:map
                                     [:x
                                      {:title "X parameter"
                                       :description "Description for X parameter"
                                       :json-schema/default 42}
                                      int?]
                                     [:y int?]]}

I believed that I could omit x from the request since it has a :json-schema/default defined:
http :3000/math/plus y:=5
but that leads to the error: "x": ["missing required key"]

I eventually discovered that my desired behavior could be achieved by changing the key name from :json-schema/default to :default.
It would be nice to have this documented.
Of course, :default is what Malli uses, but to get Malli to fill in default values, some more work needs to be done. It wasn't apparent to me to which extent reitit would assist here. Quite a lot, it turns out.
If this seems reasonable, I will be happy to submit a PR.

Thank you for all the great libraries!