Closed RohitRox closed 7 months ago
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 null
values to false
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
null
values tofalse
Try null | boolean
WOW, WAIT... WHAT!?
Yeah, that works. But why?? And can we make the more "standard" boolean | null
work as well?
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. I dont have plans to do either.
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?