-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Assertions and/or parsers should respect the default tag #930
Comments
I've designed the However, I am not sure that the function of assigning default values is necessary only in parse, and the names of functions, such as |
I wasn't sure about the convenience functions and only really included them for completeness. I would imagine that this feature would either work implicitly for everything that supports in (in which case those functions are redundant) or would be an optional addition (in which case those functions are extraneous). In either case, they are definitely riding the edge of being too wordy to be practically useful. As far as for where the default field population would occur, my thinking would be that it would work everywhere that validates an input and returns a confirmed object of the type. This would mean The biggest exception would be |
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: