-
Notifications
You must be signed in to change notification settings - Fork 256
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
parameter coercion can't work with schema validation #194
Comments
Sorry, how are you using Schema? Can you explain a little further? |
what plumatic/schema is. my sample code: (api/defendpoint GET "/:card-id/alerts"
"Getting alerts for card with specifications"
[card-id enabled :<< as-bool :as {{:keys [page size] :or {page 1 size 20}} :params}]
{enabled (s/maybe s/Bool)
page su/IntGreaterThanZero
size su/IntGreaterThanZero}
(do-something)) where (doc metabase.api.common/defendpoint)
|
We can't break existing functionality in Compojure, so I see only two ways forward. The first is to create another symbol or object to denote a missing value, and create an appropriate schema function. For example, The second is to add in a new symbol for coercion that matches even on |
When dealing with an optional boolean parameter, string literals like #{"1" "y" "yes" "on" "true"}) treated as true while #{"0" "n" "no" "off" "false"}) as false and nil for others.
i wrote a function named as-bool to coerce boolean literal refer to Destructuring-Syntax#parameter-coercion , while schema (s/maybe s/Bool) validates the parameter.
Failed the coercion when data binding if the boolean parameter isn't presented and route entirely as per wiki, there is no chance for schema validation comes to play.
Is it more reasonable to accept nil value at data binding and hand route flow over to schema validation at data validating?
The text was updated successfully, but these errors were encountered: