API Contract
Contract-first workflow for this repo.
Canonical files
- •
api.yaml(source of truth) - •
web/src/lib/api/schema.d.ts(generated)
Procedure
- •Read
progress.md, the relevant story indocs/epic.md, and existing endpoint patterns inapi.yaml. - •Update
api.yamlfirst:- •Path + method +
operationId - •Request schema
- •Response schema with required envelope
- •Auth/security definition
- •Path + method +
- •Keep response envelopes consistent:
- •Single:
{ "data": { ... } } - •List:
{ "data": [...], "meta": { "page", "page_size", "total" } } - •Error:
{ "error": { "code", "message", "details" } }
- •Single:
- •For list endpoints, include pagination params (
page,page_size) and bounded behavior. - •If adding a new error code, register it in
pkg/errors/codes.go. - •Run
.agents/skills/api-contract/scripts/sync-types.sh. - •Verify generated type usage compiles in
web/. - •Update
progress.mdwith contract changes.
Rules
- •Never implement a changed endpoint before updating
api.yaml. - •Never hand-edit
web/src/lib/api/schema.d.ts. - •Keep contract names stable (
operationId, schema keys) unless a breaking change is intentional.