Skip to content
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

Improve typing #102

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Improve typing #102

wants to merge 20 commits into from

Conversation

TobiasBales
Copy link
Contributor

@TobiasBales TobiasBales commented Jul 8, 2024

This bumps the # typed sigil to strict and runs srb tc in test cases.

This means some adjustments to the generated code (or quite a lot).
I would like to get initial agreement on the direction and then would do some clean up (there are definitely some simplifications possible and required).

Some things/questions/observations that come to mind:

  • The discrimator field for oneof values can be nilable (in generated code), even for required fields
  • Enums in one of fields are currently broken, the actual implementation. This was surfaced by sorbet, will fix this as a follow up PR
  • Optional fields take nilable values but then set the default value (which does not get encoded), this was also surfaced by sorbet

@tenderlove
Copy link
Contributor

"required" and "optional" refer to the encoding. If a field is "required", it means that it will always be encoded. If it's "optional", then it's only encoded if it is not the default value. (This is confusing from a user's perspective, but unfortunately that's how the spec is defined)

I think only fields that contain submessages are actually nillable. Everything else should require some kind of value.

@TobiasBales
Copy link
Contributor Author

"required" and "optional" refer to the encoding. If a field is "required", it means that it will always be encoded. If it's "optional", then it's only encoded if it is not the default value. (This is confusing from a user's perspective, but unfortunately that's how the spec is defined)

I think only fields that contain submessages are actually nillable. Everything else should require some kind of value.

Interesting.
So should the constructor not accept nil values but rather have a default value then?
And setters (for optional fields) would then also just accept the non nilable type?
Doing that would simplify some things indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants