PropertyValidationRules
The rule section is where you can define which validation rules will be applied to the property.
Each validation must be of a pre-defined type, for example, IsNotEmpty, IsGreaterThan, among others. You can specify a series of validations to be executed sequentially, in the same order they are defined in the YAML.
To learn more about the types of rules that exist, see Rule Types section.
Fields
A rule contains the following fields to be defined:
Type
The validation rule type that will be applied to the property.
Requirements Rules:
- Is Required;
- Must be an Allowed valid Type. See the valid Types;
Example:
1 2 |
|
Expressions
An array of values that must be passed to the validation rule when it requires params for it's proper execution.
For example, to ensure that the value of a numeric field is greater than 10, it is necessary to pass it as a param to the IsGreaterThan type rule. In addition to that, this value must be informed as an expression. For more details, see Expression section.
Requirements Rules:
- Is Required;
- Each expression in the array must be valid. See Expression section to learn more about the rules for each expression type.
Example:
1 2 3 4 |
|
ErrorCode
Allows you to define an error code for when the current validation rule fails.
Example:
1 2 3 4 5 |
|
Message
Allows you to define an error message for when the current validation rule fails.
Example:
1 2 3 4 5 6 |
|
Note
If you are configuring a validation rule for a nullable property, be aware that the comparison rules are not applied to null values. If you want to ensure that it is never null, an IsNotNull rule must also be applied.