One flat Todolist replaces Todolist, TodolistGroup and TodolistOrGroup
Todolist, TodolistGroup and the TodolistOrGroup union were three declared shapes for one wire body. They are now one flat Todolist structure, returned by every operation that used to carry any of them: the polymorphic GET/PUT, the todoset-scoped list, and group-list / group-create / group-get. No operation retains a stale shape.
Operation count is unchanged at 240 — a shape consolidation, not a surface change.
Why the union was a lie
BC3 has no group model. app/views/api/todolists/groups/index.json.jbuilder and show.json.jbuilder both render todolists/_todolist.json.jbuilder — the same partial the list routes use. So a group is a Todolist whose parent is a Todolist, it reports "type": "Todolist" (the shared recording partial emits recordable_type), and it carries description/description_attachments like any list.
The oneOf envelope the spec declared never appears on the wire, and each SDK worked around it differently:
| SDK | Workaround the oneOf forced |
|---|---|
| Go | Re-decoded resp.Body by hand at three sites, bypassing AsTodolistOrGroup0/1 entirely |
| TypeScript | A three-level guard stack ending in an outright refusal of the group arm |
| Swift | A hand-written two-arm decoder with an arm-masking guard, built in #574 to replace a synthesised Codable that decoded the flat body into two nil members and reported success. At this branch point the surviving loss is narrower: the todolist arm modelled no group_position_url, so a group read silently dropped it, and ListTodolistGroups returned the group-only projection, so every group in a list came back with its description dropped |
| Kotlin | The generator fell through to an untyped JsonElement, defended by a hand-written contentOrNull coercion guard |
| Ruby / Python | Arm-sniffing over %w[todolist group] before every read |
TodolistOrGroup was the only union in spec/basecamp.smithy and the only oneOf in openapi.json, so the Swift generator's whole union emitter — arm collection, envelope-first decode, the earlierOnlyKeys arm-masking guard in both snake and camel spellings, PermissiveKey — went with it.
Ground truth (bc3 source, not inference)
app/views/api/recordings/_recording.json.jbuilder—json.type recording.recordable_type⇒"Todolist"for both variants.app/views/api/recordings/_rich_text.json.jbuilder— emitsdescriptionanddescription_attachmentsunconditionally, with noif.app/views/api/todolists/_todolist.json.jbuilder—if recording.parent.todoset?emitsgroups_url,elseemitsgroup_position_url. Strict either/or; exactly one is always present.app/controllers/todolists_controller.rb—Todolist.new params.require(:todolist).permit(:name, :description, :track_todolist), reached for a group too (SetRecordableresolves.todolists.find(id), and a group is a Todolist recording). Sodescriptionis permitted and persisted for groups.
description nullability finding
The brief asked this be verified at implementation time rather than assumed either way. Answer: description is @required and never null.
_rich_text.json.jbuilder emits json.set! attribute, format_api_content(rich_text), and format_api_content → call_pipeline (app/helpers/content_helper.rb:127-134):
def call_pipeline(pipeline, content, options = {})
content = content.to_html if content.respond_to?(:to_html)
if content.present?
pipeline.call(content, pipeline_options.merge(options))[:output].to_s.html_safe
else
""
end
end
A blank or nil rich text takes the else branch and yields "". The key is still emitted; the value is an empty string, never null (nil.respond_to?(:to_html) is false, so a nil rich text falls straight through). So it is required and non-nullable — not required-and-nullable, and the jsonAdd ["string","null"] treatment used for SearchResult.content is not warranted here.
description_attachments is likewise never null: the partial emits rich_text&.downloadable_attachments.to_a, which is [] when there is no rich text. Both bc3 doc examples confirm on the wire: "description": "", "description_attachments": [].
Migration table
| Was | Is | Notes |
|---|---|---|
union TodolistOrGroup { todolist, group } | removed | the only union in the spec |
structure TodolistGroup | removed — use Todolist | same wire body all along |
list TodolistGroupList | removed — use TodolistList | |
GetTodolistOrGroup → TodolistOrGroup | → Todolist | flat; nothing to unwrap |
UpdateTodolistOrGroup → TodolistOrGroup | → Todolist | |
ListTodolistGroups → [TodolistGroup] | → [Todolist] | now carries description |
CreateTodolistGroup → TodolistGroup | → Todolist | |
Todolist.description optional | @required, non-nullable | |
| — | + group_position_url (optional) | group half of the structural discriminator |
| — | + color (optional, nullable) | always emitted; JSON null when unset — the ["string","null"] union is applied through jsonAdd |
| — | + comments_app_url (optional) | in-app comments URL |
Discriminate structurally, never on type — it reads "Todolist" for both variants. groups_url present ⇒ a to-do list (parent is a Todoset). group_position_url present ⇒ a group (parent is a Todolist). They are mutually exclusive and exactly one is always present.
Fixtures corrected
typescript/tests/services/todolistGroups.test.tsusedtype: "Todolist::Group", which the wire never emits — that string is a webhook recording type that leaked into an API fixture.spec/overlays/examples.smithydeclaredtype: "TodolistGroup"on the group example and wrapped both examples in the envelope.spec/fixtures/todolist_groups/{get,list}.jsoncarried nodescription,description_attachmentsorgroup_position_url.spec/fixtures/manifest.yamlgainstodolist-group-getas a secondTodolistrepresentative, so the coverage invariant now forces a group fixture to keep carrying the required fields and the nullablecolor.
Two findings the brief did not anticipate
- I dropped
app_todos_urlfrom the consolidated shape and the Go lane caught it. Rewriting the structure lost the member; it was absent fromopenapi.jsonand from all six generated models while BC3 still renders the key and every fixture still carried it. Restored and regenerated — a field-level property diff ofTodolistold-vs-new now shows exactly+color +comments_app_url +group_position_urland nothing dropped. Worth naming because a consolidation's failure mode is silent subtraction, and only a lane that had to compile against the model noticed. colorandcomments_app_urlare unconditionally emitted, not conditional._todolist.json.jbuildercallsjson.colorin both branches of itstodolist_group?conditional, andjson.comments_app_urlsits outside everyif. Both stay optional — the weaker, safer claim — whilecoloradditionally carries the null union (see the review section below). Tightening either to@requiredis a defensible follow-up.positionis the one recording-level key that is genuinely absent sometimes (if recording.positioned?). It is already optional; no change.
Guards: deleted vs retained
The one thing this PR must not be misread as. An earlier comment on #544 said the untyped SDKs' guards "become deletable" once the shape is flat; that was formally corrected, and acting on it would have reintroduced the data-loss class #574 spent eleven review passes closing. A flat Smithy shape changes what the API returns; it does not hand any SDK a decoder it did not already have.
Deleted — the machinery that existed because of the oneOf, in the SDKs that have decoders:
| SDK | Deleted |
|---|---|
| all six | the envelope-arm rung (requireArmObject / _require_arm / require_arm / arm selection) |
| Go | all three hand-rolled json.Unmarshal(resp.Body, …) bypasses — resp.JSON200/JSON201 decode the flat shape directly now; replaceTodolistOrGroup returns a decoded Todolist instead of bytes |
| Kotlin | the whole untyped JsonElement read path: requireJsonObject, JsonObject.writableString, malformedField, the contentOrNull rationale block, and five now-unused kotlinx.serialization.json imports |
| Swift | the generator's entire oneOf emitter (~157 lines: arm collection, envelope-first decode, the earlierOnlyKeys arm-masking guard in both spellings, PermissiveKey, enveloped encode), plus todolist(from:operation:) and testUnionMaskingGuardMatchesMultiWordKeys |
| TS / Kotlin / Swift | dead TodolistGroup entries in three generator alias tables, and the removed TodolistGroup TS public type export |
Retained in TypeScript, Python and Ruby — every one, re-expressed against the flat body. Their generated returns are Promise<Todolist> (erased at build), dict[str, Any], and a raw Hash: no runtime validation on any route, flat or enveloped.
| Guard | Why it survives a flat shape |
|---|---|
| body-shape | a 2xx can still be a scalar, null, or an array; typeof [] === "object", so Array.isArray is the only thing keeping an array out, and Ruby's body["name"] on a String is a substring match that returns a plausible wrong value instead of raising |
| required-field | name is presence-validated by BC3, so absent/null/"" off the wire is malformed — not a value to write back over the real name on a full-replace endpoint |
| field-type | ?? "" / || "" / or "" rule out erasure, not corruption: a number, bool, array or object rides verbatim into the PUT |
| caller-value provenance | TodolistFields is erased/mutable; an edit closure assigning 42 walks straight into the PUT. Same value, caller origin ⇒ usage error, not API error |
| error rendering | must never throw while explaining a failure — circular structures, throwing toJSON, arbitrary inspect/repr |
| no-write-on-failure | every refusal still asserts zero PUTs |
Their path shortens from object → object → scalar to object → scalar — two rungs, not zero. Making those three structurally safe is #578 and is explicitly not in scope here.
Go, Kotlin and Swift keep exactly one hand-written guard each, for the thing no decoder can catch: an empty name off the wire. "" is a valid String, BC3 presence-validates the field, and writing it back on a full-replace endpoint blanks the real name.
Go: the withheld group composite, re-anchored
TestTodolistGroupsService_ShipsNoMergeSafeComposite failed the build if TodolistGroup ever gained a Description field. It now has one — TodolistGroup is a type alias for Todolist — so that reason has expired.
The composite is still not built, for a smaller and still-true reason: the other five SDKs expose no group write at all, and todolists.Update already addresses this exact route through what is now literally the same Go type. Building it would widen a cross-SDK asymmetry rather than close a gap. The guard was re-anchored on that reason rather than deleted, and now pins type identity with two teeth — a package-level var _ Todolist = TodolistGroup{} (two named struct types are never assignable in Go, so this stops compiling the instant the alias becomes a struct) and a reflect.TypeFor comparison carrying the cold-readable explanation.
Red proofs
Every lane proved its new tests fail against the pre-change behaviour, in scratch copies — no tracked file was left mutated.
Ruby — the data-loss class, made literal. Pre-change extension + the new tests; the old arm lookup wrote a decoy wrapper's description over the record and reported success:
6) Failure:
TodolistsServiceTest#test_update_reads_the_flat_body_not_a_nested_group_key
--- expected
+++ actual
@@ -1 +1 @@
-{"name" => "Renamed list", "description" => "<p>Ship the hardware</p>"}
+{"name" => "Renamed list", "description" => "<p>Decoy description</p>"}
Ruby — proof the retained body-shape guard is load-bearing. require_hash stubbed to a pass-through; the String-body substring hazard raises nothing at all:
1) Failure:
TodolistsServiceTest#test_refuses_a_string_body_whose_text_contains_the_field_names
Basecamp::ApiError expected but nothing was raised.
Swift — the group projection dropping description in a list:
XCTAssertEqual failed: ("nil") is not equal to ("Optional("<p>Phase one hardware work</p>")") - the list elements must keep the description the group projection dropped
Kotlin — the required field is decoder-enforced now:
kotlinx.serialization.MissingFieldException: Field 'description' is required for type with
serial name 'com.basecamp.sdk.generated.models.Todolist', but it was missing at path: $
Go — the group decode, against a projection that does not populate the new fields:
todolist_groups_test.go:229: Description: got "", want "<div>Phase one hardware work</div>" — BC3 renders a group through todolists/_todolist.json.jbuilder, so it carries one like any list
todolist_groups_test.go:236: GroupPositionURL: got "", want "https://…/todolists/groups/1069479600/position.json" — a group's parent is a Todolist, so this is the variant marker
Go — the re-anchored guard's compile tooth, with the alias respelled as a defined type:
pkg/basecamp/todolist_groups_test.go:551:18: cannot use TodolistGroup{} (value of struct type TodolistGroup) as Todolist value in variable declaration
Conformance
New conformance/tests/todolists_read.json: list-read, group-read, group-list-read. The responseBody assertions read the SDK's re-serialized decoded value, so a decoder that yields nothing fails them rather than silently returning it.
All six runners dispatch both new operations — Go, TypeScript, Ruby, Python, Kotlin, Swift. ListTodolistGroups returns the first decoded element by a convention stated in the fixture itself, and every runner fails loudly on an empty list rather than letting the assertions pass vacuously.
Each lane also captured a red proof with its dispatch removed, e.g.:
=== todolists_read.json ===
FAIL: list-read: … Expected no error, got: unknown operation: GetTodolistOrGroup
FAIL: group-read: … Expected no error, got: unknown operation: GetTodolistOrGroup
FAIL: group-list-read: … Expected no error, got: unknown operation: ListTodolistGroups
Correction to a premise in the brief: an undispatched conformance operation does not silently skip. Four lanes independently verified their runner's default/else arm raises (unknown operation: …), which the noError assertion turns into a loud FAIL — Go, TypeScript, Ruby, Python, and Kotlin (UnsupportedOperationException). The dispatch was needed either way, but the hazard model is "red CI", not "silent green".
Verification
make check green, with the head pinned on both sides of every run. The round-1 run:
PRE_SHA=6013ddd64941c1e1df2c273bf1967e4c8fe4d909
REAL_EXIT=0
POST_SHA=6013ddd64941c1e1df2c273bf1967e4c8fe4d909
All 47 CI checks passed on that commit. The branch was then rebased onto a newer main, so the final head is b2a924e5 and the gate was re-run against it — a run whose PRE_SHA and POST_SHA disagreed was discarded rather than reported, because a make check that straddles a rebase has tested neither head.
Per-SDK, from that run: TypeScript 79 files / 1282 tests; Ruby 1245 runs / 29741 assertions / 0 failures; Swift Executed 335 tests, with 0 failures (it genuinely ran on this macOS host — not a SKIP line); Python + mypy clean; Go ok across all five packages. Kotlin's > Task :basecamp-sdk:jvmTest carried no FROM-CACHE/UP-TO-DATE suffix in this run, so its tests executed here too; independently, a forced --rerun-tasks --no-build-cache run reported 458 tests / 0 failures.
Conformance across all six runners, 0 failures anywhere: Go 169, Kotlin 170, TypeScript, Ruby 160, Python 171, Swift 170. The three new cases PASS in every one.
Working tree is clean after the gate — no typescript/package-lock.json dirt (#612), and the two timestamp-only generated files (ruby/lib/basecamp/generated/metadata.json, typescript/src/generated/metadata.ts) were restored rather than committed. ruby/lib/basecamp/generated/types.rb is committed: its diff is real content, not a timestamp.
Review round 1 — both findings were real, both fixed
P1, reject absent descriptions before merge-safe writes. Correct, and it was the same data-loss class this PR exists to remove — one rung lower than the envelope. Making description @required and never-null is precisely what invalidates the old tolerant read: if a GET omits the key or returns null, collapsing it to "" and then PUTting that in a full replace erases a description the caller never mentioned.
Fixed in TypeScript, Python, Ruby and Go. The subtlety worth naming is that presence and non-emptiness are two different claims, and the existing required flag conflated them:
name— BC3 presence-validates the attribute, so absent,nulland""are all malformed.description— BC3 permits a blank one, andformat_api_contentrenders it"". So absent andnullare malformed, but""is a real value that must round-trip untouched.
Reusing the old flag for description would have rejected every description-less list — the ordinary case. Each SDK now separates the two claims explicitly.
Go needed a different answer: generated.Todolist.Description is a plain string, so absent, null and a real "" are indistinguishable once decoded. The check is therefore made against the raw response bytes before the struct is used, threaded through a getWithBody variant of Get. Kotlin and Swift already reject the missing field at decode and needed nothing.
P2, model the null color value in OpenAPI. Also correct, and the defect was mine: I documented that color is emitted on every projection with a JSON null when unset, shipped a manifest'd fixture carrying "color": null, and then modelled it as a non-nullable String. The published schema contradicted my own fixture, and check-fixture-coverage did not catch it because it only null-checks required fields.
color now carries the ["string", "null"] union through jsonAdd in spec/smithy-build.json, the same treatment SearchResult.content and SearchType.key get.
I did not take the second half of that suggestion (also making it @required), and the reasoning is worth recording rather than just declining. Requiredness and nullability are separable, and only one of them was broken:
- Nullable-vs-not was the defect — uncolored lists and groups violated the published type. Fixed.
- Required-vs-optional is a truthfulness refinement.
@requiredis the stronger claim, and it obliges every captured body and every inline test stub in the three typed SDKs to carry the key. I tried it: Smithy also refuses anullfor a@requiredmember inside@examples(the null union exists only in the OpenAPI projection), so the group example would have had to advertise a color that uncolored groups do not have. That trades a real correctness win for a worse example and a wide stub churn on a cosmetic field.
Optional-and-nullable is the weaker, safer claim: it accepts an explicit null and an absent key, so nothing that BC3 actually sends can violate it. The field's doc comment records that the key is in fact always emitted and that tightening it is a clean follow-up.