GetUpcomingSchedule renders reduced partials, so give it reduced shapes (#635, #641, #644)

Merged
JE
4mo ago
+5892-753

Closes #635. Closes #641. Closes #644.

GetUpcomingSchedule declared the shared ScheduleEntry and a half-modelled Assignable, but BC3 renders the report through purpose-built calendar partials that write their own keys instead of rendering recordings/_recording. The published contract promised fields the endpoint does not send.

Two commits: the projection (#635 + #641), then the empty response examples (#644).

The failure, stated precisely

Any populated window — a response carrying at least one schedule entry, recurring occurrence, or assignable. Not "every live response": an empty three-array envelope decodes fine on any contract, and a call with no window is a bodiless BC3 400 before a body exists.

Red proof, run against main in a throwaway detached worktree. swift test exit 1, 4 failures and 1 pass:

Test Case '-[BasecampTests.UpcomingScheduleRedProofTests testWindowWithOneScheduleEntryDecodes]' started.
/private/tmp/.../red-main/swift/Sources/Basecamp/Services/BaseService.swift:76: error: -[BasecampTests.UpcomingScheduleRedProofTests testWindowWithOneScheduleEntryDecodes] : failed: caught error: "DecodingError.keyNotFound: Key 'type' not found in keyed decoding container. Path: scheduleEntries[0].bucket. Debug description: No value associated with key CodingKeys(stringValue: "type", intValue: nil) ("type")."
Test Case '-[BasecampTests.UpcomingScheduleRedProofTests testWindowWithOneScheduleEntryDecodes]' failed (0.027 seconds).
	 Executed 5 tests, with 4 failures (4 unexpected) in 7.523 (7.525) seconds

The other three failures are the same error at recurringScheduleEntryOccurrences[0].bucket, assignables[0].bucket, and on the fully-populated envelope. testEmptyWindowDecodes passed — that is the half that pins the claim.

bucket.type is the first key a strict decoder reaches, ahead of all six top-level members the calendar entry partial drops.

Per-SDK behaviour before this change

SDKBefore
SwiftThrew. ReportsService returns the typed content; BaseService decodes strictly and rethrows unwrapped.
KotlinDid not throw, and could not. reports.kt returned JsonElement and decoded decodeFromString<JsonElement>, so no contract was enforced on this operation at all.
TypeScriptTyped the members non-optional — a compile-time lie, undefined at runtime.
Go, Python, RubyLenient: zero value / absent key.

Commit 1 — the projection (#635, #641)

Six dedicated shapes, named after the owning report the way Draft* and MyAssignment* already are: UpcomingScheduleEntry, UpcomingAssignable, UpcomingScheduleBucket, UpcomingSchedulePerson, UpcomingAssignableParent, UpcomingAssignableCompletion.

A reduced projection is not a subset. Verified key by key against the partials:

schedules/calendar/_entry.json.jbuilder — relative to ScheduleEntry it drops created_at, updated_at, title, inherits_status, parent, description_attachments, description, bookmark_url, subscription_url, comments_url, join_url, highlighted, boosts_count, boosts_url; narrows bucket to id + name; and adds recurring, which no other schedule-entry projection emits. Every key is unconditional — there is no if in the partial — so every member is @required.

schedules/calendar/_assignable.json.jbuilder — the assignable half was under-modelled and wrong, and a ScheduleEntry-only fix would have left Swift throwing:

  • bucket omits required type — the same nested omission
  • parent omits required app_url, type, url — it is {id, title} only, and the title is todolist_or_group_title, which folds the grandparent list title in as "List: Group"
  • BC3 emits content; the SDK modelled title — the one field callers actually want was permanently absent, while a key that is always present went unmodelled
  • eight further always-present keys were unmodelled: status, visible_to_clients, completion_url, completed, repeating, comments_count, plus the partial's one conditional key, the completion block
  • type is the lowercase short recordable name (todo, card, step), not the CamelCase type other projections carry
  • completion_url is only absolute on the to-do branch: BC3 renders bucket_step_completions_path for everything else, and a _path helper emits no host

recurring is modelled, and it discriminates the two envelope arrays: BC3 selects schedule_entries with recurrence_schedule IS NULL and recurring_schedule_entry_occurrences with it NOT NULL.

All three envelope arrays are @required — reports/schedules/upcoming/index.json.jbuilder writes all three keys unconditionally, so an empty window is three empty arrays rather than a missing key.

Both window parameters are @required. Reports::Schedules::UpcomingController#index calls date_range_from_params, whose date_from_params does Date.strptime(params.require(name).to_s, …); the controller rescues ActionController::ParameterMissing and Date::Error into head :bad_request. An unbounded call has never worked. BadRequestError joins the operation's error list because a malformed-but-present date still 400s.

Go returns the reduced types through aliases (type UpcomingScheduleEntry = generated.UpcomingScheduleEntry, …) instead of converting them into full ScheduleEntry/Assignable values. Converting is what hid the mismatch: it compiles happily while zero-filling every field the endpoint never sends, so a missing created_at reads back as "" and nobody learns the response never carried it. Aliasing removes the conversion, so the spec is the only place the shape is stated.

Kotlin now returns the typed projection. The generator's findUnderlyingEntitySchema resolves one entity per response, so an object-of-arrays envelope had no single answer and fell through to JsonElement. A new opt-in branch (TYPED_ARRAY_ENVELOPE_OPERATIONS) emits a @Serializable result class when every property of the response object is an array whose items $ref a known entity; the emitter falls back to JsonElement rather than emitting something wrong if that stops holding. GetOverdueTodos also satisfies the structural test today and is deliberately not opted in — retyping is a Kotlin source break, and its renderer has not been verified.

#641 rides along, with three members rather than the two in its title: url, highlighted and status, all permitted by Schedules::Entries::BaseController#base_schedule_entry_params / Recording::StatusParam#status_param (which on create accepts drafted|active|archived|trashed). The read/write spelling split is preserved exactly: the join link is url on write and join_url on read, because recordings/_recording claims the url key for the recording's own API URL and the entry partial renders after it. Sending join_url on write is silently dropped by strong parameters.

Conformance — why this shipped

grep -rn "upcoming\|UpcomingSchedule" conformance/ exited 1. Zero coverage. The only two tests that touched the endpoint were worse than none: ruby/test/basecamp/services/reports_service_test.rb stubbed {"entries": [...]} — a top-level key BC3 has never sent — and asserted only that a Hash came back.

Added conformance/tests/upcoming_schedule.json: four cases (normal entry, recurring occurrence, assignable, empty envelope), dispatched independently by all six runners, with bodies read out of the partials. Each runner returns a flat summary of the decoded envelope, so the assertions read values back through each SDK's own model rather than off the wire body; Go and TypeScript resolve a responseBody path as a top-level key only, which is why the summary is flat rather than nested.

Also added: spec/fixtures/schedules/upcoming.json under the check-fixture-coverage manifest (validated against the generated schema, with element-level targets for all six new components), the corrected Ruby test, and new tests in Go, Swift, Kotlin, TypeScript and Python.

Two bugs found on the way, both fixed here:

  • conformance/runner/ruby/runner.rb's dig_path did current[key] || current[key.to_sym], so a present false read as a miss and fell through to nil. A responseBody assertion on a boolean field could never have seen false.
  • Go typed UpcomingScheduleEntry.starts_at/ends_at as time.Time, which cannot parse the bare date an all-day entry sends. Added to the FlexibleTime pass alongside ScheduleEntry.

Commit 2 — response examples that contradict their own schemas (#644)

Under a validator that checks each projected example against its projected schema, 7 of 10 fail on main — not the 8 the issue names:

FAIL ListRecordings 200 ListRecordings_example1: {} is not of type 'array' at []
FAIL ListRecordings 200 ListRecordings_example2: {} is not of type 'array' at []
FAIL ListRecordings 200 ListRecordings_example3: {} is not of type 'array' at []
FAIL UpdateSubscription 200 UpdateSubscription_example1: 'count' is a required property at []
FAIL UpdateSubscription 200 UpdateSubscription_example2: 'count' is a required property at []
FAIL GetTodolistOrGroup 200 GetTodolistOrGroup_example1: 'app_url' is a required property at []
FAIL GetTodolistOrGroup 200 GetTodolistOrGroup_example2: 'app_url' is a required property at []
checked=10 failures=7

Two corrections to the issue's premise, both load-bearing for #638:

  1. The GetTodolistOrGroup pair fails too. Its example value is {"result": {…}} against a schema that is a bare Todolist. So the "2 currently validated" figure counts the two that are in the failure list.
  2. The three UpdateProjectAccess examples pass, vacuously. ProjectAccessResult declares no required members, so {} satisfies it. Those are the 3 absent from the failure list.

Declaring output is not sufficient, which is the other half of the correction. The converter emits the Smithy output node verbatim, and restJson1 forces that node to be the wrapper structure. Adding an output to UpdateSubscription alone produced {"subscription": {…}} against a bare Subscription schema — trading an empty-object contradiction for a wrongly-wrapped one.

So the fix has two parts:

  • BareResponseExampleMapper mirrors BareObjectResponseMapper/BareArrayResponseMapper onto the examples. Those two rewrite only components.schemas; the examples live under paths and nobody unwrapped them. It reuses their own shouldTransform predicates so the three cannot drift on which schemas count as wrapped, and runs first (order 90) because the wrapper property name is only readable while the schema is still wrapped. It also drops an example with nothing to unwrap rather than publishing {}, so declaring input-only @examples stays legitimate and simply stops emitting a response example.
  • Faithful outputs for ListRecordings, UpdateProjectAccess and UpdateSubscription. TrashRecording is parameters-only and needs neither.

After: checked=10 failures=0.

Two consequences worth naming:

  • The jsonAdd pointers injecting Todolist.color into the GetTodolistOrGroup examples now end /value/color, not /value/result/color. jsonAdd is applied after the mappers, so a pointer still naming result rebuilds the wrapper that was just removed — as a sibling object holding only color, with no color on the body. Caught by observation, not by reasoning; the comment in examples.smithy records it.
  • spec/smithy-bare-arrays's own tests could not run. The project targets Java 11 and asked for JUnit 6, which publishes only a JVM-17 variant, so ./gradlew test failed at compileTestJava and nothing reported it — make check only ran publishToMavenLocal. Three test cases had drifted out of agreement with the mappers in the meantime (they still asserted an operation-name prefix rule and an inline-object case the mappers stopped honouring). Pinned to JUnit 5, corrected those three, and wired smithy-mapper-test into check-targets so it cannot go quiet again.

Verification

  • make check green, with REAL_EXIT=0 grepped out of a captured log and PRE_SHA == POST_SHA around the run.
  • All six SDK suites and all six conformance runners execute the four new cases. Swift and Kotlin genuinely executed, not UP-TO-DATE.
  • Operation count re-derived from behavior-model.json: 247, unchanged. This PR adds shapes and members, not operations.

Deliberately not in this PR

ScheduleEntry.join_url / .highlighted should now be @required. They were optional because GetUpcomingSchedule shared the shape and rendered the reduced partial. That reason is retired here, so both are now under-modelled rather than correctly modelled: every operation that still returns ScheduleEntry renders schedules/entries/_entry, which emits both unconditionally. Tightening them (join_url required-and-nullable, highlighted plain required) changes five other operations and forces every inline schedule-entry stub across six SDKs to carry the keys, so it belongs in its own reviewable diff. The member docs and SPEC §5 now say this outright instead of restating the retired reason.

Three other instances of the same defect class, found by the sweep #635's closing instruction asked for. Reported separately rather than absorbed — none is the same shape family.


Summary by cubic

Fixes GetUpcomingSchedule to return BC3’s reduced calendar projections and makes all SDKs decode typed results; also unwraps and corrects response examples to match their schemas. Addresses #635, #641, and #644.

  • Refactors

    • Added UpcomingScheduleEntry, UpcomingAssignable, and related types; envelope arrays are required; entries include recurring and a reduced bucket.
    • GetUpcomingSchedule now requires window_starts_on and window_ends_on.
    • Updated SDKs to use the new shapes and enforce required params: Swift (typed Upcoming*), Kotlin (UpcomingScheduleResult for array-envelope responses), Go (aliases for reduced shapes; starts_at/ends_at use types.FlexibleTime), TypeScript/Python/Ruby (method signatures updated).
    • CreateScheduleEntry accepts url, highlighted, and status (write url; read join_url).
    • Unwrapped response examples via BareResponseExampleMapper and added faithful outputs; fixed example pointers and enabled mapper tests.
    • Added a shared upcoming-schedule fixture and conformance tests across all SDKs.
    • Go: guard empty upcoming window bounds locally with clear errors; thread url/highlighted/status through the public CreateScheduleEntryRequest to the request body.
    • Ruby generator: fix YARD @param continuation to avoid trailing whitespace; added tests.
    • SPEC: updated schedule-entry write cases to 11 and documented the new create cases; fixed a related test comment.
  • Migration

    • Pass both window_starts_on and window_ends_on to reports.upcoming in all SDKs (Go now rejects empty bounds locally).
    • Read upcoming data from UpcomingScheduleEntry/UpcomingAssignable (e.g., use content for assignables; recurring exists on entries; bucket has id and name only).
    • Expect type changes: Swift arrays now [UpcomingScheduleEntry]/[UpcomingAssignable]; Kotlin returns UpcomingScheduleResult (not JsonElement); Go parses starts_at/ends_at as types.FlexibleTime and supports url/highlighted/status on create.