Skip to content

refactor(api-v1): read a project's request into a typed struct that writes its own schema (request-parser, Projects) - #247

Merged
aRustyDev merged 1 commit into
mainfrom
refactor/api-v1-projects-request
Nov 16, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
refactor/api-v1-projects-request

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

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

What changed

The same pattern as #235 and #242, for ProjectCreateRequest and PatchedProjectUpdateRequest:

  • PatchedProjectUpdateRequest (projects.rs) is the struct the parser reads into, and the document's schema is derived from it. ProjectCreateRequest is the creation's marker. The two hand-written structs in openapi.rs (about 90 lines) are removed.
  • New kinds of value in values.rs: Whole<MIN, MAX> (the months), Timezone (the 433 names is_known_timezone knows, for the parser and the document alike), AnyJson (icon_prop, schema {}), NullableProse (cover_image) and NullableUuid (the two people: read as uuid_field, not as NullableKey's pk_field; the schema is the same). The name and key lengths are core's own constants, as they already were in the old parser.

What the Projects added to the pattern

  • A creation that is not "the change plus a required list". The pin's ProjectCreateSerializer has no default_state or estimate, and ProjectUpdateSerializer has. PatchedProjectUpdateRequest::CHANGE_ONLY names the two: a creation does not read them, and Creations writes the creation's schema without them from the same list, so the parser and the document cannot differ about it.
  • Three stages. read (every key, no database, errors handed back), check_rows (a person must be a user that is there; no key names an estimate) adding to the same map, then one refuse_if_any, then validate(), which only runs when all of that was fine.

A bound that was written three times

The months' 12 was in the parser, in the document, and in core's check_project. Changing it in the struct alone made the conformance tests fail ("the schema allows 13, the route refused: months run from 0 to 12"): the typed struct had removed the drift between parser and document, and so exposed the one with core. MAX_PROJECT_MONTHS (core, projects.rs) is now the one place: the struct's Whole<0, { MAX_PROJECT_MONTHS }> and check_project both read it. That is the only change outside thrust-api-v1: a constant and the one line that uses it.

Two properties that had no test, now pinned

  • a_person_who_is_nobody_is_reported_beside_the_other_fields_that_are_wrong_and_hides_validate (8 cases): a user who is not there is reported beside the other wrong fields, and hides validate(). With the first stage refusing before the rows are checked, exactly these 8 fail and the 77 other Projects tests pass. With validate() run before the field errors are refused, these 8 fail and so do two tests that were already there (a_field_error_hides_validate, a_lead_who_is_nobody).
  • a_creation_ignores_the_two_keys_that_only_a_change_reads (8 cases): a creation that names estimate or default_state is not refused for them, and a change is, under that key. With the filter on a creation's body made a no-op exactly these 8 fail and the other 103 tests of the Projects, conformance and document binaries pass.

The wire is unchanged

  • tools/oracle-v1/schema/openapi.thrust.json regenerates byte-identical, the creation without the two change-only keys and the 433-value timezone enum included, so check-openapi.sh is unchanged.
  • 631 tests with the openapi feature and 605 without (the 16 new cases; none removed); thrust-core 1611 passed.
  • scripts/oracle-v1.sh native-memory controls is PASS (gate 162 cases, 12 failures all accepted; corpus 112 exchanges, including the 29 for Projects, 15 accepted, 0 unaccepted, 0 stale) and scripts/contract.sh native-memory main passes.
  • All 20 steps of the deps job, fmt, clippy for thrust-api-v1 with and without the feature, for thrust-core, and for the Worker's wasm32 target.

The oracle and contract results were measured on the tree before the replay onto main and again after it. Between the two, main gained #243 (the contract suite on nextest, counted from its JUnit report), which changed scripts/contract.sh, and the second run used it: the gate, the corpus and the controls are PASS with the same numbers, and contract main is 71 of 71 (nextest exit=0 passed=71 expected=71).

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

  1. MAX_PROJECT_MONTHS 12 to 13, one edit in core: the parser, core and four schema properties move together (the conformance tests stay green; the wire tests that hard-code 12 fail, as they should).
  2. CHANGE_ONLY shortened to ["estimate"]: default_state appears in the creation's schema and in what a creation reads; 4 tests fail and the committed document goes stale.
  3. icon_prop without nullable = false: the document writes oneOf [{}, null]. The conformance test does not see this (it still means "any value"); only the stale document and oasdiff do. It is the one control so far that is caught from one side and not two, and I had said "from two sides in every case" in refactor(api-v1): read a label's request into a typed struct that writes its own schema (request-parser, Labels) #242: that was wrong for this field.
  4. The two stage orders and the creation filter, above.

Not checked

  • The Worker bundle size (the feature is off there; values.rs grows by five small types).
  • 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.

Next

The Work Items: lists of uuids, two dates, the type key that needs a rename, and the priority enum written the pin's way. Then a request! macro could collapse the per-field attributes, as its own PR.

Refs: #58

🤖 Generated with Claude Code

…rites its own schema

The same pattern as the States' and the Labels', for the Projects: `PatchedProjectUpdateRequest` (projects.rs) is the struct the parser
reads into and the document's schema is derived from it; `ProjectCreateRequest` is the creation's marker. The two hand-written
structs in openapi.rs (about 90 lines) are gone.

What the Projects added to the pattern:

- A creation that is not the change plus a required list. The pin's `ProjectCreateSerializer` has no `default_state` or `estimate`,
  and `ProjectUpdateSerializer` has. `PatchedProjectUpdateRequest::CHANGE_ONLY` names the two; a creation does not read them (the
  parser filters them from its body), and `Creations` writes the creation's schema without them from the same list, so the
  parser and the document cannot differ about it. The creation's `REQUIRED` is `["name", "identifier"]`.
- Three stages. `read` (every key, no database, errors handed back), `check_rows` (a person must be a user that is there; no key
  names an estimate) adding to the same map, then one `refuse_if_any`, then `validate()`, which only runs when all of that was fine.
- More kinds of value in values.rs: `Whole<MIN, MAX>` (the months), `Timezone` (the 433 names `is_known_timezone` knows, for the parser
  and the document alike), `AnyJson` (`icon_prop`, schema `{}`), `NullableProse` (`cover_image`) and `NullableUuid` (the two people:
  read as `uuid_field`, not as `NullableKey`'s `pk_field`; the schema is the same).
- The name and key lengths are core's constants (`Text<1, { MAX_PROJECT_NAME }>`), as they already were in the old parser.

A bound that was written three times. The months' 12 was in the parser, in the document, and in core's `check_project`. Changing it
in the struct alone made the conformance tests fail ("the schema allows 13, the route refused: months run from 0 to 12"): the typed
struct had removed the drift between parser and document and so exposed the one with core. `MAX_PROJECT_MONTHS` (core) is now the one
place: the struct's `Whole<0, { MAX_PROJECT_MONTHS }>` and `check_project` both read it.

Two properties had no test, and are pinned now: a person who is nobody is reported beside the other fields that are wrong and hides
`validate()` (8 cases: `a_person_who_is_nobody_is_reported_beside_the_other_fields_that_are_wrong_and_hides_validate`), and a
creation ignores `estimate` and `default_state` while a change refuses the same values (8 cases:
`a_creation_ignores_the_two_keys_that_only_a_change_reads`). With the first stage refusing before the rows are checked exactly the
first 8 fail; with the filter on the creation's body made a no-op exactly the second 8 fail; with `validate()` run before the field
errors are refused the 8 fail and two tests that were there (`a_field_error_hides_validate`, `a_lead_who_is_nobody`) fail too.

Wire proof: `tools/oracle-v1/schema/openapi.thrust.json` regenerates BYTE-IDENTICAL, creation without the two keys and the 433-value
timezone enum included; 631 tests with the feature, 605 without (16 new), core 1611; oracle-v1 and contract.sh as in the PR.

Controls, each one edit made and reverted: `MAX_PROJECT_MONTHS` 12 to 13 moves core, the struct and four schema properties together
(conformance stays green, the wire tests that hard-code 12 fail, as they should); `CHANGE_ONLY` shortened to `["estimate"]` puts
`default_state` into the creation's schema and into what a creation reads (4 tests fail, the stale document); `icon_prop` without
`nullable = false` writes `oneOf [{}, null]`, which the conformance test does NOT see (it still means any value) and only the stale
document and `oasdiff` do. That is the one control so far caught from one side, not two.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit 54f01a2 into main Nov 16, 2026
39 checks passed
@aRustyDev
aRustyDev deleted the refactor/api-v1-projects-request branch November 16, 2026 23:45
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