Zum Inhalt springen
#0880
Exec

Money endpoints that refuse to return the wrong shape

A handler returns amount: "19.99" as a string where the contract says an integer in minor units plus a currency code; a downstream parses it its own way, and the ledger is off by a cent per order for a week.

hoody-exec lets the handler declare its own contract: // @return-type { amount_minor: number; currency: string; ledger_ref: string } and // @return-type-mode strict. In strict mode the runtime checks each response against the declared type and rejects a mismatch. warn logs only; dev skips production. The same check runs standalone: POST /api/v1/exec/validate/return-type takes a type definition and a value and lists the mismatches: so CI can throw fixtures at the contract before deploy.

The schema used to live in an OpenAPI file nobody enforced. Now it lives above the function, enforced by the function's runtime.

The contract is enforced by the thing that returns the response, not by the thing that reads it.