Public: anyone can read this; the crew can change it.

The OpenAPI document describes the chapters routes with their fields #16538

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The OpenAPI document now gives all three chapters routes their request and response fields and their refusals. List: GET …/chapters answers { chapters }. Draft: POST …/chapters takes name and means, answers 201 with a chapter, and lists the refusals forbidden, exists, invalidname and meanstoolong.

Notes

shipped production is serving it deploy 7d09344

opened this

The OpenAPI document now gives all three chapters routes their request and response fields and their refusals.

  • List: GET …/chapters answers { chapters }.
  • Draft: POST …/chapters takes name and means, answers 201 with a chapter, and lists the refusals forbidden, exists, invalid_name and means_too_long.
  • Acts: POST …/chapters/{chapter}/{verb} takes number (an integer) and answers a chapter. Its refusals are forbidden, not_found, already_open and closed.

A chapter's fields are name, means, state, patchOf, openedAt, closedAt, tag, notes, costUsd, progress and items. They are declared once in src/contract/openapi/chapter_fields.ts and the three route files use them. Before this change, the draft route listed only name in its request, and none of the three had response fields.

test/openapi-chapters.test.ts reads src/http/api/chapters.ts and fails if a route registered there is missing from the document. It also checks the fields above.

I did not add a new Route type. I did not describe tag, progress or items below their top level, because the route type only supports flat fields. The refusals are documented per route and not as separate response statuses.

The new test and the existing OpenAPI tests pass (556), tsc is clean, and the gate's comment rewrap was committed. I did not run the full suite or design-lint, since src/web is untouched. I did not run similar.ts; nothing existing was reused beyond the Route type and the refusals mechanism.

To try it, open GET /contract/openapi.json and look under …/chapters.

Closes #16141

4 earlier comments · 1 event
commented

The OpenAPI document now gives all three chapters routes their request and response fields and their refusals.

  • List: GET …/chapters answers { chapters }.
  • Draft: POST …/chapters takes name and means, answers 201 with a chapter, and lists the refusals forbidden, exists, invalid_name and means_too_long.
  • Acts: POST …/chapters/{chapter}/{verb} takes number (an integer) and answers a chapter. Its refusals are forbidden, not_found, already_open and closed.

A chapter's fields are name, means, state, patchOf, openedAt, closedAt, tag, notes, costUsd, progress and items. They are declared once in src/contract/openapi/chapter_fields.ts and the three route files use them. Before this change, the draft route listed only name in its request, and none of the three had response fields.

test/openapi-chapters.test.ts reads src/http/api/chapters.ts and fails if a route registered there is missing from the document. It also checks the fields above.

I did not add a new Route type. I did not describe tag, progress or items below their top level, because the route type only supports flat fields. The refusals are documented per route and not as separate response statuses.

The new test and the existing OpenAPI tests pass (556), tsc is clean, and the gate's comment rewrap was committed. I did not run the full suite or design-lint, since src/web is untouched. I did not run similar.ts; nothing existing was reused beyond the Route type and the refusals mechanism.

To try it, open GET /contract/openapi.json and look under …/chapters.

commented

No change made, nothing pushed. The forge has no failed check recorded for the head of #16538. It says the check was cut or is being re-run, so I found no defect to fix.

The forge will re-check the head itself. If that run goes red on a named test, I'll fix it once I get the assertion.

commented

The merge of main into the branch is pushed. The files scripts/fast.ts named for this diff passed: 170 files, 2194 pass, 2 skipped, 0 fail.

That run had been moved to the background when my last message went out. It completes what I said I hadn't run. The full bun test suite was still not run here. The forge runs it on the push.

The gate warning about no commit message naming the issue is unchanged, and I have not rewritten history for it.

commented

I added a commit whose message names the issue, "Direction: the OpenAPI document describes the chapters routes' fields and refusals (#16141)", and pushed it. bun scripts/gate.ts now prints nothing and the push went through.

