-
Notifications
You must be signed in to change notification settings - Fork 512
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
Null value for boolean attribute is converted to false. How to alter this behavior? #1444
Comments
Hello there RohitRox 👋 Thank you for opening your very first issue in this project. We will try to get back to you as soon as we can.👀 |
Hi there, you can customize the template as well as the route generator (template is simpler and should be sufficient). However, we should also discuss these groups of coercions and if we want to customize them (i.e. via config or hooks). However, as is, this is intended behavior, therefore I'll tag this properly. |
This issue is more obvious (and more obviously a bug vs intended behavior) when the boolean property explicitly allows nulls. e.g. interface UserCreateRequest {
preferredDelivery: boolean | null
} This also improperly converts explicitly |
Try |
WOW, WAIT... WHAT!? Yeah, that works. But why?? And can we make the more "standard" |
Validation is from left to right. Thus, so is coercion. So:
vs.
We can make it work, by rewriting the entire metadata layer to output json schemas for ajv or basically reimplement ajv ourselves. |
This is related to validation. Null values sent for attributes defined as boolean are converted to false.
Sorting
I'm submitting a ...
I confirm that I
Current & Expected Behavior
When an attribute is defined as a boolean
For eg:
and in payload/request body, if null is sent
For eg:
After the request passes through validation, the
preferredDelivery
's value is observed to be false.The expected behavior is that the null value should have been preserved.
Possible Solution
I understand in some cases this is okay and desired, but is some cases this behavior is needed. And I couldn't find a way to alter this behavior.
The validator library (https://github.com/validatorjs/validator.js) seem to have
{ loose: false }
option but I could not find a way to use it here.Any help or guidance on this?
The text was updated successfully, but these errors were encountered: