Why this feature is required (specific use-cases will be appreciated)?
It is often needed to create an api which allows to unset values explicitely in a backend.
Since undefined is not serializable to JSON, we need to pass null to indicate that intent.
Currently, @adonisjs/validator does not have strong support for nullable fields. If a required field is null, validation fails, and if an optional field is null, validation will pass, but the property which was null will be stripped away from the validated result.
for example:
export default class DataValidator {
public schema = schema.create({
field: schema.number.optional(),
});
}
// When passed {field: null} the validation result will be an empty object {}
I want null to be passed to the validated result because I need to pass it to lucid (using a model's merge method) to explicitely unset a nullable field. If the field is undefined, then the merge method will leave the column untouched in the database.
Have you tried any other work arounds?
I could always add some custom logic to controllers to add the missing null values before passing them to lucid, but that would blur separation of concern and complicate the code.
Are you willing to work on it with little guidance?
Why this feature is required (specific use-cases will be appreciated)?
It is often needed to create an api which allows to unset values explicitely in a backend.
Since
undefined
is not serializable to JSON, we need to passnull
to indicate that intent.Currently,
@adonisjs/validator
does not have strong support for nullable fields. If a required field isnull
, validation fails, and if an optional field isnull
, validation will pass, but the property which wasnull
will be stripped away from the validated result.for example:
I want
null
to be passed to the validated result because I need to pass it to lucid (using a model'smerge
method) to explicitely unset anullable
field. If the field is undefined, then themerge
method will leave the column untouched in the database.Have you tried any other work arounds?
I could always add some custom logic to controllers to add the missing
null
values before passing them to lucid, but that would blur separation of concern and complicate the code.Are you willing to work on it with little guidance?
Yes