Model Validation

The Model Validation can be used to validate an event value against a model definition and take a success or failure path. This is useful in cases where data has been modeled and needs to be validated against a model definition before sending it to the data lake or other consumer.

Model Validation Stage

Model

The model to validate the event value against. The validation does no casting. For example, if an attribute value is String “123” and the model requires an integer, the validation fails. Attribute name comparison is case sensitive. Model default attribute values are injected into the payload if the attribute is missing.

Additional Properties

Controls if additional properties in the event value that are not in the model should fail or be allowed. For example, it may be important that the modeled properties be present in the event value (ex. site name) but additional data is allowed for the use case.

Examples

Assume the event value is based on an instance, and is shaped as followed.

json
{
  "pressure": 10.1,
  "speed": 90,
  "state": true,
  "locator": "line1"
}

The value is based off an instance of the Motor model, with the following definition.

json
{
        "name": "Motor",
        "attributes": [
            {
              "name": "pressure",
              "attributeType": "Internal",
              "internalType": "Real64"
            },
            {
                "name": "speed",
                "attributeType": "Internal",
                "internalType": "Int32"
            },
            {
                "name": "state",
                "attributeType": "Internal",
                "internalType": "Boolean"
            },
            {
                "name": "locator",
                "attributeType": "Internal",
                "internalType": "String",
                "required": true
            }
        ]
    }

The above payload passes the model definition. But the following variants fail.

Example, missing required field “locator”.

json
{
  "pressure": 10.1,
  "speed": 90,
  "state": true
}

Example, where speed is a float type and should be an integer.

json
{
  "pressure": 10.1,
  "speed": 90.999,
  "state": true,
  "locator": "line1"
}

Example, where an additional attribute is present and “Fail if Present” is set.

json
{
  "pressure": 10.1,
  "speed": 90,
  "state": true,
  "locator": "line1",
  "newAttribute": "this will fail validation"
}