-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nullable class members in tl schema? #1016
Comments
In incoming requests to TDLib any object field are allowed to be null. This is up to the application and may form a correct or an incorrect request depending on other parameters. In updates and responses from TDLib for some object fields it is guaranteed that they are never null. Such fields are not marked as "may be null" in the documentation. So the correct way to add Nullable annotations is by parsing the schema and searching for "may be null" substring in the field documentation. For example, this is how it is done for our native Java bindings: td/td/generate/TlDocumentationGenerator.php Line 245 in d26cf8f
|
So, using the JSON interface, for the above object, an user might send to tdlib: {
"@type": "messages",
"total_count" : 0
} But tdlib will always send to the user: {
"@type": "messages",
"total_count" : 0,
"messages": []
} Therefore not requiring any special handling of null types since all the fields will be there with the correct type. Did I get this right? |
Any parameter can be omited when sending a request to TDLib. In that case null/false/0/'' will be used as parameter's value. In responses and updates TDLib omits only null object fields. In the
Or for
|
The documentation is quite ambiguous on this one. Since the field is called |
"may be null" can refer only to an object and for them is written in the form "; may be null". But suggestions on documentation improvements are always welcome. |
So the search shall actually be for the documentation for a field ending in "; may be null". Personally, I think the nullable annotation should have been part of the tl schema type ( Checking for |
The search for "may be null" is on purpose, because sometimes arrays also can be annotated as allowed to have null objects. Unfortunately, TL doesn't allow to mark nullable objects as such in an easy and short way, so we use the documentation comments instead for that. This isn't mentioned anywhere, because automatic parsing of the TL-schema is far beyond the scope of the Getting started guide and the JSON client usage documentation. If you need a reference implementation of the td_api TL-scheme parsing, you can use td/td/generate/TlDocumentationGenerator.php Line 100 in d26cf8f
|
Makes sense. So "may be null" for object means the object itself may be null and for vector means the contents may be null. Would there be any other meanings of "may be null"?
Understanding where something is null and where something isn't seems to me like it should be a part of the getting started, but then again, that might be just me. |
Also, I think this is basically solved at this point so I'll close the issue. |
This is absolutely correct.
This is a part of the documentation along-side other restrictions like |
How to determine from
td_api.tl
which members in a class are nullable?Take this example:
Here, the documentation specifies that "messages may be null". But how can this be determined in a concrete manner? Languages like Rust, Kotlin, Swift insist in null safety, so anything that might be nullable must be declared accordingly. Unless there is a way to determine which members are nullable, I would have to mark everything as nullable, which will be quite a bad UX.
The text was updated successfully, but these errors were encountered: