API reference
contractdiff/core
Every export of contractdiff/core, with its signature and doc comment: DIRECTIONS, RefError, pointerGet, inline, plus 7 types.
import { DIRECTIONS, RefError, pointerGet, … } from 'contractdiff/core';Classes
RefError
A reference that cannot be followed. The message ends in a fix: line.
class RefError extends Error {
readonly ref: string;
constructor(ref: string, reason: string, fix: string);
}Constants
DIRECTIONS
const DIRECTIONS: readonly ["request", "response", "publish", "subscribe", "tool-call", "tool-result", "argv"];inline
Inline every local reference under node.
const inline: (document: unknown, node: unknown) => Inlined;pointerGet
The value a local reference (#, #/a/b) points at, by RFC 6901.
const pointerGet: (document: unknown, ref: string) => unknown;Interfaces
Contract
interface Contract {
/** The input format's name, e.g. `openapi`. */
readonly format: string;
/** The parsed source, untouched: a generator that must reproduce an incumbent's output reads it. */
readonly document: unknown;
readonly operations: readonly Operation[];
/** What the reader had to translate or could not read exactly. */
readonly findings?: readonly ContractFinding[];
}ContractFinding
Something a reader or a generator could not carry over exactly. Never a silent loss: a keyword dropped, a construct translated, a value synthesised (program.md, definition of done 7).
interface ContractFinding {
/** Stable, kebab-case, e.g. `keyword-dropped`. */
readonly code: string;
/** JSON Pointer into the source document. */
readonly pointer: string;
readonly message: string;
readonly fix: string;
}Inlined
interface Inlined {
/** A copy of the input with every followed reference replaced by its target. */
readonly value: unknown;
/** References kept because their target was already open: the cycles. */
readonly cycles: readonly string[];
/** References kept because they point outside the document. */
readonly external: readonly string[];
}Operation
interface Operation {
/** Stable across runs: the spec's own id where it has one. */
readonly id: string;
/** JSON Pointer to where the operation is declared in the source document. */
readonly source: string;
readonly payloads: readonly Payload[];
}Payload
interface Payload {
/** Stable within its operation, e.g. `body:application/json` or `response:200:application/json`. */
readonly name: string;
readonly direction: Direction;
readonly schema: JsonSchema;
readonly required: boolean;
}Types
Direction
Who sends a payload. Compatibility is decided per direction (spec.md R3), so it lives here.
type Direction = (typeof DIRECTIONS)[number];JsonSchema
A JSON Schema as it appears in a document: true, false, or an object of keywords.
type JsonSchema = boolean | {
readonly [keyword: string]: unknown;
};