Schema
A Schema defines the type structure of a RelatedItem or Reading for a given NamedUserCollection. Schemas are created or updated when you create a NamedUserCollection.
All the schemas for a namespace are stored in a SchemaDefinition.
Metaschema#
The following metaschema describes all possible properties of a Schema class object, as well as the schema of each property to describe:
{ "_typeName": { "type": "string" }, "_type": { "type": "string", "enum": [ "object", "array", "string", "number", "boolean", "null", "isodate" ] }, "_properties": { "type": "object", "additionalProperties": { "$ref": "#" } }, "_description": { "type": "string" }, "_items": { "$ref": "#" }, "_required": { "type": "array", "uniqueItems": true, "items": { "type": "string" } }, "_enum": { "type": "array", "uniqueItems": true, "minItems": 1, "items": { "type": [ "string", "number", "boolean", "null" ] } }, "_relationshipTypes": { "type": "array", "items": { "type": "object", "properties": { "_isInverse": { "type": "boolean" }, "_ref": { "type": "object", "properties": { "_relatedTypeName": { "type": "string" }, "_relatedUserType": { "type": "string" }, "_relatedUserItemId": { "type": "string" } } }, "_userType": { "type": "string" }, "_description": { "type": "string" } } } }, "_readingTypes": { "type": "array", "items": { "type": "string" } }}
| Property | Type | Required | Description |
|---|---|---|---|
_typeName | String | No | A unique name for the schema, such as "Asset" or "AirQualitySensor". |
_description | String | No | A human-readable description of the schema, for example: "Schema for a door, window, or wall asset". |
_type | String | Required | The base type of the schema. Enter one of the following strings: object, array, string, number, boolean, null, isodate. |
_properties | Object | No | Defines the properties for an object-type schema. Each key is a property name and each value is another schema. This applies recursively if the _type is "object". |
_items | Object | No | Defines the schema for items in an array. Only applicable if _type is "array" and can be inline or reference-based. |
_required | Array of String | No | Specifies which properties are mandatory. All strings must be unique. Only used with _type: "object". |
_enum | Array | No | Enter an array of allowed values that are unique. The value can be of the following types with all : string, number, boolean, null. Must have at least one value. All values must be unique |
_relationshipTypes | Array of Object | No | Defines schema relationships such as foreign keys or associations. |
_isInverse | Boolean | No | Indicates an inverse direction |
_ref | Object | No | An object that contains the type name, usertype, or userItemId of the |
_relatedTypeName | String | No | Reference another schema by its _typeName. |
_relatedUserType | String | No | Reference a collection by its _userType. |
_relatedUserItemId | String | No | Reference a collection by its _userItemId. |
_userType | String | No | User-defined relationship name |
_description | String | No | Text description of the relationship |
_readingTypes | Array of String | No | Lists the schema types that represent readings or logs associated with this schema. Useful for sensors, measurements, or logs. |
For more context, see the following example:
{ _typeName: "SensorDataPoint", _properties: { measurementType: { _type: "string", _description: "The type of measurement e.g. temperature, pressure, humidity, etc" }, _sourceId: { _type: "string", _description: "Id if the sensor data point" }, unit: { _type: "string", _description: "Unit of measure, e.g. deg Celcius, PSI, etc", _enum: [ "Degrees Celsius", "Degrees Fahrenheit", "Kelvin", "PSI", "Relative Humidity", "Pascal", "Atmosphere", "Lumen" ], } }, _description: "A sensor can have more than one data points. The data points are represented in this collection as TelemetryItems. The sensors in the System Components Collection can have one to many relationships with the SensorDataPoints"}