validation

package
v0.36.4 Latest Latest
Warning

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

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

Documentation

Overview

Package validation runs the produced spec through go-openapi/validate and normalises what comes back into findings the TUI can list and navigate to.

This asks a different question from the scanner's own diagnostics. Those say whether the ANNOTATIONS were understood; these say whether the DOCUMENT they produced is a legal Swagger 2.0 spec. A scan can be perfectly clean and still emit something a consumer will reject, which is the gap this closes.

Index

Constants

View Source
const RootLabel = "(the whole document)"

RootLabel names what the empty pointer addresses.

An empty pointer is a location, not the absence of one: RFC 6901 spells the whole document that way, and a finding about something the document does not have at all - no info block, no paths - is reported there. It needs a printable stand-in, since "" would render as nothing at all.

Variables

This section is empty.

Functions

func Render

func Render(findings []Finding, ran bool, runErr error, selected int, focused bool) (string, int)

Render composes the validation tab's body.

It also reports the 0-based content line of the selected finding, or -1 when there is none.

Laid out like the scan tab and coloured by the same rule - label and message in the severity's hue, the selected row taking the whole line over RAW text - so the two tabs read as two views of one pane rather than two widgets.

func Tally

func Tally(findings []Finding) (errs, warns int)

Tally counts findings by severity, for the pane's summary line.

Types

type Finding

type Finding struct {
	Severity grammar.Severity

	// Pointer locates the offending value, as an RFC 6901 JSON pointer reported by the validator.
	//
	// Taken from the result rather than recovered from the message: the validator records the location as it walks, so
	// it is the authority on it, and a sentence is a poor place to keep a machine-readable path.
	//
	// EMPTY means the whole document, which is what RFC 6901 spells that way - not "nowhere". A finding about
	// something the document lacks entirely is reported there, so an empty pointer is navigable: see RootLabel.
	Pointer string

	Message string
}

Finding is one validation result.

Severity reuses the scanner's own enum rather than declaring a parallel one: the two kinds of finding are shown by the same pane in the same colours, and giving "error" two incompatible spellings would only mean translating between them at the one place they meet.

func Run

func Run(specJSON []byte) ([]Finding, error)

Run validates a rendered JSON spec.

Takes the rendered bytes rather than the *spec.Swagger the scan produced, so what is checked is exactly the document on screen - including whatever the JSON round-trip did to it.

Jump to

Keyboard shortcuts

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