npm install
node validate.js -s <SCHEMA-DIR> -d <DATA-TO-VALIDATE> -i <ID-TO-VALIDATE>
schema and ending with .jsonexample:
node validate.js -s schema3 -d payload.json -i '/sensor/v0.1/sensor.json'
“$id” and “$ref”: URLs should be relative or absolute. But here the $ids are defined relative but are refernced absolute. Example: Object with "$id": "sensor/v0.1/sensor" does reference sensor/v0.1/sensor-metadata.json which should resolve to sensor/v0.1/sensor/sensor/v0.1/sensor-metadata.json which is not intended here because only sensor/v0.1/sensor-metadata.json exists.
Solution: Move Ids and references to absolute values and remove .json postfix, i.e. "$id": "sensor/v0.1/sensor" and "$ref": "sensor/v0.1/sensor-metadata". This allows better referencing and clearer referencing of subitems.
ce_marking is defined as object with base64 encoing, at least for me this didn’t validate.ambient_operating_temperature seems to be related to ambient_operating_temperature_min and ambient_operating_temperature_max but there is no formal way, except string matching to see the relationship. In general, we have either reference it, e.g. “reference”: “/base-objects/v0.1/operation-conditions-runtime/base-objects-v0.1-operation-conditions-runtime-ambient-operating-temperature” or one can put the constraints directly into the field, e.g. use maximum and minimum field int the ambient_operating_temperature description.The corrected schema and an example payload can be found here. It can be validated by
node validate.js -s schema-orig-fixed -d schema-orig-fixed/payload.json -i /sensor/v0.1/sensor
From the analysis above, the following change proposals can be derived:
maximum and minimum for the operational valuessensor-data fields mandatory.NGSI-LD has stricter requirements than JSON-LD. It must have an id and type field and all other attributes can be Properties or Relationships. The property names are prefixed with the respective namespace:
{
"https://www.industry-fusion.org/properties/v0.1/machine_state": {
"type": "Property",
"value": "Testing"
},
"https://www.industry-fusion.org/properties/v0.1/hasFilter": {
"type": "Relationship"
"object": "urn:filter:1"
},
"id": "urn:x:1",
"type": "https://www.industry-fusion.org/types/v0.1/cutter"
}
NGSI-LD v1.6 provides 3 different forms:
The NGSI-LD object above is already an example for the Normalized Form. The Simplified Form reduces all attributes to key-value pairs like so:
{
"https://www.industry-fusion.org/properties/v0.1/machine_state": "Testing",
"https://www.industry-fusion.org/properties/v0.1/hasFilter": "urn:filter:1",
"id": "urn:x:1",
"type": "https://www.industry-fusion.org/types/v0.1/cutter"
}
This representation is not lossless, e.g. the differentiation whether an attribute is a Property and a Relationship is lost. Therefore NGSI-LD 1.6 defines a third form, the Concise Form which eliminates the redunancy of the Normalized Form but does not lose information:
{
"https://www.industry-fusion.org/properties/v0.1/machine_state": "Testing",
"https://www.industry-fusion.org/properties/v0.1/hasFilter": {
"object": "urn:filter:1"
},
"id": "urn:x:1",
"type": "https://www.industry-fusion.org/types/v0.1/cutter"
}
Apparently, to identify a Relationship, the object key is sufficient.
Finally, with help of standard JSON-LD contexts, the namespace prefixes can be managed:
{
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
{
"@vocab": "https://www.industry-fusion.org/properties/v0.1/"
}
],
"machine_state": "Testing",
"hasFilter": {
"object": "urn:filter:1"
},
"id": "urn:x:1",
"type": "https://www.industry-fusion.org/types/v0.1/cutter"
}
The Concise Form of NGSI-LD can easy be validated with JSON-Schema, when the context is ignored, as shown here.
This can be validated by
node validate.js -s schema-with-relationships -d schema-with-relationships payload.json -i https://www.industry-fusion.org/types/v0.1/cutter
node validate.js -s schema-ngsild-minimal -d schema-ngsild-minimal/payload.json -i "https://www.industry-fusion.org/types/v0.1/cutter"
ECLASS uses IRDI’s to identify types and properties. An IRDI is structured as follows:
RAI#DI#VI
Examples for ECLASS IRDI’S:
0173-1#02-BAH754#006
0173-1#01-AKJ975#017
0173-1#02-AAH880#003
Mapping IRDI’s to IRI’s is not straight forward. IRDI’s do not have an explicit prefix to identify the scheme like IRI’s (e.g. “http”, “urn”) Therefore, IFF needs to agree on a mapping scheme. One obvious mapping scheme is to wrap the IRDI into an IRI like so:
https://www.industry-fusion.org/eclass/0173-1#02-AAH880#003
With such a mapping the eclass identifiers can be mapped to NGSI-LD objects by extending the @context by an eclass prefix:
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
{
"@vocab": "https://www.industry-fusion.org/properties/v0.1/",
"eclass": {
"@id": "https://www.industry-fusion.org/eclass/",
"@prefix": true
}
}
]
Given the @context, the object containing eclass and normal fields can be described as follows:
{
"machine_state": "Testing",
"hasFilter": {
"object": "urn:filter:1"
},
"eclass:0173-1#02-AAH880#003": "10",
"id": "urn:x:1",
"type": "eclass:0173-1#01-AKJ975#017"
}
The expanded JSON-LD object looks like:
[
{
"https://industry-fusion.org/eclass/0173-1#02-AAH880#003": [
{
"@value": "10"
}
],
"https://industry-fusion.org/base/v0.1/hasFilter": [
{
"https://uri.etsi.org/ngsi-ld/hasObject": [
{
"@id": "urn:filter:1"
}
]
}
],
"@id": "urn:x:1",
"https://industry-fusion.org/base/v0.1/machine_state": [
{
"@value": "Testing"
}
],
"https://industry-fusion.org/base/v0.1/machine_state_from_smartbox": [
{
"@value": "Offline_Idle"
}
],
"@type": [
"https://industry-fusion.org/eclass/0173-1#01-AKJ975#017"
]
}
]
Validation of the eclass object works as follows:
node validate.js -s schema-ngsild-eclass/ -d schema-ngsild-eclass/payload.json -i "https://www.industry-fusion.org/eclass:0173-1#01-AKJ975#017"
ECLASS provides additional data for every IRDI which can be added/mapped to JSON-Schema:
Preferred Name is mapped to title fieldDefinition is mapped to description fieldUnit is mapped to unit fieldType of the field is mapped to datatype and xsd-type as described hereJSON type field of every ECLASS property is string.For example, the ECLASS property `` is described in the JSON-Schema as:
"eclass:0173-1#02-AAH880#003": {
"type": "string",
"datatype": "double",
"title": "min. cutting current",
"description": "specification of the minimum cutting current",
"unit": "A"
}