components/policy/tools/schema_validator.py
def ValidateValue(self, schema, value, enforce_use_entire_schema=False):
    """Validates that |value| complies to |schema|.

    See _ValidateValueInternal(schema, value) for a detailed description of the
    value validation. If |enforce_use_entire_schema| is enabled, each value and
    its sub-values have to use every property of each used schema at least once
    and values with schema type 'array' may not be empty.
    Args:
      schema (dict): The JSON schema.
      value (any): The value being validated.
      enforce_use_entire_schema (bool): Whether each property hsa to be used at
        least once.
    Returns:
      bool: Whether the value is valid or not.
    """
    self.enforce_use_entire_schema = enforce_use_entire_schema
    self.expected_properties = {}
    self.expected_pattern_properties = {}
    self.expected_additional_properties = {}
    self.used_properties = {}
    self.used_pattern_properties = {}
    self.used_additional_properties = {}
    self.num_errors = 0

    self._ValidateValueInternal(schema, value)

    # Check that all properties, patternProperties and additionalProperties were
    # used at least once for each schema.
    if self.enforce_use_entire_schema:
      if self.expected_properties != self.used_properties:
        for schema_id, expected_properties \
            in self.expected_properties.items():
          used_properties = self.used_properties.get(schema_id, set())
          unused_properties = expected_properties.difference(used_properties)
          if unused_properties:
            self._Error("Unused properties: %s" % unused_properties)
      if self.expected_pattern_properties != self.used_pattern_properties:
        for schema_id, expected_properties \
            in self.expected_pattern_properties.items():
          used_properties = self.used_pattern_properties.get(schema_id, set())
          unused_properties = expected_properties.difference(used_properties)
          if unused_properties:
            self._Error("Unused pattern properties: %s" % unused_properties)
      if self.expected_additional_properties != self.used_additional_properties:
        self._Error("Unused additional properties.")

    return self.num_errors == 0
Validates that |value| complies to |schema|.

    See _ValidateValueInternal(schema, value) for a detailed description of the
    value validation. If |enforce_use_entire_schema| is enabled, each value and
    its sub-values have to use every property of each used schema at least once
    and values with schema type 'array' may not be empty.
    Args:
      schema (dict): The JSON schema.
      value (any): The value being validated.
      enforce_use_entire_schema (bool): Whether each property hsa to be used at
        least once.
    Returns:
      bool: Whether the value is valid or not.
    
Validates that |value| complies to |schema|.
See _ValidateValueInternal(schema, value) for a detailed description of the
value validation. If |enforce_use_entire_schema| is enabled, each value and
its sub-values have to use every property of each used schema at least once
and values with schema type 'array' may not be empty.
Validates that |value| complies to |schema| . See _ValidateValueInternal ( schema value ) for a detailed description of the value validation . If |enforce_use_entire_schema| is enabled each value and its sub - values have to use every property of each used schema at least once and values with schema type ' array ' may not be empty .
def ValidateValue(self, schema, value, enforce_use_entire_schema=False):
    self.enforce_use_entire_schema = enforce_use_entire_schema
    self.expected_properties = {}
    self.expected_pattern_properties = {}
    self.expected_additional_properties = {}
    self.used_properties = {}
    self.used_pattern_properties = {}
    self.used_additional_properties = {}
    self.num_errors = 0
    self._ValidateValueInternal(schema, value)
    if self.enforce_use_entire_schema:
      if self.expected_properties != self.used_properties:
        for schema_id, expected_properties \
            in self.expected_properties.items():
          used_properties = self.used_properties.get(schema_id, set())
          unused_properties = expected_properties.difference(used_properties)
          if unused_properties:
            self._Error("Unused properties: %s" % unused_properties)
      if self.expected_pattern_properties != self.used_pattern_properties:
        for schema_id, expected_properties \
            in self.expected_pattern_properties.items():
          used_properties = self.used_pattern_properties.get(schema_id, set())
          unused_properties = expected_properties.difference(used_properties)
          if unused_properties:
            self._Error("Unused pattern properties: %s" % unused_properties)
      if self.expected_additional_properties != self.used_additional_properties:
        self._Error("Unused additional properties.")
    return self.num_errors == 0
def ValidateValue ( self , schema , value , enforce_use_entire_schema = False ) : self . enforce_use_entire_schema = enforce_use_entire_schema self . expected_properties = { } self . expected_pattern_properties = { } self . expected_additional_properties = { } self . used_properties = { } self . used_pattern_properties = { } self . used_additional_properties = { } self . num_errors = 0 self . _ValidateValueInternal ( schema , value ) if self . enforce_use_entire_schema : if self . expected_properties != self . used_properties : for schema_id , expected_properties in self . expected_properties . items ( ) : used_properties = self . used_properties . get ( schema_id , set ( ) ) unused_properties = expected_properties . difference ( used_properties ) if unused_properties : self . _Error ( "Unused properties: %s" % unused_properties ) if self . expected_pattern_properties != self . used_pattern_properties : for schema_id , expected_properties in self . expected_pattern_properties . items ( ) : used_properties = self . used_pattern_properties . get ( schema_id , set ( ) ) unused_properties = expected_properties . difference ( used_properties ) if unused_properties : self . _Error ( "Unused pattern properties: %s" % unused_properties ) if self . expected_additional_properties != self . used_additional_properties : self . _Error ( "Unused additional properties." ) return self . num_errors == 0
Validates that |value| complies to |schema|.
Validates that |value| complies to |schema| .
"""Validates that |value| complies to |schema|.

    See _ValidateValueInternal(schema, value) for a detailed description of the
    value validation. If |enforce_use_entire_schema| is enabled, each value and
    its sub-values have to use every property of each used schema at least once
    and values with schema type 'array' may not be empty.
    Args:
      schema (dict): The JSON schema.
      value (any): The value being validated.
      enforce_use_entire_schema (bool): Whether each property hsa to be used at
        least once.
    Returns:
      bool: Whether the value is valid or not.
    """ # Check that all properties, patternProperties and additionalProperties were # used at least once for each schema.
Whether the value is valid or not.
Whether the value is valid or not .
bool
self
schema
The JSON schema.
The JSON schema .
value
The value being validated.
The value being validated .
enforce_use_entire_schema
Whether each property hsa to be used at
least once.
Whether each property hsa to be used at least once .