protoc_plugin converts field names to camelCase, protobuf converts it back to snake case
- Dominant language
- Dart
- Stars
- 572
- Forks
- 196
- Avg merge
- 1h 59m
- Merged PRs (30d)
- 2
Description
protoc_plugin converts field names to camelCase: https://github.com/google/protobuf.dart/blob/9da84aef9d8126ac3da665f3c163e3cb4af31b6d/protoc_plugin/lib/names.dart#L426-L428 (in `_fieldMethodSuffix`, which, confusingly, is not really returning a suffix. It's also used as the field name as full).
The library then converts those names back to snake_case: https://github.com/google/protobuf.dart/blob/9da84aef9d8126ac3da665f3c163e3cb4af31b6d/protobuf/lib/src/protobuf/field_info.dart#L60
The problem is conversion from snake_case to camelCase is not invertible. For example, all of these snake_case identifiers are converted to the same camelCase:
- a_b_c_d
- a_b_cD
- a_bCD
So when we construct a `FieldInfo` without specifying the `proto_name` argument (it's optional) we'll get wrong `protoName` for the field in this constructor: https://github.com/google/protobuf.dart/blob/9da84aef9d8126ac3da665f3c163e3cb4af31b6d/protobuf/lib/src/protobuf/field_info.dart#L51-L65
Looking at protoc_compiler, I think we always pass a `proto_name` argument. If that's true then we should make this argument non-optional as it's otherwise a potential footgun.
Contributor guide
Research direction
Start by reading `_fieldMethodSuffix` in `protoc_plugin/lib/names.dart` and the `FieldInfo` constructor in `protobuf/lib/src/protobuf/field_info.dart`. Trace generated-field construction to verify whether `proto_name` is always supplied, then check how mixed-uppercase snake_case names are handled. Done means the field's original protobuf name cannot be silently changed through the optional argument path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100