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 )
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 )
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.
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.