[REQ][dart-dio] Support useOptional / patchOnly with serializationLibrary=freezed
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 42/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- dart
調査の方向性
Read the prior change in #25250 and inspect the Dart Dio generator’s Freezed templates and tests for useOptional and patchOnly; the payload does not name specific files. Prototype the proposed Freezed-specific Optional<T> serialization and check generated code for absent, explicit null, and present values, including the stated defaults and unknown enum behavior. Done when those cases work for wrapped properties while unaffected Freezed output remains unchanged.
索引モデルが issue の本文から書いたものです。
説明
Is your feature request related to a problem? Please describe.
Since #25250 added serializationLibrary=freezed (beta), useOptional and patchOnly are ignored under freezed and a warning is logged.
Freezed models declare every optional property as T? with includeIfNull: false. A PATCH body therefore cannot express the three states that partial updates need (JSON Merge Patch, RFC 7396):
| Intent | JSON |
|---|---|
| Leave unchanged | key omitted |
| Clear the field | "field": null |
| Set the field | "field": "value" |
With a plain T?, null can only mean one of the first two. Today it means "omit", so clients cannot clear a field. Switching to includeIfNull: true would instead send null for every unset field and wipe data on the server.
Describe the solution you'd like
Support useOptional / patchOnly with freezed, using the same Optional<T> API (Optional.absent() / Optional.present(value)) as the built_value and json_serializable backends:
UpdateItem(name: 'x') // {"name":"x"}
UpdateItem(name: 'x', imageId: Optional.present(null)) // {"name":"x","imageId":null}
UpdateItem(name: 'x', imageId: Optional.present('i')) // {"name":"x","imageId":"i"}
UpdateItem.fromJson({'name': 'x', 'imageId': null}).imageId // Optional.present(null)
UpdateItem.fromJson({'name': 'x'}).imageId // Optional.absent()
Proposed design (prototyped with freezed 3.2.5 / json_serializable 6.14, Dart 3.13):
- A freezed-specific
optional.dartin whichOptional<T>follows json_serializable's generic-helper protocol,Optional.fromJson(json, fromJsonT)/toJson(toJsonT). json_serializable then generates the inner conversion itself for enums,DateTime, nested models, lists and maps. Optional.absent()serializes to a private sentinel. Affected models use@Freezed(toJson: false)with a factory-level@JsonSerializable(createToJson: true), and their owntoJson()strips sentinel keys. WithouttoJson: false, freezed generates atoJson()that bypasses the stripping.@JsonKey(readValue: readOptionalValue)distinguishes a missing key from an explicitnull. json_serializable otherwise readsnullas absent.- Only models with wrapped properties change. All other freezed output, including the existing samples, is unchanged.
Decisions worth reviewing:
- Spec defaults. A wrapped property with a
defaultstarts asOptional.absent(), notOptional.present(default), because sending the default in a PATCH would overwrite server state. json_serializable currently usespresent(default). enumUnknownDefaultCase. It is not applied to wrapped enum fields, because json_serializable rejectsunknownEnumValueonOptional<Enum?>. Unknown values throw.- Binary properties are never wrapped; they are excluded from JSON anyway.
patchOnlyscope is unchanged: only schemas$ref'd directly by a PATCH request body are wrapped.- Out of scope: operation parameters (path, query, header, form) stay unwrapped, as with the other backends. Clearing a
multipart/form-datafield is not addressed, because form data has nonull.
Describe alternatives you've considered
- Reusing the shared
optional.mustache/OptionalConverter<T>. json_serializable does not apply a generic converter to concrete types such asOptional<String?>. WithserializationLibrary=json_serializableanduseOptional=true,build_runnercurrently fails withCould not generate fromJson code for ... To support the type Optional ...(separate bug report to follow). includeIfNull: falseon wrapped fields. json_serializable cannot omit a key based on its value, so this also dropsOptional.present(null).- Sending the full object (PUT-style) with
includeIfNull: true. This works only when the client always has the complete current state, sends more data, and can overwrite concurrent edits.
Additional context
Follow-up to #25250. I would like to implement this and can open a PR if the approach looks good.
- 主要言語
- Java
- スター
- 26.9k
- フォーク
- 7.8k
- 平均マージ
- 2日 10時間
- マージ済み PR(30日)
- 180
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
OpenAPITools/openapi-generator のほかの issue
-
Issue: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
OpenAPITools/openapi-generator#25643 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
OpenAPITools/openapi-generator#25640 ·
メンテナーはふだん 1 日以内に返信
-
[BUG][JAVA] Deprecated properties only get @Deprecated on the getter (base, feign, native, microprofile)対応中かも @Inf1mum が 2 日前に担当しました。 オープンIssue: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
OpenAPITools/openapi-generator#25567 ·
メンテナーはふだん 1 日以内に返信
-
[BUG][KOTLIN-SERVER] typeInfoAnnotation.mustache uses As.PROPERTY → discriminator property serialized twice対応中かも @Inf1mum が 9 日前に担当しました。 オープンIssue: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
OpenAPITools/openapi-generator#25524 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[REQ][JAVA][resteasy] Support for Jackson 3 / useJackson3対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンEnhancement: Feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
OpenAPITools/openapi-generator#25364 ·
メンテナーはふだん 1 日以内に返信
OpenAPITools/openapi-generator の issue をすべて見る
似ている issue
-
bug emitter:client:csharp
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
microsoft/typespec#12572 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
GCC 15.2: -Wcast-qual warning - cast discards const qualifier from pointer target type (H5trace.c)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 1 日以内に返信
-
[Bug] RemotingHelper.connect swaps the socket send and receive buffer configuration対応中かも @amalsaidov が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
needs-area-label
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
area/ai area/backend component/zeebe kind/task
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信