Closed koalatux closed 5 years ago
Maybe you want to use the null
value to explicitly convey the information that the state is currently unknown (e.g. if the opening state determining service is temporarily offline)?
Maybe I should document the difference between "no state service implemented" and "state service temporarily unavailable / unknown state"?
Maybe you want to use the null value to explicitly convey the information that the state is currently unknown (e.g. if the opening state determining service is temporarily offline)?
Right.
Maybe I should document the difference between "no state service implemented" and "state service unavailable / unknown state"?
That would actually be nice, if we document how it is supposed to be useed and what it means if the state
field if absent compared to if state.open
is set to null
.
Maybe you want to use the null value to explicitly convey the information that the state is currently unknown (e.g. if the opening state determining service is temporarily offline)?
Doesn't most json librarys interpret a field set to null the same like it won't exist? Most languages don't make a difference between undefined and null so I'm not even sure if you would even be able to distinguish that.
Maybe I should document the difference between "no state service implemented" and "state service unavailable / unknown state"?
That would actually be nice, if we document how it is supposed to be useed and what it means if the
state
field if absent compared to ifstate.open
is set tonull
.
I would vote for set the open field to not required and also for merge the change of the state field now if we disagree about the open field and separate the changes since they are not really depending on each other.
Doesn't most json librarys interpret a field set to null the same like it won't exist? Most languages don't make a difference between undefined and null so I'm not even sure if you would even be able to distinguish that.
At least in Python accessing a JSON property set to null returns None and accessing an absent property gets you a KeyError.
In [1]: import json
In [2]: j = json.loads('{"a":"foo","b":null}')
In [3]: j['a']
Out[3]: 'foo'
In [4]: j['b']
In [5]: j['c']
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-5-92c0ce4ca33a> in <module>()
----> 1 j['c']
KeyError: 'c'
I think making option
non-nullable is worse than the status quo. Because if you want to represent the state service being unavailable, you have to omit the whole state
property, with that you will lose all metadata like the icons. Furthermore it will change the structure of the data. Having a fix data structure for an endpoint makes it easier to develop a simple script to parse a specific endpoint, because you don't have to catch all corner cases of a changing data structure.
The more important thing to consider is the stability issue. Current clients might assume the state property is always present and might crash otherwise. How important is it to not introduce breaking changes in contrast to have a clean API?
Let's sum up all the possibilities:
state
required, open
nullable (status quo)
state
optional, open
nullable (currently this PR)
state
property is available.state
optional, open
not nullable
state
property is available.Oh, sorry, i had it in my head, but appreantly didn't write it down. For me removing the null type from the open field also means to remove the required flag from it.
So it would be a fourth option:
optional
, open optional
, not nullableWhich is the same as option 2 but without the null
"hack".
There are approx 11 spaces right now who set it to null and for me it looks like all of them are just trying to get around the required problem.
curl https://api.spaceapi.io/collector | json_pp | grep "\"open\" : null" -C 5
For me the breaking changes are necessary, it's an issue that software has to adapt to it but in my eyes a different problem that we should challenge on a different level (e.g. spaces can provide different versions or something similar). Releasing versions that are fully backward compatible is not applicable for me.
I totally didn't think of that solution and I'm happy you are open to breaking changes :-) I will update the PR then.
Oh, one more thing: Can you update the CHANGELOG with the change (to be used as an upgrade guide)?
Thank you!
This fixes #40