Keep server-sent empty lists empty, and marshal every result type in snake_case

Merged
JE
16d ago
+884-292

A list the API sends as [] reached SDK users as nil, null or a missing key, and the Go page/result wrappers marshaled under their Go names ({"BubbleUps":…,"Meta":…}). basecamp-mcp-server#344 now guards the MCP side; this fixes the SDK.

Go

  • Empty lists. Converters built lists only when len(x) > 0: subscriptionFromGenerated, the overdue report (lists appended onto nil), cards, card tables, steps, todos, schedule entries, search results, projects and templates. Now:

    • a shared mapSlice in helpers.go keeps nil as nil and turns [] into a non-nil empty slice;
    • the converters with their own loop bodies check != nil;
    • append([]T(nil), x...) copies became slices.Clone.

    On marshal, response structs' list fields are now tagged omitzero instead of omitempty: a nil list is still left out, and a preserved [] is written as []. Request types are unchanged.

  • snake_case keys. Every ...ListResult, BubbleUpsResult, ListMeta, PersonProgressResult and the other untagged result wrappers (95 fields) now have snake_case json tags.

  • Tests.

    • empty_lists_test.go runs all 78 *FromGenerated converters on JSON fixtures in which every list member, top-level or nested two levels down, is []. It checks the result is non-nil and marshals as [], covering 78 list fields. A second test parses the package and fails if a converter isn't enrolled.
    • json_tags_test.go parses the package and requires a snake_case json tag on every exported field of every exported data struct: 1,945 fields across 345 structs. Inputs (…Options, …Filters, …Fields, …Config), errors, and a named list of non-data types are exempt, each with its reason. The eventfeed and oauth subpackages aren't covered; they're connector/OAuth plumbing, not API data.
    • I checked that the sweep catches the bug: run against the old subscriptions.go, cards.go, hill_charts.go and doors.go, it reports 17 lists converted to nil.

Recording summaries (every SDK)

summarize dropped a to-do's, card's or step's "assignees": []:

  • TypeScript: length > 0
  • Ruby: the empty? arm
  • Kotlin: takeIf { isNotEmpty() }
  • Swift: isEmpty ? nil
  • Rust: skip_serializing_if = "Vec::is_empty"

All now keep []. An absent list is still left out, except in Python and Rust: Python already always wrote the key, and Rust's Vec can't tell absent from empty, so it now always writes the key too. Changing Rust to Option<Vec<_>> would break readers. Each SDK has a new test for this.

Not changed: Swift's generated CodingKeys are camelCase and depend on BaseService.encoder/decoder's snake_case conversion. Giving them raw values would break decoding through the public convertFromSnakeCase decoder.

Compatibility

No type changes. Marshal output changes in two places, both noted under Unreleased in MIGRATING.md:

  • A list the server sent as [] now encodes as [].
  • The result wrappers encode in snake_case.

Go code that tested x == nil to mean "empty" now has to test the length.


Summary by cubic

Fixes two ways Go's output drifted from the API: a list the API sends as [] now reaches SDK callers as an empty list instead of nil, null, or a missing key, and Go's page/result wrappers now marshal under the API's snake_case keys. There are no type changes, but json.Marshal output changes in two places (both noted under Unreleased in MIGRATING.md), and Go code that tested x == nil to mean "empty" must test the length instead.

Empty lists stay empty

  • Go converters build every optional list through a shared mapSlice helper (or a != nil check) so a server-sent [] stays a non-nil empty slice and an absent list stays nil.
  • Response list fields are tagged omitzero instead of omitempty, so a preserved [] marshals as [] and a nil list is still omitted.
  • Recording summaries in TypeScript, Ruby, Kotlin, Swift, and Rust no longer drop "assignees": []; only an absent list is omitted, except in Rust, which now always writes the key because a Vec can't tell absent from empty.
  • A sweep test feeds all 78 *FromGenerated converters fixtures with every list field [], including pointer-backed *[] variants, and asserts each resolves non-nil and marshals as []; it now reaches 87 list fields, and a companion test fails if a converter is added without being enrolled.

snake_case result wrappers

  • The 95 untagged fields across the page/result wrappers (...ListResult, BubbleUpsResult, ListMeta, PersonProgressResult, and the rest) gained snake_case json tags, so {"BubbleUps":…,"Meta":…} now encodes as {"bubble_ups":…,"meta":…}.
  • A source-parsing test requires a snake_case json tag on every exported field of every exported data struct — 1,945 fields across 345 structs — including embedded fields, exempting inputs, errors, and a named helper set.