add: version ラッパー型の任意フィールドに omitempty を付与#47
Open
fujiwara wants to merge 1 commit into
Open
Conversation
Optional pointer and slice fields (and the optional registryPasswordAction enum) in CreateParams, VersionDetail, ExposedPort and EnvironmentVariable now carry omitempty, so marshaling a wrapper value to JSON omits unset fields instead of emitting null/zero noise. bool fields (useLetsEncrypt, secret) are intentionally left without omitempty: false is a meaningful value, so it is always serialized and can be told apart from omission. Required fields (cpu, memory, scalingMode, image, targetPort, key) are unchanged. This is backward compatible: API requests are encoded through into() and the v1 (ogen) types, so the payload sent to the API is unaffected; only direct json.Marshal of the wrapper types is changed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: fujiwara <fujiwara.shunichiro@gmail.com>
8818020 to
8a241e3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
apis/versionの手書きラッパー型(CreateParams/VersionDetail/ExposedPort/EnvironmentVariable)の任意フィールドにomitemptyを付与します。registryPasswordAction(enum)cpu/memory/scalingMode/image/targetPort/key)boolフィールド(useLetsEncrypt/secret)。falseは意味のある値なので常に出力し、「未設定」と区別できるようにします動機
これらのラッパー型は、SDK 上のアプリケーションで定義ファイルの入出力(読み込み・レンダリング・差分表示など)にそのまま使えると便利です。しかし
omitemptyが無いと、未設定のフィールドがすべてnull/ゼロ値として出力されます。{ "cpu": 100, "memory": 128, "scalingMode": "manual", "fixedScale": null, "minScale": null, "image": "nginx:latest", "cmd": null, "registryUsername": null, "registryPasswordAction": "", "exposedPorts": null, "envVars": null }差分表示などではノイズが大きく、利用側で
omitempty付きのミラー構造体を定義する動機になってしまいます。omitemptyを付けると出力が最小限に保たれます。{ "cpu": 100, "memory": 128, "scalingMode": "manual", "image": "nginx:latest" }なお
boolにはomitemptyを付けていません。falseを省略すると「未設定」と区別できず分かりにくいため、常に出力します。互換性
後方互換です。API リクエストのエンコードは
into()経由でv1(ogen)型を組み立てて行われるため、API へ送信される内容は変わりません。影響するのはラッパー型を直接json.Marshalしたときの出力のみです。nullと欠落はどちらもゼロ値にデコードされるため、ラウンドトリップも変わりません。TestJSONTagsを新しい挙動に合わせて更新しています。