Preserve empty optional containers in Go JSON#252
Merged
Conversation
- generate MarshalJSON helpers for optional non-null array/map fields so non-nil empty values are
serialized instead of dropped by omitempty
- keep omitted fields omitted while allowing explicit [] / {} payloads for request models such as
message buttons and files
- regenerate sdk/go/generated/types.go and verify Go serialization for unset vs explicit empty buttons;
checks: cd sdk/go/generated && go test ./...
Co-authored-by: openai-codex/gpt-5.4 <noreply@openai.com>
- move generator snapshot regeneration to the repo-level scripts directory and wire the package scripts to use it instead of package-local bin/tests entrypoints - update generator snapshots and related docs after the Go optional-container MarshalJSON change so local tests and recorded outputs stay in sync - document that generator snapshot regeneration is a bulk rewrite and should be user-invoked; checks: cd packages/generator && npm test Co-authored-by: openai-codex/gpt-5.4 <noreply@openai.com>
- announce the generator change that preserves explicit empty optional containers in Go JSON via generated MarshalJSON helpers - announce the corresponding Go SDK behavior fix so changelog checks stay aligned with the published package changes on this branch - checks: bun run check:changelog Co-authored-by: openai-codex/gpt-5.4 <noreply@openai.com>
Regenerate the docs-derived outputs after adding the June 2 generator and\nGo SDK release entries.\n\nThis updates the generated updates index, adds the per-date and seasonal\nMarkdown pages, and refreshes the generated AGENTS.md guidance so CI's\ncheck-generated-sync step stays green.\n\nCo-authored-by: openai-codex/gpt-5.4 <openai-codex-gpt-5-4@models.pi.local>
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.
Summary
omitemptydropped non-nil empty container values such as message buttons[]/{}intentionallyKey changes
packages/generator/src/lang/go.ts: detect optional non-null container fields and generateMarshalJSONhelpers that reinsert non-nil slice/map values after the default
omitemptypasspackages/generator/src/lang/go.ts: includeencoding/jsonimports when generated models need the custommarshaler path
sdk/go/generated/types.go: regenerate Go models so affected request types preserve explicit emptycontainers, including message buttons/files and similar optional list/map fields
Verification
cd sdk/go/generated && go test ./...MessageUpdateRequestMessage{Buttons: [][]Button{}}->{"message":{"buttons":[]}}MessageUpdateRequestMessage{}->{"message":{}}buttons: nullvsbuttons: []while deciding onthe fix; final implementation preserves omit-vs-empty semantics and avoids sending
nullwhenbuttons were not set
References
MessageCreateRequestMessage.Buttons/MessageUpdateRequestMessage.Buttons