Azure / opendigitaltwins-dtdl

Digital Twins Definition Language
Creative Commons Attribution 4.0 International
470 stars 160 forks source link

Clarification of 'schema' property data type #184

Open dmocek opened 1 week ago

dmocek commented 1 week ago

What is the data type for a 'schema' value when the value is a DTMI reference to an Interface schema? For example, in the DTDL v3 Spec, there is this example:

{
  "@context": "dtmi:dtdl:context;3",
  "@id": "dtmi:com:example:ReusableTypeExample;1",
  "@type": "Interface",
  "contents": [
    {
      "@type": "Telemetry",
      "name": "accelerometer1",
      "schema": "dtmi:com:example:acceleration;1"
    },
    {
      "@type": "Telemetry",
      "name": "accelerometer2",
      "schema": "dtmi:com:example:acceleration;1"
    }
  ],
  "schemas": [
    {
      "@id": "dtmi:com:example:acceleration;1",
      "@type": "Object",
      "fields": [
        {
          "name": "x",
          "schema": "double"
        },
        {
          "name": "y",
          "schema": "double"
        },
        {
          "name": "z",
          "schema": "double"
        }
      ]
    }
  ]
}

Per the spec, the schema for accelerometer1 is supposed to be of a data type 'Schema' and indeed it references the Interface schema 'Object' complex schema described below it. However, the data type of the value in this property:

  "schema": "dtmi:com:example:acceleration;1"

is not a Primitive Schema nor a Complex Schema, but a DTMI reference to the Interface schema 'Object' complex schema. In the 'Complex Schema' section of the DTDL spec it states: "A complex schema can be specified directly as the value of a schema property or described in the Interface schemas set and referenced in a schema property.". What is the data type when "the complex schema is referenced in a schema property"? It seems to me that in the spec, the data type for "schema" should be either a 'Schema' (as already specified) or 'DTMI' (when it's a reference) which is a reference to an Interface schema.

jrdouceur commented 6 days ago

The datatype is 'Schema', whether it is inlined or referred to indirectly. You can see the schema type in the JSON-LD metamodel definition of DTDL v3 Telemetry, wherein the relevant parts are:

    {
      "@id": "dtmi:dtdl:class:Telemetry;3",
      "sh:property": [
        {
          "sh:path": "dtmi:dtdl:property:schema;3",
          "sh:or": [
            { "sh:class": "dtmi:dtdl:class:Schema;3" },
            { "sh:class": "dtmi:dtdl:class:Schema;2" }
          ]
        }
      ]
    }

You can also see in the DTDL Parser code that the Schema property on the DTTelemetryInfo class has type DTSchemaInfo.