Azure / opendigitaltwins-dtdl

Digital Twins Definition Language
Creative Commons Attribution 4.0 International
473 stars 161 forks source link

Are reference nodes allowed in DTDL? #132

Open jbkoh opened 2 years ago

jbkoh commented 2 years ago

Hi, there.

I'm trying to define a schema with DTDL v2. I see many fields are "required" while they can be referenced only. For example, I can globally define an Enum and refer to it by @id in other Property definitions. JSON-LD defines node reference:

A node reference is a node object containing only the @id property, which may represent a reference to a node object found elsewhere in the document.

However, in the DTDL v2 spec, @type, enumValues, and valueSchema are required which should not exist in referencing objects.

Do DTDL respect reference nodes, where the above properties should be optional), or should I always denormalize all the references?

Thanks!

rido-min commented 1 year ago

Hi @jbkoh

You can reference custom schemas and referencing those types, eg:

{
  "@context": "dtmi:dtdl:context;2",
  "@id": "dtmi:samples:customSchemas;1",
  "@type": "Interface",
  "schemas": [
    {
      "@id": "dtmi:samples:customSchemas:OffOnEnum;1",
      "@type": "Enum",
      "valueSchema": "integer",
      "enumValues": [
        {
          "name": "On",
          "enumValue": 1
        },
        {
          "name": "Off",
          "enumValue": 0
        }
      ]
    }
  ],
  "contents": [
    {
      "@type": "Property",
      "name": "myEnumOnOff",
      "schema": "dtmi:samples:customSchemas:OffOnEnum;1"
    }
  ]
}