Repository navigation
refactor(api-v1): read a project's request into a typed struct that writes its own schema (request-parser, Projects) - #247
Merged
Conversation
…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]>
Merged
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 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
ProjectCreateRequestandPatchedProjectUpdateRequest:PatchedProjectUpdateRequest(projects.rs) is the struct the parser reads into, and the document's schema is derived from it.ProjectCreateRequestis the creation's marker. The two hand-written structs inopenapi.rs(about 90 lines) are removed.values.rs:Whole<MIN, MAX>(the months),Timezone(the 433 namesis_known_timezoneknows, for the parser and the document alike),AnyJson(icon_prop, schema{}),NullableProse(cover_image) andNullableUuid(the two people: read asuuid_field, not asNullableKey'spk_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
ProjectCreateSerializerhas nodefault_stateorestimate, andProjectUpdateSerializerhas.PatchedProjectUpdateRequest::CHANGE_ONLYnames the two: a creation does not read them, andCreationswrites the creation's schema without them from the same list, so the parser and the document cannot differ about it.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 onerefuse_if_any, thenvalidate(), 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'sWhole<0, { MAX_PROJECT_MONTHS }>andcheck_projectboth read it. That is the only change outsidethrust-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 hidesvalidate(). With the first stage refusing before the rows are checked, exactly these 8 fail and the 77 other Projects tests pass. Withvalidate()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 namesestimateordefault_stateis 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.jsonregenerates byte-identical, the creation without the two change-only keys and the 433-value timezone enum included, socheck-openapi.shis unchanged.openapifeature and 605 without (the 16 new cases; none removed);thrust-core1611 passed.scripts/oracle-v1.sh native-memory controlsis PASS (gate 162 cases, 12 failures all accepted; corpus 112 exchanges, including the 29 for Projects, 15 accepted, 0 unaccepted, 0 stale) andscripts/contract.sh native-memory mainpasses.depsjob, fmt, clippy forthrust-api-v1with and without the feature, forthrust-core, and for the Worker's wasm32 target.The oracle and contract results were measured on the tree before the replay onto
mainand again after it. Between the two,maingained #243 (the contract suite on nextest, counted from its JUnit report), which changedscripts/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
MAX_PROJECT_MONTHS12 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).CHANGE_ONLYshortened to["estimate"]:default_stateappears in the creation's schema and in what a creation reads; 4 tests fail and the committed document goes stale.icon_propwithoutnullable = false: the document writesoneOf [{}, null]. The conformance test does not see this (it still means "any value"); only the stale document andoasdiffdo. 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.Not checked
values.rsgrows by five small types).docsjob (mdbook-mermaidis not installed on this machine; the edits add no page or link).Next
The Work Items: lists of uuids, two dates, the
typekey that needs a rename, and the priority enum written the pin's way. Then arequest!macro could collapse the per-field attributes, as its own PR.Refs: #58
🤖 Generated with Claude Code