w3c / wot-scripting-api

Web of Things (WoT) Scripting API
http://w3c.github.io/wot-scripting-api/
Other
42 stars 28 forks source link

fix(InteractionOutput): don't require schema.type in value function #534

Closed JKRhb closed 8 months ago

JKRhb commented 10 months ago

At the moment, the value function of the InteractionOutput interface requires the type field of its schema to be set. In a discussion over at https://github.com/eclipse-thingweb/node-wot/issues/1221, we identified this as a problem for several different scenarios, including the exloreDirectory method, as the things property of the Thing Description Directory API specification does not contain a type field itself, as there are two different types that can be obtained from the property (namely, an array or an object of TDs).

Therefore, this PR proposes changing the algorithm to not throw anymore when the field should be null or undefined, making it usable in more scenarios.


Preview | Diff

JKRhb commented 10 months ago

Very good points, @relu91, thank you. You are right, this definitely requires more work, especially when it comes to the "check data schema" algorithm. Could we maybe refer to something already defined by JSON Schema here?

relu91 commented 9 months ago

Call 05/02:

JKRhb commented 9 months ago

I've now tried to incorporate oneOf, enum, default, and const into the check data schema algorithm in 0f00764cce6f813ba8c168bab682eef1d6791037. There are at least two aspects of the algorithm that we could discuss in the call later today – I marked these with TODO comments in the HTML document.

JKRhb commented 9 months ago

Edit: This comment has been moved to https://github.com/w3c/wot-scripting-api/issues/546

Regarding the use cases, please find a brief first attempt (that definitely needs more work) for the four terms below:

oneOf

Relevant when a device described by a TD offers two different representations of the same resource (e.g., a property or an action output). A concrete example is the things property in the Thing Description Directory API, where – depending on the URI variable format – the directory can return TDs either as an array or a "collection", i.e. as part of a JSON object.

const

As a developer, I might want to specify that a Thing always returns a certain value when an action is performed. A simple example could be a value like "Success". Combined with oneOf, we could describe that an interaction (in this case an action) always either returns "Success" or "Operation failed" like so:

{
  "actions": {
    "exampleAction": {
      "output": {
        "oneOf": [
          {
            "const": "Success"
          },
          {
            "const": "Operation failed"
          }
        ]
      }
    }
  }
}

default

As a developer, I want to save bandwidth, especially in resource-constrained environments. Therefore, I want to be able to specify a default value that has to be assumed by a TD consumer if the response sent after an operation has been completed does not contain a value.

enum

As a developer, I want to constrain the values that are valid as an interaction output to a set of values. This could be used to describe the allowed states of a smart light ("on" or "off"), for example.

relu91 commented 9 months ago

Call 19/02:

relu91 commented 8 months ago

From 04/03: