protocolbuffers / protocolbuffers/protobuf-javascript
[JavaScript] Getters returning nulls instead of default values for primitives
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 471
- フォーク
- 91
- 平均マージ
- 3時間 57分
- マージ済み PR(30日)
- 2
説明
What language does this apply to?
JavaScript
Describe the problem you are trying to solve.
Currently, all generated getters for primitives in _pb.js files call to jspb.Message.getFieldWithDefault and there seem to be no way to tell generator to simply call jspb.Message.getField instead.
This is particularly problematic when using proto2 syntax with required/optional numeric fields. If an optional field is not set, it will default to "0".
Describe the solution you'd like
Ideally there would be an option passed to the js_out parameter of protoc where we could say whether or not to use defaults.
Describe alternatives you've considered
One could potentially leverage hasMyField() to determine if the field has been set or not, but it would make the mapping layer between proto and internal app model even more verbose, as this would need to be done on all optional fields, which we have quite a few.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、jspb.Message.getFieldWithDefault を呼び出す生成済みのプリミティブ getter と、js_out パラメータの解析方法を追跡します。ジェネレーターに既存のオプション処理と、存在する場合は getter 生成のテストを確認します。オプショナルなプリミティブ getter が未設定の値を保持するかどうかを、ドキュメント化されたオプションで制御でき、proto2 の数値フィールドに対するカバレッジがあることを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100