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

openapi.json describes what each route answers #17917

opened this in answer to

Merged 24h 36m ago, live in production

/api/v1/openapi.json now gives full request and response schemas for the repo and conversation routes the Apple app uses. A new test calls each route and checks its real answer against its schema. Type check passes and the openapi, contract, feature-doc and guide tests pass (731).

Notes

opened this

/api/v1/openapi.json now gives full request and response schemas for the repo and conversation routes the Apple app uses. A new test calls each route and checks its real answer against its schema. Type check passes and the openapi, contract, feature-doc and guide tests pass (731). I did not run the full suite. I ran the dead-code and hollow tests, and they pass.

What changed

  • A route's row can now carry response and request as JSON Schema, in plain data built with src/contract/openapi/schema_kit.ts. When set, they replace the old thin reply and body listing.
  • The schemas are named under components.schemas and each operation points at them with $ref. They live in src/contract/openapi/schemas/: pull.ts, repo.ts, conversation.ts, diff.ts.
  • Routes covered:
    • Contents and branches: contents (directory or file), commits (list and one), branches.
    • Issues: one issue and its comment.
    • Pulls: list, one pull (all ~45 fields, including the structured diff), files, checks, line reviews, verdicts, comment and merge.
    • Writes and conversations: POST contents, POST edits, conversations (list, create, patch) and POST conversation/messages.
  • Fixes the test found:
    • The pull's diff is a structured object (files, hunks, numbered lines), not a string.
    • ahead and behind on branches can be null.
    • POST issues/{n}/comments answers 201, but its row said 200. The row now says 201.
  • Slices: ?tag= slices keep only the schemas their operations reach (schemasReached in src/contract/served.ts). The pulls slice is still larger, about 55 KB against 44 KB before, so I raised its test cap from 45 KB to 60 KB.
  • Tests changed: test/contract-openapi-tags.test.ts (that cap, and slice components are now cut to what they reach). test/openapi-oa-pull-checks.test.ts now checks the checks schema through its $ref, because the schema gained why and looks.

Drift guard

  • test/openapi-schemas.test.ts makes real calls and validates the answers and the request bodies it sends with a strict checker (test/helpers/json_schema.ts).
  • The checker fails on a field the schema doesn't name, so a field a handler gains without a schema line fails by name.
  • The published schemas stay open (extra properties allowed), so the forge can add a field without breaking a generated client.

Not done

  • The schemas are written by hand and held to the handlers by the test. They are not generated from the handler code, because the handlers build their JSON inline.
  • Some nested values are only object: variantSiblings, proposal, preview, and the items of check run, runs and looks.
  • Not covered: GET conversation/turns, the issues list, POST pulls, GET repos/{owner}/{name}, and the roughly 400 other routes. The repo read already had typed fields.
  • The message test only covers the 202 that comes back in this sandbox. I did not check a started turn's reply with queued.
  • scripts/similar.ts was not run, and nothing existing was reused beyond the Route and replySchema plumbing in openapi.ts.
  • The keep_plan and estimate tools were not available here, so there is no plan on the issue.

Doors

  • The terminal's API screen and /api read the same document builder, so they show the schemas unchanged. docs/features/api-reference.md says so.
  • The commit line says No door: with that reason.

Try it

  • curl $FORGE_URL/api/v1/openapi.json | jq '.components.schemas.PullDetail'
  • bun test test/openapi-schemas.test.ts

🤖 Generated with Claude Code

Closes #17911

commented

/api/v1/openapi.json now gives full request and response schemas for the repo and conversation routes the Apple app uses. A new test calls each route and checks its real answer against its schema. Type check passes and the openapi, contract, feature-doc and guide tests pass (731). I did not run the full suite. I ran the dead-code and hollow tests, and they pass.

