rules

package
v1.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package rules defines the metadata model of the backward-compatibility rules: the severity levels, the Direction/Area/Kind taxonomy, the Effect a rule concludes about the accepted-value set, the Guards that select the document state it applies to, and the claims tying each rule to the edits it covers (see checker/metaschema).

The model is what makes the rules auditable rather than merely runnable: checker/coverage measures the claims against every possible edit, and the checker's tests derive each rule's severity from its Effect, Guards and Direction and look for broken symmetries across the taxonomy.

The package holds no check implementations: the checker package binds each Rule to the function that implements it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Area

type Area int8

Area is the OpenAPI Object a rule concerns, aligned with the OpenAPI spec's object model.

const (
	AreaSchema Area = iota
	AreaParameters
	AreaRequestBody
	AreaResponses
	AreaPaths
	AreaHeaders
	AreaSecurity
	AreaTags
	AreaComponents
	// AreaInfo's rules judge the versioning policy, not the wire contract:
	// info is annotation-only, so nothing in it can break a client, but
	// info.version is the declared shape of the change and can contradict it.
	AreaInfo
	// AreaServers has no rules yet: server changes are treated as deployment
	// metadata. It exists so the area taxonomy covers every top-level
	// document section a future rule could target.
	AreaServers
	AreaNone
)

func (Area) String

func (a Area) String() string

type Direction

type Direction int8
const (
	DirectionRequest Direction = iota
	DirectionResponse
	DirectionNone
)

func (Direction) String

func (d Direction) String() string

type Effect

type Effect int8

Effect is a rule's verdict about the accepted-value set: how the set of payloads (or API surface) the contract admits changes when the rule fires. It is the semantic axis of a rule, orthogonal to the syntactic edit recorded in the rule's location claims, and together with Direction it determines the expected severity (see rule_severity_law_test.go).

const (
	// EffectNone: the change has no accepted-set semantics (metadata,
	// lifecycle annotations, defaults).
	EffectNone Effect = iota
	// EffectWidens: the accepted set provably grows.
	EffectWidens
	// EffectNarrows: the accepted set provably shrinks.
	EffectNarrows
	// EffectIncomparable: the change both rejects payloads that were valid
	// and accepts payloads that were not, so neither set contains the other.
	EffectIncomparable
	// EffectUnknown: the check cannot tell which way the change goes.
	EffectUnknown
	// EffectViolation: the change breaks oasdiff's lifecycle governance
	// (removal before sunset, invalid or missing sunset, stability decrease)
	// rather than the wire contract.
	EffectViolation
)

func (Effect) String

func (e Effect) String() string

type Guard

type Guard string

Guard is a named predicate over the document state that a rule requires before it fires. Rules covering the same edits may carry different Effects and severities because their guards select different document states.

const (
	// GuardReadOnly: the changed property is readOnly, so it does not
	// appear in requests; request-side effects are nullified.
	GuardReadOnly Guard = "read-only"
	// GuardWriteOnly: the changed property is writeOnly, so it does not
	// appear in responses; response-side effects are nullified.
	GuardWriteOnly Guard = "write-only"
	// GuardSanctioned: the removed element was deprecated and its sunset
	// period was honored, so the removal follows the deprecation contract.
	GuardSanctioned Guard = "sanctioned"
	// GuardNonSuccess: the affected response status is a non-success
	// status. The responses map does not promise that the server returns
	// only the statuses it lists, so neither documenting one more nor
	// dropping one changes what a conforming client can receive; the
	// effect is nullified.
	GuardNonSuccess Guard = "non-success"
	// GuardHasDefault: the changed element declares a default value.
	GuardHasDefault Guard = "has-default"
	// GuardNegotiated: the rule judges the availability of something the
	// client selects or relies on, such as a response status, media type,
	// or header, or the payload that inhabits one. Removing an option the
	// client chooses rejects that choice the way narrowing a request does,
	// and adding one harms nobody, so the level is derived as if the
	// element were on the request side: narrowing is breaking, widening is
	// not, the reverse of plain response polarity.
	GuardNegotiated Guard = "negotiated"
)

type Kind

type Kind int8

Kind is the aspect of the API contract a rule concerns, orthogonal to Area.

const (
	KindExistence Kind = iota
	KindRequiredness
	KindMutability
	KindType
	KindConstraints
	KindValues
	KindStructure
	KindLifecycle
	KindNone
)

func (Kind) String

func (k Kind) String() string

type Level

type Level int
const (
	ERR     Level = 3
	WARN    Level = 2
	INFO    Level = 1
	NONE    Level = 0
	INVALID Level = -1
)

func NewLevel

func NewLevel(level string) (Level, error)

func (Level) IsBreaking

func (level Level) IsBreaking() bool

func (Level) PrettyString

func (level Level) PrettyString() string

func (Level) String

func (level Level) String() string

func (Level) StringCond

func (level Level) StringCond(colorMode colorize.ColorMode) string

type Rule

type Rule struct {
	Id          string
	Level       Level
	Description string
	Direction   Direction
	Area        Area
	Kind        Kind
	Effect      Effect
	Guards      []Guard
	// Locations are the edits the rule covers, as
	// "pattern:action[,action...]" claims (see metaschema.ParseClaim).
	Locations []string
}

Rule is the metadata of one backward-compatibility rule: where it fires (Locations), what it concludes (Effect), under which document states (Guards), which side of the wire it judges (Direction), and its severity (Level). The checker package binds a Rule to its implementation.

func (Rule) Actions

func (r Rule) Actions() []metaschema.Action

Actions returns the syntactic edits the rule covers, derived from its location claims: the rule fires on these edit verbs at its locations. Unlike Effect, which is the rule's semantic verdict, actions describe what literally changed in the document.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL