OPCFoundation / UA-CloudLibrary

OPC UA Information Model database with a REST and GraphQL interface, as well as user management. The global instance of this (hosted by the OPC Foundation) can be found at https://uacloudlibrary.opcfoundation.org.
Other
37 stars 18 forks source link

GraphQL query produces invalid JSON in certain "value" attributes #172

Closed sebwiendl closed 1 year ago

sebwiendl commented 1 year ago

Hello everyone,

we found a potential issue when querying for variables via the GraphQL API, in our case for a variable of type MultiStateDiscreteType and its EnumStrings. We used this NodeSet to reproduce the issue: o6k-im-example-enumstrings.zip

Our query returns the following:

{
  "data":{
    "objectTypes":{
      "nodes":[
        {
          "browseName":"urn:openpack:information-model:type:example-enumstrings;FooType",
          "namespace":"urn:openpack:information-model:type:example-enumstrings",
          "nodeId":"nsu=urn:openpack:information-model:type:example-enumstrings;i=1003",
          "displayName":[
            {
              "text":"FooType"
            }
          ],
          "dataVariables":[
            {
              "browseName":"urn:openpack:information-model:type:example-enumstrings;BarVariable",
              "displayName":[
                {
                  "text":"BarVariable"
                }
              ],
              "engUnitNodeId":null,
              "engUnitModelingRule":null,
              "modelingRule":"Mandatory",
              "namespace":"urn:openpack:information-model:type:example-enumstrings",
              "nodeId":"nsu=urn:openpack:information-model:type:example-enumstrings;i=6001",
              "dataType":{
                "browseName":"http://opcfoundation.org/UA/;UInteger",
                "nodeId":"nsu=http://opcfoundation.org/UA/;i=28",
                "displayName":[
                  {
                    "locale":"",
                    "text":"UInteger"
                  }
                ]
              },
              "engineeringUnit":null,
              "properties":[
                {
                  "browseName":"http://opcfoundation.org/UA/;EnumStrings",
                  "arrayDimensions":"0",
                  "typeDefinition":{
                    "browseName":"http://opcfoundation.org/UA/;PropertyType"
                  },
                  "value":"{\"Value\":{\"Type\":21,\"Body\":[{\"Text\":\"Baz\"},{\"Text\":\"Bang\"}]}"
                }
              ],
              "typeDefinition":{
                "browseName":"http://opcfoundation.org/UA/;MultiStateDiscreteType",
                "documentation":"https://reference.opcfoundation.org/v104/Core/docs/Part8/5.3.3/#5.3.3.3",
                "namespace":"http://opcfoundation.org/UA/",
                "nodeId":"nsu=http://opcfoundation.org/UA/;i=2376"
              }
            }
          ],
          "superType":{
            "browseName":"http://opcfoundation.org/UA/;BaseObjectType",
            "nodeId":"nsu=http://opcfoundation.org/UA/;i=58",
            "displayName":[
              {
                "locale":"",
                "text":"BaseObjectType"
              }
            ],
            "dataVariables":[

            ],
            "superType":null
          }
        }
      ]
    }
  }
}

The issue seems to be

"value":"{\"Value\":{\"Type\":21,\"Body\":[{\"Text\":\"Baz\"},{\"Text\":\"Bang\"}]}"

as that is not a valid JSON string and cannot simply be deserialized further. A final closing } seems to be missing.

A quick check also shows, that the string from above is persisted exactly like this in the DB as well.

Best regards Sebastian

sebwiendl commented 1 year ago

Additional info regarding DB persistence:

grafik

yields the following in column Value:

grafik

All Values seem to lack the closing }.

This seems to be a issue related to all values, not just EnumStrings.

MarkusHorstmann commented 1 year ago

The issue is understood. Thank you for reporting!

A fix is in the works: https://github.com/cesmii/CESMII-NodeSet-Utilities/pull/16. Once that releases we can pick up the new NuGet in the cloud library, likely in the next few days.