pip_services3_commons.validate.PropertySchema module

pip_services3_commons.validate.PropertySchema

Validation schema for object properties

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_commons.validate.PropertySchema.PropertySchema(name: str = None, value_type: Any = None, required: bool = None, rules: List[pip_services3_commons.validate.IValidationRule.IValidationRule] = None)

Bases: pip_services3_commons.validate.Schema.Schema

Schema to validate object properties

Example:

schema = ObjectSchema().with_property(PropertySchema("id", TypeCode.String))

schema.validate({ id: "1", name: "ABC" })       # Result: no errors
schema.validate({ name: "ABC" })                # Result: no errors
schema.validate({ id: 1, name: "ABC" })         # Result: id type mismatch
get_name()str

Gets the property name.

Returns

the property name.

get_type() → Any

Gets the property type.

Returns

the property type.

set_name(value: str)

Sets the property name.

Parameters

value – a new property name.

set_type(value: Any)

Sets a new property type. The type can be defined as type, type name or TypeCode

Parameters

value – a new property type.