def __call__(self, instance, location): results = [] for prop, dependentProperties in self.value.items(): if prop in instance: if not (set(dependentProperties) < set(instance.keys())): # need to fill in the message results.append( ValidationResult(message="", location=location, keywordLocation=self.location)) # need to fill in message return (True if not results else ValidationResult( message="", keywordLocation=self.location, location=location))
def __call__(self, instance, location): self._validators = [] if self._items_validator: self._validators = itertools.repeat(self._items_validator) elif self._items_validators: if self._additional_items_validator: self._validators = itertools.chain( self._items_validators, itertools.repeat(self._additional_items_validator), ) else: self._validators = self._items_validators results = filterfalse( bool, (validator(instance=item, location=f"{location}/{i}") for i, ( item, validator) in enumerate(zip(instance, (self._validators)))), ) results = list(results) return (True if not results else ValidationResult( message="this fails for items and additional_items", keywordLocation="", # since this is a virtual keyword location=location, sub_results=results, ))
def __call__(self, instance, location): res = len(instance) <= self.value return (True if res else ValidationResult( message=f"This has more than {self.value} items", keywordLocation=self.location, location=location, ))
def __call__(self, instance, location): if not self._if_validator: return True res = True if self._if_validator(instance=instance, location=location): if self._then_validator: res = self._then_validator( instance=instance, location=location ) # this location is wrong else: if self._else_validator: res = self._else_validator( instance=instance, location=location ) # this location is wrong return ( True if res else ValidationResult( message="failed if then else", keywordLocation=self.location, location=location, sub_results=[res], ) )
def __call__(self, instance, location): res = instance < self.value return (True if res else ValidationResult( message=f"{instance!r} is less than or equal to {self.value!r}", keywordLocation=self.location, location=location, ))
def __call__(self, instance, location): if self._validator: count = 0 for value in instance: res = self._validator(instance=value, location=location) if res: count += 1 sub_results = [] if count == 0: sub_results.append( ValidationResult( message="This doesnt contain an item that matches this", keywordLocation=f"{self.location}/contains", location=location, )) else: if not (self.minContainsValue <= count): sub_results.append( ValidationResult( message= f"This contains less than {self.minContainsValue} matches", keywordLocation=f"{self.location}/minContains", location=location, )) if not (count <= self.maxContainsValue): sub_results.append( ValidationResult( message= f"This contains more than {self.maxContainsValue} matches", keywordLocation=f"{self.location}/maxContains", location=location, )) if sub_results: return ValidationResult( # this is technically wrong since it combines more than one result message="", location=location, keywordLocation="", # since this is a virtual keyword sub_results=sub_results, ) else: return True else: return True
def __call__(self, instance, location): if not self.regex.search(instance): return ValidationResult( message=f"{instance!r} doesnt match this pattern: {self.value!r}", location=location, keywordLocation=self.location, ) return True
def __call__(self, instance, location): res = len(instance) <= self.value return (True if res else ValidationResult( message= f"this {instance} has more than maxProperties: {self.value}", keywordLocation=self.location, location=location, ))
def __call__(self, instance, location): for type_ in self._types: if isinstance_(instance, NAME_TO_TYPE[type_]): return True return ValidationResult( message=f"{instance!r} is not a {self.value}", location=location, keywordLocation=self.location, )
def __call__(self, instance, location): for value in self.value: if equals(value, instance): return True return ValidationResult( message=f"{instance!r} is not one of the values in this enum {self.value!r}", location=location, keywordLocation=self.location, )
def __call__(self, instance, location): missing = set(self.value) - set(instance.keys()) if missing: return ValidationResult( message= f"This instance is missing these required keys: {missing}", location=location, keywordLocation=self.location, ) return True
def __call__(self, instance, location): res = len(instance) <= self.value return ( True if res else ValidationResult( message=f"{instance!r}'s length is more than max_length: {self.value!r}", keywordLocation=self.location, location=location, ) )
def __call__(self, instance, location): ok = equals(self.value, instance) return ( True if ok else ValidationResult( message=f"{instance!r} is not equal to the constant {self.value!r}", location=location, keywordLocation=self.location, ) )
def __call__(self, instance, location): res = self._validator(instance=instance, location=location) return ( True if res else ValidationResult( message="failed ref", keywordLocation=self.location, location=location, sub_results=[res], ) )
def __call__(self, instance, location): # using this multipier here so that the precision is better multiplier = 100000 instance = instance * multiplier value = self.value * multiplier if (instance % value) != 0: return ValidationResult( message=f"{instance!r} is not a multiple of {self.value!r}", location=location, keywordLocation=self.location, ) return True
def __call__(self, instance, location): results = validate_instance_against_all_validators( validators=self._validators, instance=instance, location=location) results = list(results) if not results: return True else: return ValidationResult( message="", location=location, keywordLocation=self.location, sub_results=results, )
def __call__(self, instance, location): if self.value: itemsset = set([str(value) for value in instance]) # TODO(ope) - actually make sure the values are unique - is this even possible? if len(itemsset) != len(instance): return ValidationResult( message="This doesnt have unique items", location=location, keywordLocation=self.location, ) return True
def __call__(self, instance, location): # errors populated but not actual error. # unset error? result = self._validator(instance=instance, location=location) return ( ValidationResult( message="failed Not validation", location=location, keywordLocation=self.location, sub_results=[result], ) if result else True )
def __call__(self, instance, location): results = validate_property_names(validator=self._validator, instance=instance, location=location) results = list(results) if all(results): return True else: return ValidationResult( message="Not all property names match this schema", location=location, keywordLocation=self.location, sub_results=results, )
def __call__(self, instance, location): results = filterfalse( bool, ( validator(instance=instance, location=location) for validator in self._validators ), ) # this location is probably wrong results = list(results) return ( True if not results else ValidationResult( message="failed allOf", keywordLocation=self.location, location=location, sub_results=[results], ) )
def __call__(self, instance, location): results = list( filterfalse( bool, ( validator(instance=instance, location=location) for validator in self._validators ), # this location is probably wrong ) ) return ( True if len(results) == (len(self._validators) - 1) else ValidationResult( message="failed oneOf", keywordLocation=self.location, location=location, sub_results=results, ) )
def __call__(self, instance, location): results = _validate( property_validators=self._validators, additional_validator=self._additional_validator, pattern_validators=self._pattern_validators, instance=instance, location=location, ) results = list(results) if all(results): return True else: return ValidationResult( message= f"This instance fails the combination of properties, patternProperties and additionalProperties", location=location, keywordLocation=self.location, sub_results=results, )
def __call__(self, instance, location): return ValidationResult( message="this fails for every instance", location=location, keywordLocation=self.location, )