Documentation
¶
Overview ¶
Package linter provides an OpenAPI specification linter that validates API specs using independently registered checks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckPathRoot ¶
CheckPathRoot rejects paths outside root, including symlink escapes. Missing targets are checked through their nearest existing ancestor. An empty root leaves filesystem policy to the direct library caller.
func DiscoverSchemas ¶
DiscoverSchemas recursively finds all .yaml files under the given directory.
func PointerSegment ¶
PointerSegment escapes a key for use in a JSON pointer.
Types ¶
type Diagnostic ¶
type Document ¶
type Document struct {
// Schema is populated for standalone YAML-schema inputs instead of Model.
Schema *SchemaDocument
Path string
Source []byte
Model *v3.Document
Root *yaml.Node
}
Document exposes both the parsed OpenAPI model and original source locations.
func LoadDocument ¶
LoadDocument reads an OpenAPI 3 document with local references confined to root. Remote references are rejected, including references in external schema files.
func LoadSchemaDocument ¶
LoadSchemaDocument loads a standalone YAML schema under the same reference policy.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine executes public visitor checks over an OpenAPI document.
func (*Engine) RegisterRule ¶
RegisterRule adds a REST API rule to the engine.
type Linter ¶
type Linter struct {
// contains filtered or unexported fields
}
Linter loads and holds a parsed OpenAPI document model for validation.
type Pass ¶
func (*Pass) Diagnostics ¶
func (p *Pass) Diagnostics() []Diagnostic
func (*Pass) Report ¶
func (p *Pass) Report(d Diagnostic)
func (*Pass) ReportError ¶
ReportError stops pack execution with an operational failure, rather than a lint finding.
type Rule ¶
type Rule interface {
// Name returns the unique identifier for this rule.
Name() string
// VisitSchema is called for each named schema component.
// schemaName is the component name (e.g., "CreateWidgetRequest").
// schema is the resolved schema object.
VisitSchema(schemaName string, schema *base.Schema) []Violation
// VisitPath is called for each path in the spec.
// path is the URL path string (e.g., "/endpoints/{endpointId}").
// pathItem is the path item object containing operations.
VisitPath(path string, pathItem *v3high.PathItem) []Violation
// VisitOperation is called for each operation on each path.
// path is the URL path, method is the HTTP method (e.g., "GET"),
// and operation is the operation object.
VisitOperation(path string, method string, operation *v3high.Operation) []Violation
}
Rule defines a validation rule that can visit different parts of an OpenAPI spec. Implementations only need to provide logic for the visitor methods relevant to their rule; unused methods should return nil.
type SchemaDocument ¶
type SchemaDocument struct {
// Content holds the raw parsed YAML as a map of root-level keys.
// x-extension fields (e.g., x-type, x-namespace) are accessible as string keys.
Content map[string]any
}
SchemaDocument represents a parsed standalone schema YAML file.
func LoadSchema ¶
func LoadSchema(path string) (*SchemaDocument, error)
LoadSchema reads and parses a YAML file into a SchemaDocument.
type SchemaRule ¶
type SchemaRule interface {
Name() string
VisitSchema(string, *SchemaDocument) []Violation
}
SchemaRule checks a standalone YAML schema using the same public violation type.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cli provides stock and customer-registry OpenAPI commands.
|
Package cli provides stock and customer-registry OpenAPI commands. |
|
cmd
|
|
|
openapilint
command
|
|
|
examples
|
|
|
custom
command
A customer command with a check registered through the stock extension API.
|
A customer command with a check registered through the stock extension API. |
|
Package rulepack configures built-in and customer analyzers through one registry.
|
Package rulepack configures built-in and customer analyzers through one registry. |