components/policy/tools/schema_validator.py
def _ValidateObjectSchema(self, schema):
    """Validates a schema of type 'object'.

    If |schema| has a 'required' attribute, this method validates that it is not
    empty, only contains strings and only contains property names of properties
    defined in the 'properties' attribute.
    This method also ensures that at least one of 'properties',
    'patternProperties' or 'additionalProperties' is defined.
    If 'properties' are defined, they must have non-empty string names and
    contain a valid schema.
    If 'patternProperties' are defined, they must be valid regex patterns and
    contain a valid schema.
    If 'additionalProperties is defined, it must contain a valid schema.
    Args:
      schema (dict): The JSON schema.
    '"""
    # Validate 'required' attribute.
    if 'required' in schema:
      required_properties = schema['required']
      if not required_properties:
        self._Error("Attribute 'required' may not be empty (omit it if empty).")
      if not all(
          isinstance(required_property, str)
          for required_property in required_properties):
        self._Error("Attribute 'required' may only contain strings.")
      properties = schema.get('properties', {})
      unknown_properties = [
          property_name for property_name in required_properties
          if property_name not in properties
      ]
      if unknown_properties:
        self._Error("Unknown properties in 'required': %s" % unknown_properties)
    # Validate '*properties' attributes.
    has_any_properties = False
    if 'properties' in schema:
      has_any_properties = True
      properties = schema['properties']
      for property_name, property_schema in properties.items():
        if not isinstance(property_name, str):
          self._Error("Property name must be a string.")
        if not property_name:
          self._Error("Property name may not be empty.")
        self._ValidateSchemaInternal(property_schema)
    if 'patternProperties' in schema:
      has_any_properties = True
      pattern_properties = schema['patternProperties']
      for property_pattern, property_schema in pattern_properties.items():
        self._ValidatePattern(property_pattern)
        self._ValidateSchemaInternal(property_schema)
    if 'additionalProperties' in schema:
      has_any_properties = True
      additional_properties = schema['additionalProperties']
      self._ValidateSchemaInternal(additional_properties)
    if not has_any_properties:
      self._Error(
          "Schema of type 'object' must have at least one of the following "
          "attributes: ['properties', 'patternProperties' or "
          "'additionalProperties'].")
Validates a schema of type 'object'.

    If |schema| has a 'required' attribute, this method validates that it is not
    empty, only contains strings and only contains property names of properties
    defined in the 'properties' attribute.
    This method also ensures that at least one of 'properties',
    'patternProperties' or 'additionalProperties' is defined.
    If 'properties' are defined, they must have non-empty string names and
    contain a valid schema.
    If 'patternProperties' are defined, they must be valid regex patterns and
    contain a valid schema.
    If 'additionalProperties is defined, it must contain a valid schema.
    Args:
      schema (dict): The JSON schema.
    
Validates a schema of type 'object'.
If |schema| has a 'required' attribute, this method validates that it is not
empty, only contains strings and only contains property names of properties
defined in the 'properties' attribute.
Validates a schema of type ' object ' . If |schema| has a ' required ' attribute this method validates that it is not empty only contains strings and only contains property names of properties defined in the ' properties ' attribute .
def _ValidateObjectSchema(self, schema):
    if 'required' in schema:
      required_properties = schema['required']
      if not required_properties:
        self._Error("Attribute 'required' may not be empty (omit it if empty).")
      if not all(
          isinstance(required_property, str)
          for required_property in required_properties):
        self._Error("Attribute 'required' may only contain strings.")
      properties = schema.get('properties', {})
      unknown_properties = [
          property_name for property_name in required_properties
          if property_name not in properties
      ]
      if unknown_properties:
        self._Error("Unknown properties in 'required': %s" % unknown_properties)
    has_any_properties = False
    if 'properties' in schema:
      has_any_properties = True
      properties = schema['properties']
      for property_name, property_schema in properties.items():
        if not isinstance(property_name, str):
          self._Error("Property name must be a string.")
        if not property_name:
          self._Error("Property name may not be empty.")
        self._ValidateSchemaInternal(property_schema)
    if 'patternProperties' in schema:
      has_any_properties = True
      pattern_properties = schema['patternProperties']
      for property_pattern, property_schema in pattern_properties.items():
        self._ValidatePattern(property_pattern)
        self._ValidateSchemaInternal(property_schema)
    if 'additionalProperties' in schema:
      has_any_properties = True
      additional_properties = schema['additionalProperties']
      self._ValidateSchemaInternal(additional_properties)
    if not has_any_properties:
      self._Error(
          "Schema of type 'object' must have at least one of the following "
          "attributes: ['properties', 'patternProperties' or "
          "'additionalProperties'].")
def _ValidateObjectSchema ( self , schema ) : if 'required' in schema : required_properties = schema [ 'required' ] if not required_properties : self . _Error ( "Attribute 'required' may not be empty (omit it if empty)." ) if not all ( isinstance ( required_property , str ) for required_property in required_properties ) : self . _Error ( "Attribute 'required' may only contain strings." ) properties = schema . get ( 'properties' , { } ) unknown_properties = [ property_name for property_name in required_properties if property_name not in properties ] if unknown_properties : self . _Error ( "Unknown properties in 'required': %s" % unknown_properties ) has_any_properties = False if 'properties' in schema : has_any_properties = True properties = schema [ 'properties' ] for property_name , property_schema in properties . items ( ) : if not isinstance ( property_name , str ) : self . _Error ( "Property name must be a string." ) if not property_name : self . _Error ( "Property name may not be empty." ) self . _ValidateSchemaInternal ( property_schema ) if 'patternProperties' in schema : has_any_properties = True pattern_properties = schema [ 'patternProperties' ] for property_pattern , property_schema in pattern_properties . items ( ) : self . _ValidatePattern ( property_pattern ) self . _ValidateSchemaInternal ( property_schema ) if 'additionalProperties' in schema : has_any_properties = True additional_properties = schema [ 'additionalProperties' ] self . _ValidateSchemaInternal ( additional_properties ) if not has_any_properties : self . _Error ( "Schema of type 'object' must have at least one of the following " "attributes: ['properties', 'patternProperties' or " "'additionalProperties']." )
Validates a schema of type 'object'.
Validates a schema of type ' object ' .
"""Validates a schema of type 'object'.

    If |schema| has a 'required' attribute, this method validates that it is not
    empty, only contains strings and only contains property names of properties
    defined in the 'properties' attribute.
    This method also ensures that at least one of 'properties',
    'patternProperties' or 'additionalProperties' is defined.
    If 'properties' are defined, they must have non-empty string names and
    contain a valid schema.
    If 'patternProperties' are defined, they must be valid regex patterns and
    contain a valid schema.
    If 'additionalProperties is defined, it must contain a valid schema.
    Args:
      schema (dict): The JSON schema.
    '""" # Validate 'required' attribute. # Validate '*properties' attributes.
self
schema
The JSON schema.
The JSON schema .