Skip to content

api-contract-verifier

Checks an ApiContract against sample payloads, for a contract’s own test: every method has both schemas, every schema reports the expected vendor, and each schema accepts every valid payload and refuses every invalid one.

It returns what it found rather than asserting, so it runs under any test framework:

expect(await verifyApiContract(MY_API_CONTRACT, { cases, vendor: 'my-plugin' })).toEqual([]);

It lives apart from api-contract.ts because a contract a consumer copies imports that module into its plugin, and nothing here is needed at runtime.

Interface Description
ApiMethodCases The sample payloads of one method, for each half of its contract.
PayloadCases Sample payloads for one schema.
VerifyApiContractOptions Options for verifyApiContract.
Function Description
validateSync Runs a Standard Schema that must be synchronous. A schema guarding a call it cannot delay, as a contract’s schemas do, has to answer before that call returns.
verifyApiContract Checks a contract against sample payloads: the contract has exactly the methods the cases name, each with both schemas, every schema reports the given vendor and Standard Schema version 1, and each schema accepts every valid payload and refuses every invalid one.