node-wot icon indicating copy to clipboard operation
node-wot copied to clipboard

action and event affordance do not raise error when data schema does not match

Open VigneshVSV opened this issue 1 year ago • 3 comments

I have an action with the following schema:

"sample_get_method": {
      "title": "sample_get_method",
      "forms": [
        {
          "href": "https://LAPTOP-F60CU35D:8083/spectrometer/ocean-optics/USB2000-plus/get-example",
          "op": "invokeaction",
          "htv:methodName": "GET",
          "contentType": "application/json"
        }
      ],
      "safe": true,
      "idempotent": true,
      "synchronous": true
    },

When i invoke this action in node-wot


console.log("action with return value", await spectrometer.invokeAction("sample_get_method"));
console.log("action with return value awaited", await (await await spectrometer.invokeAction("sample_get_method").value())

here the spectrometer object refers to the node-wot client which I create after consuming the TD.

I get the output

action with value InteractionOutput {form: {…}, schema: undefined, dataUsed: false}
action with value undefined

I was told it would be better if it throws an error similar to how readProperties work - to complain that the schema didnt match.

the td-playground validator does not also complain the absence of input/output schema i.e. td is accepted, but action (also event) reply dont produce error because schema is not matching due to its absence?

VigneshVSV avatar May 02 '24 17:05 VigneshVSV

Hi, any update on this?

VigneshVSV avatar Jul 22 '24 12:07 VigneshVSV

Just for clarification. The TD does not mention any output for the action, right? The server code returns data or does not return any data? I am not 100% sure about the problem nor about the expectation...

danielpeintner avatar Jul 23 '24 08:07 danielpeintner

I re-read the issue. I think I get it now, the absence of output schema for actions indicate no return value from the server. The absence of input schema can indicate no requirement of a payload to be sent to invoke the action. Therefore, the current way of accepting actions without an input or output schema is fine.

However, for events, if there is no "data" field specified, and since events always have a payload, is it possible to throw a warning if a "data" field is not specified?

I can clarify further with an example if necessary.

VigneshVSV avatar Sep 25 '24 19:09 VigneshVSV

Events do not need to have a payload. The event can be called buttonPressed and with longpolling, whenever the button is pressed, you get a 200. Not saying this is the best way but it is possible at least.

egekorkan avatar Sep 25 '24 20:09 egekorkan

Ah okay!! then this issue can be closed because there is inherent meaning in not having a schema as well.

VigneshVSV avatar Sep 25 '24 20:09 VigneshVSV