Repository navigation
refactor(api-v1): read a label's request into a typed struct that writes its own schema (request-parser, Labels) - #242
Merged
Conversation
…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]>
Merged
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
LabelCreateUpdateRequestandPatchedLabelCreateUpdateRequest:PatchedLabelCreateUpdateRequest(labels.rs) is the struct the parser reads into, and the document's schema is derived from it.LabelCreateUpdateRequestis the creation's marker, filled byCreations(openapi.rs) withPatchedLabelCreateUpdateRequest::REQUIRED, the list the parser checks. The two hand-written structs inopenapi.rsare removed.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 newNullableKey(the parent: a related row's key aspk_fieldreads it, ornull; it writestype: [string, null], format: uuid).What is new: a field that needs the database
parentmust name a live label of the project, and the parser reports every field at once, so a body is now read in two stages:readreads every key with no database (aparentas its key only) and hands back the errors it found, without refusing them;check_parentasks the database and adds its error to the same map; onerefuse_if_anythen 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_wrongpins it: five wrong fields, on a creation and on a change (10 cases). Withrefuse_if_any(errors.clone())?put beforecheck_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.jsonregenerates byte-identical, socheck-openapi.shis unchanged (103 findings, none unaccepted).openapifeature and 589 without (the 10 new cases; none removed).scripts/oracle-v1.sh native-memory controlsis PASS (gate 162 cases, 12 failures all accepted; corpus 112 exchanges including the 11 for Labels, 15 accepted, 0 unaccepted, 0 stale) andscripts/contract.sh native-memory mainis 71 of 71. These ran before the replay ontomain;maingained only docs and plans in between (nothing undercrates,.github,scripts,toolsor the lockfile), andgit range-diffshows the commit unchanged.depsjob, 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
name: Text<1, 256>: the route and both schemas move together (the committed document goes stale, the signal), anda_long_namefails.colorwithoutnullable = false: the document claimsoneOf [string, null], which the route refuses; both Labels conformance tests fail and the committed document goes stale.parentwithoutnullable = false, whose type already allowsnull: I expected only the stale document to catch it, and the conformance test caught it too (a schema with notypeis read as "any value", and the route refuses most of those). A forgotten attribute is caught from two sides in every case I tried.Not checked
values.rsgrows by one small type).docsjob (mdbook-mermaidis not installed on this machine; the edits add no page or link).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