microsoft / vscode-dtdl

Digital Twins Definition Language extension for VSCode
https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-dtdl
MIT License
23 stars 16 forks source link

Support Relationships created by Central #91

Open rido-min opened 3 years ago

rido-min commented 3 years ago

Repro Steps

Create a Device Template in Central Select Edge Device Export the device template Extract each of the interfaces to a different file

Expected: No errors since those are valid DTDL files Observed:

The DTDL extension complains about the Relationship:

image

Although the files passes the .NET parser validations

Exported file ```json [ { "@id": "dtmi:p8pl7l5ly:capabilitymodel:mybouqmfzo;1", "@type": "Interface", "contents": [ { "@id": "dtmi:p8pl7l5ly:capabilitymodel:mybouqmfzo:SamplePnPModule;1", "@type": [ "Relationship", "EdgeModule" ], "displayName": { "en": "SamplePnPModule" }, "maxMultiplicity": 1, "name": "SamplePnPModule", "target": [ "dtmi:p8pl7l5ly:SamplePnPModule;1" ] } ], "displayName": { "en": "Azure IoT Edge Capability Model mybouqmfzo" }, "@context": [ "dtmi:iotcentral:context;2", "dtmi:dtdl:context;2" ] }, { "@id": "dtmi:p8pl7l5ly:SamplePnPModule;1", "@type": "Interface", "displayName": { "en": "Module SamplePnPModule" }, "@context": [ "dtmi:iotcentral:context;2", "dtmi:dtdl:context;2" ] } ] ```
rido-min commented 3 years ago

@jrdouceur the parser does not complain, so I was assuming it's a valid DTDL. (asking before looping Central folks)

cschormann commented 3 years ago

The target is not supposed to be an array, I thought?

jrdouceur commented 3 years ago

There are two squigglies here. The first is because VSCode does not recognize EdgeModule as a type. DTDL allows undefined co-types, so this is valid according to the language definition. I think VSCode is correct to flag this in an authoring situation because it is unlikely that someone writing DTDL in VSCode will intentionally refer to an undefined adjunct type. But it is permitted in the language.

The second squiggly is because the "target" value is an array. This is also fine, according to the language definition. Only one value is permitted for "target" but according to JSON-LD there is no difference between a single-value array and the value itself. They both yield the same RDF triples. So, I think VSCode should accept this.

rido-min commented 3 years ago

RE adjunct types. Should we flag this issue as a Warning instead of an error? same as in #88 RE Arrays in target: This seems like a bug so I've created #93

Will keep this one open until we clarify which conditions should be flagged as a Warning instead of an error.

jrdouceur commented 3 years ago

Agreed on both points. Warning seems perfectly appropriate for unrecognized adjunct types. Disallowing a JSON array for target is a bug.