Refactor role handling: Introduce JsonPartialRole and PartialRole for improved deserialization - #413
Conversation
…terface for improved deserialization
|
Thanks, could you explain why this is even needed? There are many cases in which Discord returns some partial objects, and it so far worked that we just used default values for the omitted properties. That way we don't introduce an additional complexity when it is not needed. |
Suppose an invite grants an Administrator role. Discord sends the id, the name, etc. but deliberately does not send permissions. Then if NetCord constructs a normal Role from that payload you can write Permissions.NoneThat statement is false. Discord did not tell us that the role has no permissions, it told us nothing about its permissions. It's just a semantic problem. Additionally the existing Role is documented as “Represents a role in a guild” and exposes all of those properties as if they were authoritative. So defaulting leaks through the public API as apparently real data. There is also precedence: PartialGuildUser, for example, explicitly represents a guild user lacking GuildId and methods depending on it, while GuildUser derives from it. That said, if NetCord intentionally treats omitted fields this way and prefers keeping one model for the "same" conceptual Discord object, then I agree this may be more complexity than the library wants. As to why this specific class drew my attention, I was just checking recent api changelog entries against NetCord and found this mismatch, and the implementation is very small. |
|
I think your concerns are generally valid, nobody wants to get invalid data. Are you sure there are no more cases in which returned roles are partial in the API? Also I think ideally it should be Also |
I think this could become awkward because PartialRole is an |
Not awkward at all, |
…type and use `partial` keyword for the class declaration
…r correct documentation inheritance
|
The documentation preview is available at https://preview.netcord.dev/413. |
Removed duplicate GenerateAlias attribute for Role in ModifyGuildRoleAsync method.
…redundant XML comments, and move JsonPartialRole to a separate file
|
@KubaZ2 this is now fully ready |
No description provided.