Skip to content

refactor(api-v1): read a label's request into a typed struct that writes its own schema (request-parser, Labels) - #242

Merged
aRustyDev merged 2 commits into
mainfrom
refactor/api-v1-labels-request
Nov 16, 2026
Merged

aRustyDev merged 2 commits into
mainfrom
refactor/api-v1-labels-request

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

The Labels' request is now read into a typed struct, and the document's schema is derived from that struct: the second resource of the request-parser series, after the States (#235). Part of #58, which is closed; this PR does not reopen it.

What changed

The same pattern as #235, for LabelCreateUpdateRequest and PatchedLabelCreateUpdateRequest:

  • PatchedLabelCreateUpdateRequest (labels.rs) is the struct the parser reads into, and the document's schema is derived from it. LabelCreateUpdateRequest is the creation's marker, filled by Creations (openapi.rs) with PatchedLabelCreateUpdateRequest::REQUIRED, the list the parser checks. The two hand-written structs in openapi.rs are removed.
  • The bounds are types: Text<1, 255> (the name, never blank), Text<0, 255> (the colour, may be blank), Prose (the description), NullableText<0, 255> (the two external keys) and a new NullableKey (the parent: a related row's key as pk_field reads it, or null; it writes type: [string, null], format: uuid).

What is new: a field that needs the database

parent must name a live label of the project, and the parser reports every field at once, so a body is now read in two stages:

  1. read reads every key with no database (a parent as its key only) and hands back the errors it found, without refusing them;
  2. check_parent asks the database and adds its error to the same map; one refuse_if_any then answers.

Refusing after the first stage would drop a missing parent from a 400 that also names a wrong field. That property had no test. a_parent_that_is_not_there_is_reported_beside_the_other_fields_that_are_wrong pins it: five wrong fields, on a creation and on a change (10 cases). With refuse_if_any(errors.clone())? put before check_parent, exactly those 10 fail and the 44 Labels tests that were there still pass, so the suite did not hold it before. The pattern is the one Projects and Work Items will need.

The wire is unchanged

  • tools/oracle-v1/schema/openapi.thrust.json regenerates byte-identical, so check-openapi.sh is unchanged (103 findings, none unaccepted).
  • 615 tests with the openapi feature and 589 without (the 10 new cases; none removed).
  • scripts/oracle-v1.sh native-memory controls is PASS (gate 162 cases, 12 failures all accepted; corpus 112 exchanges including the 11 for Labels, 15 accepted, 0 unaccepted, 0 stale) and scripts/contract.sh native-memory main is 71 of 71. These ran before the replay onto main; main gained only docs and plans in between (nothing under crates, .github, scripts, tools or the lockfile), and git range-diff shows the commit unchanged.
  • All 20 steps of the deps job, fmt, clippy with and without the feature and for the Worker's wasm32 target, run locally on the replayed commit.

Controls (AGENTS.md rule 8), each one edit made and reverted

  1. name: Text<1, 256>: the route and both schemas move together (the committed document goes stale, the signal), and a_long_name fails.
  2. color without nullable = false: the document claims oneOf [string, null], which the route refuses; both Labels conformance tests fail and the committed document goes stale.
  3. parent without nullable = false, whose type already allows null: I expected only the stale document to catch it, and the conformance test caught it too (a schema with no type is read as "any value", and the route refuses most of those). A forgotten attribute is caught from two sides in every case I tried.
  4. The two stages made naive: the 10 new cases fail (above).

Not checked

  • The Worker bundle size (the feature is off there, and values.rs grows by one small type).
  • The book build of the docs job (mdbook-mermaid is not installed on this machine; the edits add no page or link).
  • The whole CI run.
  • One run of the default suite reported 1 leaky (a pass that left a handle open); I did not capture which test, and it did not recur in three reruns.

Next

Projects: a timezone list of about 600 values, the months' bounds, and two user relations (project_lead, default_assignee) that need the database, on the same two-stage pattern.

Refs: #58

🤖 Generated with Claude Code

aRustyDev and others added 2 commits November 16, 2026 17:11
…tes its own schema

The same pattern as the States' (the previous commit), for the Labels. `PatchedLabelCreateUpdateRequest` (labels.rs) is the struct the
parser reads into, and the document's schema is derived from it; `LabelCreateUpdateRequest` is the creation's marker, filled by
`Creations` (openapi.rs) with `PatchedLabelCreateUpdateRequest::REQUIRED`, the list the parser checks. The two hand-written structs
in openapi.rs are removed. A label's bounds are `Text<1, 255>` (the name, never blank), `Text<0, 255>` (the colour, may be blank),
`Prose` (the description), `NullableText<0, 255>` (the two external keys) and `NullableKey` (the parent).

What is new here is a field that needs the database. `parent` must name a live label of the project, and the parser reports every
field at once, so a body is read in two stages: `read` reads every key with no database (a `parent` as its key only, `NullableKey`,
which is `pk_field`'s reading and writes `type: [string, null], format: uuid`) and hands back the errors it found; `check_parent`
asks the database and adds its error to the same map; one `refuse_if_any` then answers. `read` returns the errors and does not refuse
them, because refusing after the first stage would drop a missing parent from a 400 that also names a wrong field.

That property had no test. `a_parent_that_is_not_there_is_reported_beside_the_other_fields_that_are_wrong` pins it, for five wrong
fields on a creation and on a change (10 cases); with `refuse_if_any(errors.clone())?` put before `check_parent` exactly those 10
fail and the 44 Labels tests that were there still pass, so the suite did not hold it before.

Wire proof: `tools/oracle-v1/schema/openapi.thrust.json` regenerates BYTE-IDENTICAL, so `check-openapi.sh` is unchanged; the suite is
615 with the feature and 589 without (the 10 new cases); oracle-v1 native-memory and contract.sh native-memory main as in the PR.

Controls, each one edit made and reverted: `name: Text<1, 256>` moves the route and both schemas together and fails `a_long_name`;
`color` without `nullable = false` writes a `oneOf [string, null]` that the route refuses (both Labels conformance tests fail and the
committed document goes stale); `parent` without `nullable = false`, whose type already allows `null`, was expected to be caught by
the stale document only, and the conformance test caught it too (a schema with no `type` is read as any value, and the route refuses
most of those), so a forgotten attribute is caught from two sides in every case tried.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant