Closed JKRhb closed 8 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?
Call 05/02:
oneOf
const
enum
default
? (related to https://github.com/w3c/wot-scripting-api/issues/537)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.
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:
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.
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"
}
]
}
}
}
}
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.
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.
Call 19/02:
From 04/03:
At the moment, the
value
function of theInteractionOutput
interface requires thetype
field of itsschema
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 theexloreDirectory
method, as thethings
property of the Thing Description Directory API specification does not contain atype
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
orundefined
, making it usable in more scenarios.Preview | Diff