Azure / opendigitaltwins-dtdl

Digital Twins Definition Language
Creative Commons Attribution 4.0 International
478 stars 162 forks source link

Example for acutal data of type "Map" #24

Closed yphuangms closed 4 years ago

yphuangms commented 5 years ago

When define a "Property" of type "Map", how do we actually assigned / formatted value for this property? Is there any example?

{
    "@type": "Property",
    "name": "modules",
    "writable": true,
    "schema": {
        "@type": "Map",
        "mapKey": {
            "name": "moduleName",
            "schema": "string"
        },
        "mapValue": {
            "name": "moduleState",
            "schema": "string"
        }
    }
}

Does it look like this:

"modules" : [  
      { "moduleName" : "moduel1", "moduleState" : "on" }, 
      { "moduelName" : "module2", "moduleState" : "off" } 
]

Or looks like this:

"modules" : { 
      "moduel1" : "on",
      "module2" : "off"
}
briancr-ms commented 5 years ago

Great question because this isn't clear. We expect the value to look like your second example (a JSON object with the mapKey as the key and the mapValue as the value. The names in the model are provided for potential code generation scenarios where these names might be useful in different programming languages.

I'll keep this issue open until I get a chance to update the docs with a sample.

askpatrickw commented 4 years ago

Hey @briancr-ms, since it been 4 months, why not put an example in this Issue so there's a clear answer (and maybe someone can do a doc PR for you). ;-)

briancr-ms commented 4 years ago

Fixed in #70.