-
Notifications
You must be signed in to change notification settings - Fork 153
Fix typespec generation for repeated fields #173
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
Fix typespec generation for repeated fields #173
Conversation
| def enum_to_spec(:TYPE_SFIXED64), do: "integer" | ||
| def enum_to_spec(:TYPE_SINT32), do: "integer" | ||
| def enum_to_spec(:TYPE_SINT64), do: "integer" | ||
| def enum_to_spec(_), do: "any" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TYPE_GROUP was the only one missing, added above ☝️. Removing this catch-all clause will make the library more strict (and brittle) in regards to the unknown future. As an alternative, we could add it back but raise a warning instead.
| def enum_to_spec(:TYPE_MESSAGE, type, true = _repeated), do: "[#{type}.t]" | ||
| def enum_to_spec(:TYPE_MESSAGE, type, false = _repeated), do: "#{type}.t | nil" | ||
| def enum_to_spec(:TYPE_ENUM, type, true = _repeated), do: "[#{type}.t]" | ||
| def enum_to_spec(:TYPE_ENUM, type, false = _repeated), do: "#{type}.t" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The label (optional, required or repeated) logic didn't seem to fit well in here, so I moved it up to the caller.
76b4ed8 to
54f1397
Compare
d4f7c42 to
922c823
Compare
|
Rebased ✅
|
Optional fields types were not including `nil` as a possible value, now they do. Repeated scalar fields were not getting wrapped in brackets, now they are.
922c823 to
89e49fb
Compare
Skip the ` | nil` on scalar fields, even when optional.
Optional when type is message and required otherwise.
|
Nice job @britto, thanks! 💟 |
Scalars were no longer getting wrapped in brackets since #140 (See #173), now they are. Also add parentheses to remote type calls with no arguments (
.t->.t()).