Skip to content

Preserve empty optional containers in Go JSON#252

Merged
aenadgrleey merged 4 commits into
mainfrom
go-custom-marshal
Jun 2, 2026
Merged

Preserve empty optional containers in Go JSON#252
aenadgrleey merged 4 commits into
mainfrom
go-custom-marshal

Conversation

@aenadgrleey

Copy link
Copy Markdown
Contributor

Summary

  • preserve explicit empty arrays/maps in generated Go request JSON
  • fix the Go SDK case where omitempty dropped non-nil empty container values such as message buttons
  • keep omitted fields omitted while still allowing callers to send [] / {} intentionally

Key changes

  • packages/generator/src/lang/go.ts: detect optional non-null container fields and generate MarshalJSON
    helpers that reinsert non-nil slice/map values after the default omitempty pass
  • packages/generator/src/lang/go.ts: include encoding/json imports when generated models need the custom
    marshaler path
  • sdk/go/generated/types.go: regenerate Go models so affected request types preserve explicit empty
    containers, including message buttons/files and similar optional list/map fields

Verification

  • cd sdk/go/generated && go test ./...
  • verified Go JSON output for MessageUpdateRequestMessage{Buttons: [][]Button{}} ->
    {"message":{"buttons":[]}}
  • verified Go JSON output for MessageUpdateRequestMessage{} -> {"message":{}}
  • tested stage API behavior for message updates with buttons: null vs buttons: [] while deciding on
    the fix; final implementation preserves omit-vs-empty semantics and avoids sending null when
    buttons were not set

References

  • request model affected first: MessageCreateRequestMessage.Buttons /
    MessageUpdateRequestMessage.Buttons

aenadgrleey and others added 4 commits June 2, 2026 11:49
- 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>
@aenadgrleey aenadgrleey merged commit 79f5839 into main Jun 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant