mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
broker: state the no-null rule where an implementer will read it
The rule that omission is the only spelling of absence was already enforced in code and pinned by test, but the only prose stating it was a paragraph inside "The no-secret rule" — a section about key material. A host written in another language does not read a secrets section looking for JSON encoding rules, so the first place that implementer would learn the rule is a rejected request. Promote it to its own top-level contract section, `Optional members: omission is the only spelling of absence`, and name the concrete failure mode: a serializer that emits `null` for an unset field (Go without `omitempty`, a `None` attribute through `json.dumps`, a map that assigns the key unconditionally) produces a payload this contract rejects in full. The fix on their side is one sentence long — omit unset members — which is worth saying outright rather than leaving to be inferred from an error string. Also point at it from the HTTP binding docs, since that is where someone configures the serializer that will get this wrong, and keep the reference from the no-secret rule so the third strictness hole is still traceable from where the other two are described. Docs only; no behavior change. The anchor both links resolve to is verified present in the generated HTML, since rustdoc does not check intra-doc fragments. Requested by ss-core-02 on #6742 as the doc half of the explicit-null fix. Signed-off-by: ss-dev-00 <a02c4e0850e5e612b4ddf95dbe2f5c56467cf27c6552203bc833ff438fb31971@buzz.block.builderlab.xyz> Co-authored-by: Bradley Axen <baxen@squareup.com> Signed-off-by: Bradley Axen <baxen@squareup.com>
This commit is contained in:
@@ -16,6 +16,11 @@
|
||||
//! `200`, because the verdict lives in `status` and a second copy in the status
|
||||
//! line could only ever disagree with it.
|
||||
//!
|
||||
//! Both directions follow one JSON rule worth stating at the binding, since it
|
||||
//! constrains how an implementer configures a serializer: an optional member
|
||||
//! means absent by being **omitted**, and an explicit `null` is rejected. See
|
||||
//! [the contract docs](super#optional-members-omission-is-the-only-spelling-of-absence).
|
||||
//!
|
||||
//! A client must nonetheless **attempt to parse an envelope regardless of HTTP
|
||||
//! status**. A host or intermediary may map dispositions onto conventional
|
||||
//! statuses for observability or for middleware that cannot read bodies; if a
|
||||
|
||||
@@ -64,20 +64,41 @@
|
||||
//! inside each event object — a host cannot ship a `secretKey` beside `sig` and
|
||||
//! have it silently trimmed.
|
||||
//!
|
||||
//! A third hole was subtler and is closed the same way: `deny_unknown_fields`
|
||||
//! constrains *which* members may appear, not what they may hold, and
|
||||
//! `#[serde(default)] Option<T>` accepts an explicit `null` as `None` —
|
||||
//! indistinguishable from absent. An envelope that decides its shape from absence
|
||||
//! therefore accepted `{"status":"failed","outcome":null}` as a plain failure. So
|
||||
//! **no optional member anywhere in this contract accepts `null`**: nothing here
|
||||
//! emits one, absence is spelled by omission, and a `null` is a malformed payload
|
||||
//! rather than a second spelling with its own interpretation.
|
||||
//! A third hole was subtler and is closed the same way — see
|
||||
//! [Optional members](#optional-members-omission-is-the-only-spelling-of-absence).
|
||||
//!
|
||||
//! Two limits are worth stating. A `String` field can physically hold secret
|
||||
//! text, so keeping secrets out of message content and error messages is host
|
||||
//! policy this contract cannot enforce. And nothing stops a host from *holding*
|
||||
//! keys — that is the point; it stops one from handing them over.
|
||||
//!
|
||||
//! # Optional members: omission is the only spelling of absence
|
||||
//!
|
||||
//! **`null` is never a legal value anywhere in this contract.** Every optional
|
||||
//! member means "absent" by being **omitted from the object**. A member present
|
||||
//! with the value `null` is a malformed payload and is rejected — in a request,
|
||||
//! in a response, in `args`, in an outcome, at any depth.
|
||||
//!
|
||||
//! This matters most to a host or agent implemented in another language. Many
|
||||
//! serializers emit `null` for an unset field by default — Go's
|
||||
//! `encoding/json` for a nil pointer without `omitempty`, Python's `json.dumps`
|
||||
//! of an attribute left at `None`, a hand-built map that assigns the key
|
||||
//! unconditionally. Such a payload will be rejected in full, not quietly read as
|
||||
//! absent. Configure the serializer to **omit** unset members.
|
||||
//!
|
||||
//! The reason is that this contract decides meaning from absence, so absence
|
||||
//! cannot have two spellings. `#[serde(default)] Option<T>` maps an explicit
|
||||
//! `null` to the same value as an omitted member, which made
|
||||
//! `{"status":"failed","outcome":null}` parse as a plain failure and skip the
|
||||
//! per-status contradiction check. Rejecting `null` is stronger than recording
|
||||
//! presence beside the value, because it leaves no layer with the question of
|
||||
//! what a present-but-empty member was supposed to mean. Applied uniformly, it
|
||||
//! also removes the guess about whether `{"limit": null}` requests the default
|
||||
//! page limit or no limit at all: it requests neither, it is a malformed request.
|
||||
//!
|
||||
//! The rule is uniform, so there is nothing to look up per field: if a member
|
||||
//! carries no value, leave it out.
|
||||
//!
|
||||
//! # Ownership recursion
|
||||
//!
|
||||
//! [`Action::AgentsCreate`] has no owner field. The owner of a created agent is
|
||||
|
||||
Reference in New Issue
Block a user