Documentation
¶
Overview ¶
Package contract defines the lint and compare plugin input/output types matching the published JSON Schema contracts at https://ifc7.dev/schemas/plugins/v0/ and https://ifc7.dev/schemas/plugins/v1/.
v1 is a superset of v0: it adds LintInput.Ruleset, LintOutput.Findings, LintOutput.IgnoredFindings, LintOutput.Engine and CompareOutput.Changes. A v0 consumer that ignores those fields keeps working.
Index ¶
Constants ¶
const ( VersionV0 = "v0" VersionV1 = "v1" )
Contract versions.
Variables ¶
var Severities = []Severity{SeverityError, SeverityWarn, SeverityInfo, SeverityHint}
Severities lists every severity, most severe first.
Functions ¶
This section is empty.
Types ¶
type Change ¶ added in v0.0.3
type Change struct {
// Kind classifies the change as {object}.{property}.{action}, for
// example "pathItem.operation.removed" or "schema.type.modified".
// action is added, removed or modified.
Kind string `json:"kind"`
// Pointer is a JSON Pointer to the changed location. It points into the
// after document, or into the before document for a removal. Array
// members that have a name (parameters) are addressed by that name.
Pointer string `json:"pointer"`
Breaking bool `json:"breaking"`
// Level is error for a breaking change and warn otherwise.
Level ChangeLevel `json:"level"`
Message string `json:"message"`
// Stability is set when a change that would be breaking is exempt
// because its operation is marked x-stability-level (draft or alpha).
Stability string `json:"stability,omitempty"`
// Fingerprint identifies the change by kind and pointer.
Fingerprint string `json:"fingerprint"`
}
Change is one structured difference between two documents.
type ChangeLevel ¶ added in v0.0.3
type ChangeLevel string
ChangeLevel is how much a change matters to a gate.
const ( // ChangeLevelError is a change a breaking-change gate judges: by // default every breaking change. ChangeLevelError ChangeLevel = "error" // ChangeLevelWarn is reported but never fails a gate: by default every // non-breaking change. ChangeLevelWarn ChangeLevel = "warn" // ChangeLevelIgnore drops the change. Plugins never emit it; a // governance policy may set it per change kind. ChangeLevelIgnore ChangeLevel = "ignore" )
type CompareInput ¶
type CompareInput struct {
InterfaceType InterfaceType `json:"interfaceType"`
Before SpecificationDocument `json:"before"`
After SpecificationDocument `json:"after"`
Options map[string]any `json:"options,omitempty"`
}
CompareInput is the input contract for change-detector plugins.
type CompareOutput ¶
type CompareOutput struct {
Breaking bool `json:"breaking"`
Raw string `json:"raw"`
// Changes are the structured change records (v1). Breaking is true
// exactly when at least one change is breaking.
Changes []Change `json:"changes,omitempty"`
Extra map[string]any `json:"extra,omitempty"`
}
CompareOutput is the output contract for change-detector plugins.
type FileFormat ¶
type FileFormat string
FileFormat is the serialization format of decoded specification bytes.
const ( FileFormatJSON FileFormat = "json" FileFormatYAML FileFormat = "yaml" )
func DetectFileFormat ¶
func DetectFileFormat(raw []byte) FileFormat
DetectFileFormat returns json or yaml based on content.
type Finding ¶ added in v0.0.3
type Finding struct {
RuleID string `json:"ruleId"`
Severity Severity `json:"severity"`
Message string `json:"message"`
// Pointer is a JSON Pointer (RFC 6901) to the offending node. Empty
// string means the document root.
Pointer string `json:"pointer"`
// Range is the 1-based source location, when known.
Range *Range `json:"range,omitempty"`
// Fingerprint identifies the finding across formatting changes.
Fingerprint string `json:"fingerprint"`
DocumentationURL string `json:"documentationUrl,omitempty"`
}
Finding is a single structured lint result.
type InterfaceType ¶
type InterfaceType string
InterfaceType identifies the kind of interface specification.
const ( InterfaceTypeOpenAPI InterfaceType = "OPENAPI" InterfaceTypeJSONSchema InterfaceType = "JSON_SCHEMA" )
type LintInput ¶
type LintInput struct {
InterfaceType InterfaceType `json:"interfaceType"`
Document SpecificationDocument `json:"document"`
// Ruleset is the effective OpenLint ruleset to lint with (v1). Nil means
// the plugin's built-in default.
Ruleset *RulesetDocument `json:"ruleset,omitempty"`
Options map[string]any `json:"options,omitempty"`
}
LintInput is the input contract for linter plugins.
type LintOutput ¶
type LintOutput struct {
// Score is the ifc7 quality score, 0 (worst) to 100 (best).
Score int `json:"score"`
// Raw is human-readable detail. v1 plugins render it from Findings.
Raw string `json:"raw"`
// Findings are the structured lint results (v1).
Findings []Finding `json:"findings,omitempty"`
// IgnoredFindings are results the document suppressed with an inline
// x-lint-ignore (v1). They are not in Findings and do not affect Score;
// a governance policy decides whether they count (see
// pkg/governance/policy).
IgnoredFindings []Finding `json:"ignoredFindings,omitempty"`
// Engine names the lint engine that produced the findings (v1).
Engine *Engine `json:"engine,omitempty"`
Extra map[string]any `json:"extra,omitempty"`
}
LintOutput is the output contract for linter plugins.
type RulesetDocument ¶ added in v0.0.3
type RulesetDocument struct {
// Document is the base64-encoded ruleset, JSON or YAML.
Document string `json:"document"`
// SHA256 is the lowercase hex sha256 of the canonical ruleset bytes.
SHA256 string `json:"sha256"`
}
RulesetDocument carries an effective (fully resolved) OpenLint ruleset.
func NewRulesetDocument ¶ added in v0.0.3
func NewRulesetDocument(raw []byte, sha256 string) *RulesetDocument
NewRulesetDocument encodes ruleset bytes and their canonical sha256.
func (RulesetDocument) Decode ¶ added in v0.0.3
func (r RulesetDocument) Decode() ([]byte, error)
Decode returns the raw ruleset bytes.
type SpecificationDocument ¶
type SpecificationDocument struct {
Specification string `json:"specification"`
FileFormat FileFormat `json:"fileFormat"`
}
SpecificationDocument is a single interface specification payload.
func NewSpecificationDocument ¶
func NewSpecificationDocument(raw []byte, format FileFormat) SpecificationDocument
NewSpecificationDocument encodes raw bytes as a SpecificationDocument.
func (SpecificationDocument) Decode ¶
func (d SpecificationDocument) Decode() ([]byte, error)
Decode returns the raw specification bytes.