Class PropertySchema
java.lang.Object
org.pipservices3.commons.validate.Schema
org.pipservices3.commons.validate.PropertySchema
Schema to validate object properties
### Example ###
ObjectSchema schema = new ObjectSchema().withProperty(new PropertySchema("id", TypeCode.String));
schema.validate(Map.of("id", "1", "name" ,"ABC" )); // Result: no errors
schema.validate(Map.of( "name", "ABC" )); // Result: no errors
schema.validate(Map.of( "id", 1, "name", "ABC" )); // Result: id type mismatch
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new validation schema.PropertySchema
(String name, Object type) Creates a new validation schema and sets its values.PropertySchema
(String name, Object type, Boolean required, List<IValidationRule> rules) Creates a new validation schema and sets its values. -
Method Summary
Modifier and TypeMethodDescriptiongetName()
Gets the property name.getType()
Gets the property type.protected void
performValidation
(String path, Object value, List<ValidationResult> results) Validates a given value against the schema and configured validation rules.void
Sets the property name.void
Sets a new property type.Methods inherited from class org.pipservices3.commons.validate.Schema
getRules, isRequired, makeOptional, makeRequired, performTypeValidation, setRequired, setRules, validate, validateAndThrowException, validateAndThrowException, withRule
-
Constructor Details
-
PropertySchema
public PropertySchema()Creates a new validation schema. -
PropertySchema
Creates a new validation schema and sets its values.- Parameters:
name
- (optional) a property nametype
- (optional) a property type- See Also:
-
PropertySchema
Creates a new validation schema and sets its values.- Parameters:
name
- (optional) a property nametype
- (optional) a property typerequired
- (optional) true to always require non-null values.rules
- (optional) a list with validation rules.- See Also:
-
-
Method Details
-
getName
Gets the property name.- Returns:
- the property name.
-
setName
Sets the property name.- Parameters:
value
- a new property name.
-
getType
Gets the property type.- Returns:
- the property type.
-
setType
Sets a new property type. The type can be defined as type, type name or [[TypeCode]]- Parameters:
value
- a new property type.
-
performValidation
Validates a given value against the schema and configured validation rules.- Overrides:
performValidation
in classSchema
- Parameters:
path
- a dot notation path to the value.value
- a value to be validated.results
- a list with validation results to add new results.
-