Bare field-map bodies, Swift's structured slot, and two re-tagged emitters

Merged
JE
4mo ago
+2419-265

Follow-up to #541, which landed the field-keyed validation contract for the wrapped {"errors": {...}} rendering and closed #527. This PR covers what that contract does not reach.

What's net-new

1. Bare (unwrapped) field-map bodies

Not every BC5 controller wraps. Four families render the same ActiveModel::Errors payload as the whole body:

render json: @webhook.errors, status: :bad_request
ControllerStatus
webhooks_controller.rb:31,48400
chats/integrations_controller.rb:32,49400
concerns/category_actions.rb:33,63 (message types)400
lineup/markers_controller.rb:32,49422

So the wire carries {"payload_url": ["is not a valid URL"]} with no errors key anywhere. Under #541's contract that extracts nothing and the caller gets a generic "validation error" — the exact failure #527 was filed about, one wire shape over.

SPEC §6 gains step 2 for the unwrapped shape, implemented in all six transports. The recognition gate is deliberately stricter than step 1's per-entry filtering, and the asymmetry is the point: an explicit errors key already declares the body's intent, so a partly malformed map is still unambiguously a field map — whereas an unwrapped body is recognizable by shape alone. Every member must be a non-empty array of non-empty strings, and the body must carry none of error, errors, or message. One non-conforming member means it is some other JSON object and must not be reinterpreted as validation detail. Each SDK pins that with a nine-case near-miss matrix.

2. Swift's structured slot — BREAKING (source)

#541 recorded the deviation in SPEC §6: "extending the .validation associated values is source-breaking for every case .validation match, so the structured slot awaits a deliberate break." This is that break.

.validation gains a fifth associated value, fieldErrors: [String: [String]]?. Swift was the only SDK where the actionable field data existed solely as a substring of a human-readable message; parity is now six for six and the deviation paragraph is retired.

Migration: every case .validation(...) match needs one more wildcard. Most call sites do not need to — BasecampError.fieldErrors reads the slot without matching the case at all.

This targets the next breaking release. v0.12.0 shipped before #541 landed, so neither that PR nor this one is in it.

3. Two re-tagged emitters

UpdateMyNote and UpdateMyPreferences move from ValidationError to FieldValidationError. Both controllers render the wrapped field-keyed shape (my/notes_controller.rb:19, my/preferences_controller.rb:20) at the current pin d0edc128, so the declared 422 schema was simply wrong — the transports already parsed it correctly, but the generated types advertised a flat {error} body the server never sends. UpdateCalendar was the only operation carrying the correct tag. Their test stubs move to the shape they now declare.

Both doc comments are reflowed so line one is a complete sentence: the TS/Ruby/Kotlin generators truncate method docs to the first line.

4. Go's raw-Client escape hatch

doRequest had no 400/422 arm — those statuses fell through to default: and surfaced as api_error with no hint and no field errors, while every generated service method went through checkResponse and got the structured treatment.

BEHAVIOR CHANGE: raw Client.Get/Post/Put/Delete callers now see code validation (exit 9) instead of api_error (exit 7) for 400 and 422. The generated service layer is unaffected.

The default: arm also drops its private struct decode for the shared parser — that decode failed whole on any unexpected member type, so {"error": {}, "message": "Payment required"} reported the generic "Request failed (HTTP 402)" and discarded both the usable message and the hint. Same bug class #541 fixed in checkResponse, still live on this path. Retryability is untouched; §7's contract is not in scope. Remaining status-mapping divergences stay tracked in #552.

5. Docs

#541 shipped no documentation. All six SDK READMEs gain a Validation Errors section, and Swift's error-handling example and case table are corrected — they would otherwise ship code that no longer compiles.

Conformance

Three cases on CreateWebhook, green in all five runners: single field, multiple fields sorted and joined, and a reserved-key body that keeps its flat message.

The single-field case was red in Go, Kotlin, and TypeScript for a reason that had nothing to do with the SDKs: all three mock servers unwrap a body that is an object with exactly one array-valued property — an accommodation for list endpoints that expect raw arrays. A single-field bare map is exactly that shape, so {"payload_url": ["is invalid"]} went out on the wire as ["is invalid"] and the fixture could never be expressed. The unwrap is now gated on a success status; error bodies go out verbatim. Ruby and Python never unwrapped.

Runners assert errorMessage by substring, so the reserved-key case pins only the positive half of that rule; the negative half is pinned exactly by each SDK's own strict-gate matrix.

Considered and declined

Rails' record-level base key renders as an ordinary field (base: Can't be undocked). bc3 has five errors.add(:base, ...) sites, but none is a proven emitter on a modeled operation, so special-casing it in six languages would be speculative surface — and #541's flattening shape is explicitly "change it everywhere or nowhere". SPEC §6 now states the rule instead: field names are data, never structure.

Verification

  • make check green (REAL_EXIT=0), make conformance green in all five runners.
  • Red-first per SDK: every bare-map suite was run against the pristine transport and observed failing (generic fallback message, empty slot) before the parser changed.
  • No provenance repin: no upstream drift is absorbed. The re-tag corrects the SDK's description of contracts already live at the current pin.

Bare-map spec modeling — a Smithy error shape that unwraps to the bare map — remains tracked in #550; this PR is transport-level recognition only.