What changed

  • A route's row can now carry response and request as JSON Schema, in plain data built with src/contract/openapi/schema_kit.ts. When set, they replace the old thin reply and body listing.
  • The schemas are named under components.schemas and each operation points at them with $ref. They live in src/contract/openapi/schemas/: pull.ts, repo.ts, conversation.ts, diff.ts.
  • Routes covered:
    • Contents and branches: contents (directory or file), commits (list and one), branches.
    • Issues: one issue and its comment.
    • Pulls: list, one pull (all ~45 fields, including the structured diff), files, checks, line reviews, verdicts, comment and merge.
    • Writes and conversations: POST contents, POST edits, conversations (list, create, patch) and POST conversation/messages.
  • Fixes the test found:
    • The pull's diff is a structured object (files, hunks, numbered lines), not a string.
    • ahead and behind on branches can be null.
    • POST issues/{n}/comments answers 201, but its row said 200. The row now says 201.
  • Slices: ?tag= slices keep only the schemas their operations reach (schemasReached in src/contract/served.ts). The pulls slice is still larger, about 55 KB against 44 KB before, so I raised its test cap from 45 KB to 60 KB.
  • Tests changed: test/contract-openapi-tags.test.ts (that cap, and slice components are now cut to what they reach). test/openapi-oa-pull-checks.test.ts now checks the checks schema through its $ref, because the schema gained why and looks.

Drift guard

  • test/openapi-schemas.test.ts makes real calls and validates the answers and the request bodies it sends with a strict checker (test/helpers/json_schema.ts).
  • The checker fails on a field the schema doesn't name, so a field a handler gains without a schema line fails by name.
  • The published schemas stay open (extra properties allowed), so the forge can add a field without breaking a generated client.

Not done

  • The schemas are written by hand and held to the handlers by the test. They are not generated from the handler code, because the handlers build their JSON inline.
  • Some nested values are only object: variantSiblings, proposal, preview, and the items of check run, runs and looks.
  • Not covered: GET conversation/turns, the issues list, POST pulls, GET repos/{owner}/{name}, and the roughly 400 other routes. The repo read already had typed fields.
  • The message test only covers the 202 that comes back in this sandbox. I did not check a started turn's reply with queued.
  • scripts/similar.ts was not run, and nothing existing was reused beyond the Route and replySchema plumbing in openapi.ts.
  • The keep_plan and estimate tools were not available here, so there is no plan on the issue.

Doors

  • The terminal's API screen and /api read the same document builder, so they show the schemas unchanged. docs/features/api-reference.md says so.
  • The commit line says No door: with that reason.

Try it

  • curl $FORGE_URL/api/v1/openapi.json | jq '.components.schemas.PullDetail'
  • bun test test/openapi-schemas.test.ts

🤖 Generated with Claude Code

commented

This round addresses all four of juniper's points; the one disagreement is in the 413 test on the bare contents route. I ran the openapi, tags and errors suites and tsc; they pass, and the gate passes with two notes (over-100-column comments, and a test helper that resembles one in test/crew-early.test.ts). I did not run the whole suite.

1. The 413. Both contents routes now declare 413 with ContentsTooLarge, which is {type:'file', tooLarge:true, size}. A route row has a new answers field for this: a non-error body at a status of its own. The drift test builds a 5,000,001-byte file in git, because the write routes refuse one. It calls GET …/contents/big.txt and holds the real 413 body to the schema. The bare GET …/contents handler never reads ?path=, even though its row lists that query. It cannot reach a file, so for that route the test only checks that the document declares the 413. I left the row's path query as it was. openapi-errors.test.ts required every non-2xx to be the Error shape, so it now allows ContentsTooLarge for a 413 on the contents routes.

2. Loose values. None is left as a bare object.

  • variantSiblings is a list of integers, and preview is a string or null.
  • question is open, settled or null.
  • proposal, plan, run, runs and looks use new named schemas Proposal, Plan, Run, Look and CheckDetail, in schemas/run.ts. The strict drift test checks each against the real body.

3. pull.ts.

  • The doc comment now sits on PULL_DETAIL.
  • COMMENT and ISSUE_DETAIL are re-indented.
  • The [] is gone from FILE_CHANGE and MERGED.
  • Contents is a oneOf of ContentsDir and ContentsFile with discriminator: {propertyName:'type', mapping}. The two variants are named schemas because swift-openapi-generator wants $refs there. The too-large body stays a separate schema because it shares type: "file" with the file variant.

4. Size cap. I did not raise the number. The one 60 KB cap is replaced by two caps:

  • The operations keep the original 45 KB. They measure about 42 KB.
  • The named schemas get 15 KB. They measure about 13 KB, of which Run is 1.8 KB and the Diff tree about 1.4 KB.

docs/features/api-reference.md carries the how-to for the 413 and the discriminator. The terminal's API screen reads the same document, so it needed no change.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs