Skip to content

2.06 REST API Design (Contract First): Exit Evidence

Evidence · Step: 2.06 REST API Design (Contract First)

Step 2.06 REST API Design (Contract First)
Date 2026-11-14
Tools Postman CLI 1.75.0 (spec lint, collection generation and lint), not logged in
Result Passed; the contract is frozen at v1-draft and awaits review
Deliverable Where
OpenAPI spec openapi/mezgeb.v1.yaml: OpenAPI 3.1, 41 paths, 68 error codes with an example each
Error catalogue docs/api/errors.md: every code, its HTTP status, rule number and source (PostingError, TemplateError, LedgerError, protocol)
Postman collection postman/collections/mezgeb-api-v1, generated from the spec (v3 format, folders by tag, every example); .postman/workflows.yaml links it to the spec
OWASP review docs/api/owasp-review.md
Conventions and compatibility policy docs/api/README.md
Contract tests crates/api/tests/openapi.rs

The work arrived in four pull requests: the contract, its error catalogue and tests (#69), the Postman collection (#70), the conventions and the OWASP review (#71), and this evidence.

Task Done
accounts: create and get openAccount, getAccount, listAccounts (also find by chart reference)
balance at a point in time getAccountBalance?as_of=
entry history getAccountLedger?from=&to=: the general ledger, cursor-paginated, with the opening balance and the balance after each line
posting operations (one per template) 14 operations, POST /v1/operations/{template}.v1, each with a typed body naming its roles, amounts and required metadata
reversal reverseEntry
holds placeHold, getHold, captureHold, releaseHold
lookup by idempotency key getEntryByIdempotencyKey
periods listPeriods, getCurrentPeriod, getPeriod, closePeriod
reports getTrialBalance (now, at a period’s end, at a time) and getAgeing
offline endpoints, stubbed registerDevice, issueVoucher, submitReceipts: 501 not_implemented, marked x-mezgeb-status: planned
An error code catalogue mapped to PostingError Every PostingError (1001–1012) and TemplateError (2001–2022) has a stable code and its rule number; every LedgerError the API can return has a code too
A Postman collection generated from the spec postman spec generate collection --folder-strategy Tags

Also in the contract, beyond the list: account status changes (freeze, close), the template catalogue (listTemplates, getTemplate), and maker-checker adjustments (requestAdjustment, approveAdjustment, rejectAdjustment).

From docs/api/README.md:

  • One endpoint per template version, with a typed body, not one generic operation endpoint. Clients and generated SDKs get each operation’s exact shape, and a new template version is a new endpoint, never a change to an old one.
  • Accounts are named by ID or by chart reference ("2010:cust-abebe", "4010").
  • Adjustments are two-step: request, then approve or reject by a different authenticated person. This came out of the OWASP review.
  • No batch writes in v1 (the open question in spec §9).
  • /v1 only grows; a breaking change is /v2.
  • Not found means not found or not yours (404 rather than 403).
Requirement How Result
Spec lint postman spec lint openapi/mezgeb.v1.yaml --no-report-events --issueType syntax; postman collection lint on the generated collection Spec: no issues. Collection: no issues, after the three fixes below
A review of every endpoint against OWASP API Top 10 owasp-review.md: every group against API1–API10, with what the contract does and what 2.07, 2.08 and 2.16 must prove Done; three design changes came out of it (listed in the review)
Examples for each error code Every code has an example in components/examples, used by at least one response Checked by every_error_code_has_an_example_used_by_a_response and every_rule_has_a_documented_error

Lint coverage. Without a Postman login, spec lint checks syntax only; Postman’s governance rules need postman login. Running Spectral from npm was not permitted in this session. The contract tests below cover the project’s own rules instead.

The collection. Two things were fixed in the generated collection:

  • Path length. The generator names files after tags, summaries and response descriptions. The first wording produced paths up to 227 characters, which git add refused on Windows. The contract now uses short tags, summaries of at most 32 characters and one- or two-word response descriptions; the longest path is 134 characters. the_collection_paths_fit_on_windows keeps every path within 150.
  • FMT209. The generator wrote three RFC 3339 query values unquoted, so YAML read them back as dates and the collection lint reported FMT209. Each was fixed with postman collection request update --url; the steps are in the API README.

Every template and engine operation is reachable, and no endpoint allows raw arbitrary lines except an admin-only adjustment. Checked in CI by crates/api/tests/openapi.rs:

Test What it proves
every_template_has_an_operation_with_its_exact_shape The contract has exactly one operation per released template, and its roles, optional roles, amounts, optional amounts, required metadata and refund flag equal the template registry’s. The request schema names each one
every_engine_operation_is_reachable Every engine operation (accounts, balance, history, status, entries, idempotency lookup, reversal, adjustments, holds, periods, close, reports) and the offline stubs have an operation
only_the_adjustment_request_takes_raw_lines Of every request body in the contract, only POST /v1/adjustments has lines. It needs adjustments:request, and its approval needs adjustments:approve and refuses maker_is_checker
every_operation_is_scoped_and_every_posting_is_idempotent Every operation names a scope, and every write that posts or places a hold takes Idempotency-Key
every_rule_has_a_documented_error, every_error_code_has_an_example_used_by_a_response Every posting and template rule has an example; every code has an example that a response uses, and a row in errors.md
the_collection_paths_fit_on_windows The generated collection can be checked out on Windows

A drift test was run by hand. Changing one template’s optional amounts in the contract made every_template_has_an_operation_with_its_exact_shape fail, naming the template and the field.

The spec is reviewed and frozen at v1-draft. The contract’s info.version is 1.0.0-draft, and the API README records the freeze: a change before v1 is a reviewed change to the contract first. The review is pending: it needs a person, as for the accounting and dispute reviews. The OWASP review and the “Decisions” above are the points to check. The roadmap marks the step done with the review pending.

  • The implementation: step 2.07.
  • The token format, ownership checks and scope enforcement: step 2.08.
  • The offline request bodies: step 2.10.