Closed mrstegeman closed 4 years ago
Good question. In general I think schemas should try to constrain data types so that clients know what to expect, but I think explicitly saying that particular schemas optionally support enums to further constrain the possible values would be OK. We could make the assumption that all values support enums, but that might add quite a lot of complexity to WoT clients to cater to all possible values. What do you think?
I agree that it could add complexity to a client, but I think that's acceptable in this case. It can definitely be helpful to constrain inputs further at times.
For reference, the HAP (HomeKit) spec allows for the following constraints:
I wonder whether to simplify the web abstraction, the implementation could simply round a value to the nearest valid value. On the other hand, if the web layer knows what the valid values are it could better represent that in the UI (e.g. as a drop-down list or a stepped slider based on a step value).
I can't remember anything in JSON Schema which allows setting step values, have you come across anything like that.
What I wouldn't want to happen is that thing description authors end up specifying an enum with 256 values from 0-255 and then the UI to represent that as a drop-down list, when it would be better represented by a stepped slider.
But in general, I think it's OK to specify that particular Property schemas can optionally support an enum, and we can make sure we deal with that in the UI implementation. A Thing Description can then also provide an enum for any property, but it's up to the client to decide whether and how to render that.
From the JSON Schema spec:
6.2.1. multipleOf
The value of "multipleOf" MUST be a number, strictly greater than 0.
A numeric instance is valid only if division by this keyword's value results in an integer.
We have some examples in the spec for enums now, so closing this.
Should the following optionally support an enum to limit possible values?
Do we even need to specify that enums are acceptable for all types, or should it be optional for everything?
Inspired by mozilla-iot/gateway#1467