Azure / opendigitaltwins-dtdl

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

Array of Enum #93

Closed Andrej-Kalocanj-Mohaci closed 3 years ago

Andrej-Kalocanj-Mohaci commented 3 years ago

Greetings,

I need to define an array of enums. The only way to do that is to target the array from Telemetry, but I don't want that cuz it's not a stream on data, it should be defined when adding a new twin and it would be best to put it in Property, but Property don't contain definition for Array.

Is there a way to do this?

Thanks for the answer. Kind regards

briancr-ms commented 3 years ago

Yes, you are right: arrays in properties are not supported in DTDL v2. There are two workarounds you could consider while we work on supporting arrays in properties:

  1. If the number of elements is known and small, you could create an object with fixed fields ("element1", "element2", etc.).
  2. If the number of elements is larger or unknown, you could use a DTDL Map to implement an array where the key values are array indexes ("0", "1", etc.). This approach would require more client code to act like an array. The storage required for this approach may be larger than an array.

We realize that neither of these workarounds is the same as supporting arrays so we are working on supporting arrays in properties in an upcoming release.