Documentation
¶
Overview ¶
Package contracts checks explicitly declared contracts with bounded schema support.
Index ¶
- Constants
- func DecodeDocument(data []byte) (map[string]any, error)
- func DecodeDocumentAt(p string, data []byte) (map[string]any, error)
- func FieldOverlaps(declared, changed string) bool
- func MissingConsumerFields(content []byte, fields []string) []string
- func Pointer(doc map[string]any, pointer string) (map[string]any, error)
- func ReadSchema(ctx context.Context, root, ref, path string) (map[string]any, error)
- type Binding
- type BindingCheck
- type Change
- type LintReport
- type Manifest
- type ObligationChange
- type Report
- type Retirement
- type Schema
Constants ¶
const ManifestPath = ".radar/contracts.json"
ManifestPath is the committed location of explicit contract bindings.
Variables ¶
This section is empty.
Functions ¶
func DecodeDocument ¶
DecodeDocument decodes a JSON contract document.
func DecodeDocumentAt ¶
DecodeDocumentAt decodes JSON, or YAML when the path ends in .yaml/.yml. YAML is normalized through JSON so both formats compare identically.
func FieldOverlaps ¶
FieldOverlaps reports whether a declared consumer field depends on a changed schema field: the same field, a nested field of it, or an enclosing object.
func MissingConsumerFields ¶
MissingConsumerFields returns declared fields whose final name does not occur as an identifier in the consumer source. This lexical check flags declarations that may be stale; presence does not prove runtime use.
Types ¶
type BindingCheck ¶
type BindingCheck struct {
ID string `json:"id"`
Status model.Status `json:"status"`
Issues []string `json:"issues"`
Notes []string `json:"notes,omitempty"`
}
BindingCheck reports whether one binding can be analyzed and still matches the files it declares.
type Change ¶
type LintReport ¶
type LintReport struct {
Status model.Status `json:"status"`
Revision string `json:"revision"`
Bindings []BindingCheck `json:"bindings"`
Error string `json:"error,omitempty"`
}
LintReport summarizes `radar contracts`.
type Manifest ¶
type Manifest struct {
Version int `json:"version"`
Bindings []Binding `json:"bindings"`
Retired []Retirement `json:"retired,omitempty"`
}
type ObligationChange ¶
type ObligationChange struct {
Binding string `json:"binding"`
Head string `json:"head"`
// Kind is removed, narrowed, moved, retired, consumer_removed or invalid.
Kind string `json:"kind"`
Explanation string `json:"explanation"`
}
ObligationChange records how a binding declared at base differs at a head.
type Report ¶
type Report struct {
Status model.Status `json:"status"`
Checkpoint string `json:"checkpoint"`
Base string `json:"base"`
Heads []string `json:"heads"`
Bindings int `json:"bindings"`
Analyzed int `json:"analyzed"`
Findings []model.Finding `json:"findings"`
Diagnostics []model.Diagnostic `json:"diagnostics"`
// Obligations lists base declarations removed, narrowed, moved or retired.
Obligations []ObligationChange `json:"obligation_changes"`
// Unverified lists reasons no-breaking-contracts cannot be established.
Unverified []string `json:"unverified_obligations"`
}
Report is the outcome of a committed or working-tree contract comparison. Status is "incomplete" when a binding could not be analyzed, so a clean finding list never hides skipped contracts.
func Impact ¶
Impact compares declared obligations at base with head. approved lists retirements reviewed outside the manifest (an approved plan's removal delta); they apply in addition to "retired" entries the head manifest introduces.
func (Report) Unestablished ¶
Unestablished returns every reason the report cannot support a passing no-breaking-contracts verdict, independent of the finding list.
type Retirement ¶
type Retirement struct {
ID string `json:"id"`
Fields []string `json:"fields,omitempty"`
Reason string `json:"reason"`
}
Retirement explicitly withdraws a previously declared obligation, or some of its fields, so its removal is a reviewable manifest change rather than a silent loss of verification coverage. Radar records but cannot verify who reviewed it; protect .radar/ with code ownership where that matters.
type Schema ¶
type Schema struct {
Types []string // sorted; nil means unconstrained
Properties map[string]*Schema
Required []string
Items *Schema
Enum []string // canonical JSON values; nil means no enum
Constraints string // canonical JSON of validation keywords
Opaque string // reason this subtree is not analyzed
Raw string // canonical expanded form of an opaque subtree
Ignored []string // unrecognized keywords
}
Schema is the normalized subset of JSON Schema/OpenAPI Radar compares. Annotations are dropped, validation keywords are summarized, and constructs Radar cannot reason about are kept as opaque subtrees.
func Analyzable ¶
Analyzable reports whether the object at pointer can be normalized.