Assertions and/or parsers should respect the default tag #930
Labels
enhancement
New feature or request
good first issue
Good for newcomers
question
Further information is requested
Feature Request
When creating my data models, I make ample use of tags to make them easily serializable into a JSON schema format. Another feature I use are the validation and parsing functions, but I have noticed that they don't seem to respect when a field has the
Default
tag.I would've expected that when I run a validator on an object or a parse on a valid JSON string that omitted a field marked with the
Default
tag, the validator/parser would self-insert the specified default value for that field. This is especially true for parser functions, where the common use case is to validate user input and I would expect omitted fields with default values to be automatically populated.I'm not sure if the desired approach should be to mark the field with the default value as optional or not, so I will include expected behavior for both approaches:
Example (Required Field)
Current Behavior
Expected Behavior
Example (Optional Field)
Current Behavior
Expected Behavior
Alternative Solution:
applyDefaults
FunctionIf for whatever reason it is undesired or overly complicated to bundle this functionality into the existing parsing and validating functions, an alternative solution would be a new function that analyzes the missing optional fields of an object and supplies any default values from the defined tags:
Definition
Usage
The text was updated successfully, but these errors were encountered: