pip_services3_commons.validate.OnlyOneExistRule module

pip_services3_commons.validate.OnlyOneExistRule

Only one exist rule implementation

copyright

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

license

MIT, see LICENSE for more details.

class pip_services3_commons.validate.OnlyOneExistRule.OnlyOneExistRule(*properties: str)

Bases: pip_services3_commons.validate.IValidationRule.IValidationRule

Validation rule that check that at exactly one of the object properties is not null.

Example:

schema = Schema().with_rule(OnlyOneExistsRule("field1", "field2"))

schema.validate({ field1: 1, field2: "A" })     # Result: only one of properties field1, field2 must exist
schema.validate({ field1: 1 })                  # Result: no errors
schema.validate({ })                            # Result: only one of properties field1, field2 must exist
validate(path: str, schema: <module 'pip_services3_commons.validate.Schema' from '/pip_services3_commons/validate/Schema.py'>, value: Any, results: List[pip_services3_commons.validate.ValidationResult.ValidationResult])

Validates a given args against this rule.

Parameters
  • path – a dot notation path to the args.

  • schema – a schema this rule is called from

  • value – a args to be validated.

  • results – a list with validation results to add new results.