def check_each_element_for_error(instance): for element in instance["elements"]: if "type" not in element: raise SchemaValidationError("Each element needs a 'type' field") found_type = element["type"] if found_type not in element_types: raise SchemaValidationError( "Element has type '%s'. Type must be one of the following: %s" % (found_type, element_types) ) try: validate_component(element) except SchemaValidationError as e: # catch the validation error and re-write the error so the user knows which element has the issue raise SchemaValidationError("%s for element of type '%s'" % (e.message, found_type))
def check_only_one_of_each_element(instance): if "elements" not in instance: return found = {} for element in instance["elements"]: if element["type"]: if element["type"] not in found: found[element["type"]] = 1 else: raise SchemaValidationError(f"Multiple elements of type: {element['type']}")
def check_each_element_for_error(instance): if "elements" not in instance: return for element in instance["elements"]: if "type" not in element: raise SchemaValidationError("Each element needs a 'type' field") found_type = element["type"] if found_type not in element_types: raise SchemaValidationError( f"Element has type '{found_type}'. Type must be one of the following: {element_types}" ) try: validate_component(element) except SchemaValidationError as e: # catch the validation error and re-write the error so the user knows which element has the issue raise SchemaValidationError( f"{e.message} for element of type '{found_type}'" # noqa: B306 )
def validate_text_component_defaults(element, found_type): data = element["settings"] if found_type == "alert-rule-action" else element optional_fields = data.get("optional_fields", []) required_fields = data.get("required_fields", []) for field in optional_fields + required_fields: if field.get("type") in TEXT_COMPONENTS: default = field.get("default") if default and default not in DEFAULT_TEXT_TYPES: raise SchemaValidationError( f"Elements of type {TEXT_COMPONENTS} may only have a default value of the following: {DEFAULT_TEXT_TYPES}, but {default} was found." )
def check_elements_is_array(instance): if "elements" in instance and not isinstance(instance["elements"], list): raise SchemaValidationError("'elements' should be an array of objects")