validate default= is published in op docs but never applied to a JSON body
The cause is wider than that op. `applyDefault` is reached only from `DecodeValues`, which the router uses for GET query strings and POST forms. A JSON body goes straight through `json.NewDecoder` into the struct in `decodeIn` and never sees a validate tag. `ops.Descriptor` publishes the default regardless, so every op with `default=` on any field documents a behaviour that does not happen for JSON callers. That is 185 ops sharing one codec.
A second, narrower bug in the same tag was fixed alongside it: `applyDefault` had cases for int, uint and float and none for bool, so `default=1` on a bool was dead on EVERY path, not just JSON.
Why this is worth its own change rather than a footnote: a default that applies on one transport and not another is the kind of difference nobody checks for, because the documentation is the same in both. The web form never showed it because the form handler sets the field explicitly on every submit.
Options, roughly in order of how much they cost:
1. Stop publishing a default that cannot be honoured — narrowest, and it makes the documentation true, but it leaves the tag misleading to whoever writes the next op. 2. Apply defaults on the JSON path by decoding into a map first to learn which keys were absent, then into the struct. Correct and uniform, and it touches the codec every op shares, so it wants doing deliberately rather than as a side effect. 3. Make absence explicit in the op, as team.member now does: a pointer field, where nil means the caller did not mention it. Correct per-op, no codec change, but it has to be remembered every time — the same shape of hazard as a rule that lives at 185 call sites instead of one.
The immediate case is fixed by 3 on branch absent-means-keep, which also gave applyDefault its Bool case and taught setField and fieldSchema about pointers. This ticket is for the codec question that fix deliberately did not answer.
Related, and the reason the pointer mattered more than the default: team.member is an upsert, so a plain bool could not tell "set this false" from "I did not mention it". A caller changing an owner's caps without naming `owner` demoted them and got ok back.
Fixed by landing e2a0b712, deployed — option 2 from this ticket: the codec change, so all 185 ops get it at once.
This one is verified by tests, not on production, and I'm saying so up front. Every op carrying a default= is either a GET, where defaults already worked, or a write that would change real state (team.member, adding a mirror). I didn't want to make a real change just to observe one. What the tests cover, through the real router:
- an omitted field takes its declared default (bool
default=1-> true, intdefault=50-> 50) - an explicit zero is kept:
{"listed": false, "limit": 0}comes through as false and 0 - a key sent in different case still counts as present:
{"Listed": false}.encoding/jsonmatches field names without regard to case, so a case-sensitive check would have overwritten this value. I confirmed this test fails when the lowercasing is removed. - a pointer field stays nil, which keeps the upsert's "you didn't mention it" meaning intact
- the form path behaves as before
Whether a field is absent is decided from the keys actually in the body, not by checking whether the decoded value is zero.