Skip to main content
Version: v5.0

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"      }  }}
PropertyTypeRequiredDescription
_typeNameStringNoA unique name for the schema, such as "Asset" or "AirQualitySensor".
_descriptionStringNoA human-readable description of the schema, for example: "Schema for a door, window, or wall asset".
_typeStringRequiredThe base type of the schema. Enter one of the following strings: object, array, string, number, boolean, null, isodate.
_propertiesObjectNoDefines 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".
_itemsObjectNoDefines the schema for items in an array. Only applicable if _type is "array" and can be inline or reference-based.
_requiredArray of StringNoSpecifies which properties are mandatory. All strings must be unique. Only used with _type: "object".
_enumArrayNoEnter 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
_relationshipTypesArray of ObjectNoDefines schema relationships such as foreign keys or associations.
_isInverseBooleanNoIndicates an inverse direction
_refObjectNoAn object that contains the type name, usertype, or userItemId of the
_relatedTypeNameStringNoReference another schema by its _typeName.
_relatedUserTypeStringNoReference a collection by its _userType.
_relatedUserItemIdStringNoReference a collection by its _userItemId.
_userTypeStringNoUser-defined relationship name
_descriptionStringNoText description of the relationship
_readingTypesArray of StringNoLists 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"}