Required fields
Updated
Learn where TEN message schemas can use required fields and how graph validation checks them.
In the TEN framework, only message schemas can include required fields. Extension properties cannot include required fields.
This means that schemas for cmd_in, cmd_out, data_in, data_out, audio_frame_in, audio_frame_out, video_frame_in, and video_frame_out can define required fields.
For message schemas, the required field is valid only in the following three locations:
- At the same level as
propertyinfoo_inorfoo_out - Inside the
propertyofresultinfoo_inorfoo_out - Within a
propertyof typeobject(for nested structures)
Examples of these scenarios are shown below.
{
"api": {
"cmd_in": [
{
"name": "foo",
"property": {
"a": {
"type": "int8"
},
"b": {
"type": "uint8"
},
"c": {
"type": "array",
"items": {
"type": "string"
}
},
"d": {
"type": "object",
"properties": {
"e": {
"type": "float32"
}
}
},
"exampleObject": {
"type": "object",
"properties": {
"foo": {
"type": "int32"
},
"bar": {
"type": "string"
}
},
"required": ["foo"] // 3.
}
},
"required": ["a", "b"], // 1.
"result": {
"property": {
"ccc": {
"type": "buf"
},
"detail": {
"type": "buf"
}
},
"required": ["ccc"] // 2.
}
}
]
}
}Use of required
Message sent from an extension
When an extension calls send_foo(msg_X) or return_result(result_Y), the framework checks msg_X or result_Y against their respective schemas in the extension. If msg_X or result_Y is missing any of the fields marked as required in the schema, the schema check fails, indicating an error.
The handling of these three scenarios is identical, though they are discussed separately:
-
If
send_foois sending a TEN command and the schema check fails:send_fooreturns false immediately. If an error parameter is provided, it includes the schema check failure error message. -
If
return_resultfails the schema check:return_resultreturns false. If an error parameter is provided, it includes the schema check failure error message. -
If
send_foois sending a general data-like TEN message, such as data, audio frame, or video frame:send_fooreturns false. If an error parameter is provided, it includes the schema check failure error message.
Message received by an extension
Before TEN runtime passes msg_X or result_Y to an extension's on_foo() or result handler, it checks whether all required fields defined in the schema of msg_X or result_Y are present. If a required field is missing, the schema check fails.
-
If the incoming message is a TEN command:
ten_runtimereturns an errorstatus_coderesult to the previous extension. -
If the incoming message is a TEN command result:
ten_runtimechanges thestatus_codeof the result to error, adds the missingrequiredfields, and sets the values of these fields to their default values based on their type. -
If the incoming message is a TEN data-like message:
ten_runtimesimply drops the data-like message.
Behavior of graph check
TEN Manager has a function called Graph Check, which is used to verify the semantic correctness of a graph. The checks related to required fields are as follows:
- For a connection, the
requiredfields of the source must be a superset of therequiredfields of the destination. - If the same field name appears in both the source and destination
requiredfields, their types must be compatible.