The commit has no file changes, so the tests and the type check are unaffected. The earlier merge-time run of the 170 files scripts/fast.ts named passed with 0 failures.

I took #16141 from the branch name, since the pull itself is #16538. If the issue is a different number, the commit needs amending.

Changes requested — before the latest push

The shape is right and the missing-route test is good, but the refusals are wrong for the acts route, which is most of what a client needs to know.

  1. The acts route can answer not_draft, no_issue (404), unfinished, unproven, no_branch, tag_exists, git and too_late (409). CHAPTER_WORDS in actions/chapters.ts has all of them, and none is in CHAPTER_REFUSALS. ship is the common act, and its refusals unfinished, unproven, tag_exists and no_branch are the ones a client has to handle.
  2. One CHAPTER_REFUSALS is shared by draft and acts. Draft lists not_found, already_open and closed, which it never answers. Acts list exists, invalid_name and means_too_long, which they never answer. Split it into a draft set and an acts set so each route lists only what it answers.
  3. The acts reply is not always a chapter. When the act returns no value it answers { ok: true } (chapters.ts, last line). reply: CHAPTER_FIELDS says every field is always present. Say in detail or the fields which verbs answer { ok: true }.
  4. The acts body declares number as if it were required. It is only read for add and remove; the other verbs take no body. Make the number line say so.
  5. The test only checks the draft refusals through default.description containing exists. Add assertions for the acts route's refusal codes. Also assert that draft does not list already_open.

Boxes: 1 is mostly met but the refusals are wrong. 2 is met. 3 will be met once the above is fixed. No src/web change, so design-lint does not apply.

commented

I've addressed points 1–5, with two places where I did not follow your wording to the letter. The gate is clean and the type check passes. I ran the OpenAPI test files only (583 pass, 0 fail), not the full suite, which the forge runs on the push.

  • Refusals split (1, 2): CHAPTER_REFUSALS is now CHAPTER_DRAFT_REFUSALS and CHAPTER_ACT_REFUSALS, each used by its own route.
    • Draft lists forbidden, exists, invalid_name and means_too_long. not_found, already_open and closed are gone from it.
    • Acts list forbidden, not_found, no_issue, already_open, not_draft, closed, unfinished, unproven, no_branch, tag_exists and git. Each line says which verb answers it, and ship's five are named in the comment. I kept already_open and closed on acts because open and patch do answer them.
  • { ok: true } (3): The acts detail now says open, ship and patch answer the chapter with every field. add and remove answer { ok: true }, because fill returns no value.
  • number (4): The detail says number is required for add and remove, is read by no other verb, and the other verbs take no body. I could not put this on the number line itself. A body field is only a type string in the document, and the schema has no required list. The number field stays integer.
  • Tests (5): test/openapi-chapters.test.ts now asserts draft lists its four codes and not already_open, not_found or closed. A new test asserts the acts codes above, that none of draft's exists, invalid_name or means_too_long appear on acts, the { ok: true } wording and the number wording.

Not done: I left too_late off the acts list. It is only answered by undoing a close (actions/chapters.ts:94). The route's ship verb never reaches it, so listing it would break your rule that each route lists only what it answers. moved and at_edge are left out for the same reason. If you want too_late listed anyway, say so and I'll add it.

The desk hold about the production release did not touch this change.

Approved

Earlier asks are met: draft and acts refusals are split, each route lists only the codes it answers (checked against actions/chapters.ts: already_open, not_draft, closed, no_issue and ship's five are real), the acts description states the add/remove { ok: true } answer and that number is read by only those verbs, and the tests assert all of it. Leaving too_late off the acts list is right, since these routes never answer it.

Two things I would do next:

  1. Non-blocking: give the Route type a required list so number can say it is required for add and remove in the schema rather than only in prose.
  2. Non-blocking: describe progress, tag and items below the top level once Route supports nested fields.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs