Connhex JSON Schema fields
JSON Schemas used by Connhex Resources can specify one or more utility fields to get additional functionalities without adding code. All of the following fields are supported by client modules
Location field
A location field can used to register a street address. It is defined as:
{
"connhex": {
"type": "location",
"autocomplete": true
}
}
By setting autocomplete
to true
, you're telling Connhex Resources to provide autocomplete functionality through Google Maps Places Autocomplete 1. Here's an example for an address
field:
{
"address": {
"type": "object",
"title": "address",
"properties": {
"text": {
"type": "string",
"title": "Formatted text address"
},
"lat": {
"type": "number",
"title": "Latitude"
},
"lng": {
"type": "number",
"title": "Longitude"
}
},
"connhex": {
"type": "location",
"autocomplete": true
}
}
}
Colorpicker field
You can display a colorpicker by setting the type property accordingly.
For example, suppose a tag
resource has a color
property. Here's a JSON Schema configuration to automatically display a colorpicker for the color
field:
{
"schema": {
"$id": "https://connhex.com/compiuta/tag.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"label": {
"type": "string",
"title": "Label"
},
"color": {
"type": "colorpicker",
"title": "Color"
}
}
}
}
Image field
Connhex Resources supports base64 images. You can define an image attribute as:
"connhex": {
"type": "image"
}
Suppose a we want to display a logo
for an installation
. This can be easily achieved with:
{
"schema": {
"$id": "https://connhex.com/compiuta/installation.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"logo": {
"type": "object",
"title": "Logo",
"properties": {
"base64": {
"type": "string",
"title": "Base64 image"
}
},
"connhex": {
"type": "image"
}
}
}
}
}
Model reference
References link schemas together, defining either one-to-one or one-to-many relationships.
One-to-one relationships
A one-to-one relationship with a resource with id $id
is defined by:
{
"connhex": {
"id": "$id"
}
}
For example, suppose a device belongs to a plant:
{
"schema": {
"$id": "https://connhex.com/compiuta/device.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"serial": {
"type": "string",
"title": "Serial",
"readOnly": true
},
"plant": {
"type": "string",
"title": "plant",
"connhex": {
"id": "plant"
}
}
}
}
}
One-to-many relationships
A one-to-many relationship is defined exactly like a one-to-one, but the
"connhex": {
"id": "$id"
}
object is enclosed in an array of strings.
For example, suppose you can assign tags to a device resource:
{
"schema": {
"$id": "https://connhex.com/compiuta/device.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"serial": {
"type": "string",
"title": "Serial",
"readOnly": true
},
"connhexId": {
"type": "string",
"title": "ConnhexId",
"readOnly": true
},
"notes": {
"type": "string",
"title": "Notes"
},
"tags": {
"type": "array",
"title": "tags",
"items": {
"type": "string",
"connhex": {
"id": "tag"
}
}
}
}
}
}
- a separate Google Maps API key is needed.↩