Azure-Samples / digital-twins-explorer

A code sample for visualizing Azure Digital Twins graphs as a web application to create, edit, view, and diagnose digital twins, models, and relationships.
MIT License
191 stars 118 forks source link

Error when Importing DTDLs generated in IoT Central using ADT Explorer, CLI works fine #234

Open pczhao1210 opened 3 years ago

pczhao1210 commented 3 years ago

The dtdls are simple, created in Azure IoT Central and export directly, showed below:

[
  {
    "@id": "dtmi:dtdlv2:TempSensor:original;1",
    "@type": "Interface",
    "contents": [
      {
        "@id": "dtmi:dtdlv2:TempSensor:Temperature;1",
        "@type": [
          "Property",
          "Temperature"
        ],
        "displayName": {
          "en": "Temperature"
        },
        "name": "Temperature",
        "schema": "double",
        "unit": "degreeCelsius",
        "writable": true
      },
      {
        "@id": "dtmi:dtdlv2:TempSensor:Humidity;1",
        "@type": [
          "Property",
          "RelativeHumidity"
        ],
        "displayName": {
          "en": "Humidity"
        },
        "name": "Humidity",
        "schema": "double",
        "unit": "percent",
        "writable": true
      }
    ],
    "displayName": {
      "en": "TempSensor"
    },
    "@context": [
      "dtmi:iotcentral:context;2",
      "dtmi:dtdl:context;2"
    ]
  }
]

Following errors will pop up when import using ADT Explorer:

DocumentParseError: Failed to parse input. Error: jsonld.InvalidUrl: Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context. at n. (https://explorer.digitaltwins.azure.net/static/js/2.2bafa1d5.chunk.js:2:7913129) at c (https://explorer.digitaltwins.azure.net/static/js/2.2bafa1d5.chunk.js:2:7185557) at Generator._invoke (https://explorer.digitaltwins.azure.net/static/js/2.2bafa1d5.chunk.js:2:7185345) at Generator.E.forEach.e. [as throw] (https://explorer.digitaltwins.azure.net/static/js/2.2bafa1d5.chunk.js:2:7185980) at s (https://explorer.digitaltwins.azure.net/static/js/2.2bafa1d5.chunk.js:2:7898628)

Need to remove "dtmi:iotcentral:context;2" from "@context" in order to perform a successfully import using ADT Explorer.

OR using CLI, the import will success without editing the original file.

jamiewilbraham commented 2 years ago

Hi @pczhao1210 - I believe this should have been addressed in this commit https://github.com/Azure-Samples/digital-twins-explorer/commit/416aa851c24fd6b75b2c5b2dfd71bf12597318d3.

Let me know if you still see the issue!