Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/Tutorial: Explain how to automatically fill default values #630

Open
samhedin opened this issue Jun 16, 2023 · 0 comments
Open

Docs/Tutorial: Explain how to automatically fill default values #630

samhedin opened this issue Jun 16, 2023 · 0 comments

Comments

@samhedin
Copy link

samhedin commented Jun 16, 2023

(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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant