analyze

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package analyze provides project-level intelligence features including dead component detection, breaking change analysis, and bundle preview.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BreakingChangesAnalyzer

func BreakingChangesAnalyzer(baselines map[string]*SpecSummary) graph.AnalyzeFunc

BreakingChangesAnalyzer returns a graph.AnalyzeFunc that compares the current spec against a previously stored baseline. The baseline is stored per-URI in the provided map and updated after each comparison.

func BreakingChangesToDiagnostics

func BreakingChangesToDiagnostics(changes []BreakingChange) []ctypes.Diagnostic

BreakingChangesToDiagnostics converts breaking changes to diagnostics.

func DefaultAnalyzers

func DefaultAnalyzers() []graph.AnalyzeFunc

DefaultAnalyzers returns the standard set of analyzer functions.

func DependencyOrder

func DependencyOrder(g graph.ReadOnlyGraph, rootURI string) []string

DependencyOrder returns the URIs in the bundle in dependency order. The root is first, followed by its transitive dependencies.

func UnusedComponentsAnalyzer

func UnusedComponentsAnalyzer() graph.AnalyzeFunc

UnusedComponentsAnalyzer returns a graph.AnalyzeFunc that detects unreferenced components within each document using the graph's reverse edge index.

func UnusedToDiagnostics

func UnusedToDiagnostics(unused []UnusedResult) map[string][]ctypes.Diagnostic

UnusedToDiagnostics converts unused component results to diagnostics.

Types

type BreakingChange

type BreakingChange struct {
	Kind   BreakingChangeKind
	Path   string // API path, e.g. "/pets"
	Method string // HTTP method, e.g. "get"
	Detail string // human-readable description
	Range  ctypes.Range
}

BreakingChange represents a single detected breaking change.

func DetectBreakingChanges

func DetectBreakingChanges(base, current *SpecSummary) []BreakingChange

DetectBreakingChanges compares a base spec summary to the current spec and returns all detected breaking changes.

type BreakingChangeKind

type BreakingChangeKind string

BreakingChangeKind categorizes the type of breaking change.

const (
	BreakRemovedPath          BreakingChangeKind = "removed-path"
	BreakRemovedOperation     BreakingChangeKind = "removed-operation"
	BreakRemovedParameter     BreakingChangeKind = "removed-parameter"
	BreakNewRequiredParameter BreakingChangeKind = "new-required-parameter"
	BreakTypeNarrowed         BreakingChangeKind = "type-narrowed"
	BreakRemovedEnumValue     BreakingChangeKind = "removed-enum-value"
	BreakAddedSecurity        BreakingChangeKind = "added-security"
	BreakNewRequiredField     BreakingChangeKind = "new-required-field"
	BreakRemovedResponse      BreakingChangeKind = "removed-response"
)

type BundleFormat

type BundleFormat int

BundleFormat specifies the output format for bundles.

const (
	BundleFormatYAML BundleFormat = iota
	BundleFormatJSON
)

type BundleOptions

type BundleOptions struct {
	Format   BundleFormat
	MaxDepth int // max $ref follow depth; 0 = unlimited
	RootURI  string
}

BundleOptions configures the bundle operation.

type BundleResult

type BundleResult struct {
	RootURI string
	Content []byte
	Format  BundleFormat
	Errors  []string
}

BundleResult represents the output of a multi-root bundle preview.

func BundlePreview

func BundlePreview(g graph.ReadOnlyGraph, opts BundleOptions) *BundleResult

BundlePreview traverses the graph starting from the root URI, collecting all referenced documents. It produces a manifest of URIs in dependency order suitable for producing a fully-dereferenced bundle.

The actual YAML/JSON merging is handled by the caller — this function provides the graph traversal and cycle-safe ordering.

type ComponentEntry

type ComponentEntry struct {
	Kind       string // "schemas", "responses", "parameters", etc.
	Name       string
	Range      ctypes.Range
	Suppressed bool // true if x-telescope-ignore: unused is present
}

ComponentEntry represents a single component definition in a document.

type OperationSummary

type OperationSummary struct {
	Parameters      []ParamSummary
	ResponseCodes   []string
	SecuritySchemes []string
	RequestBody     *RequestBodySummary
}

OperationSummary represents a single operation for comparison.

type ParamSummary

type ParamSummary struct {
	Name     string
	In       string
	Required bool
	Type     string
	Enum     []string
}

ParamSummary represents a parameter for comparison.

type PathSummary

type PathSummary struct {
	Operations map[string]OperationSummary
}

PathSummary represents a single path item.

type RequestBodySummary

type RequestBodySummary struct {
	Required       bool
	RequiredFields []string
}

RequestBodySummary represents a request body for comparison.

type SpecSummary

type SpecSummary struct {
	Paths map[string]PathSummary
}

SpecSummary is a simplified representation of an API spec for comparison. Built from the OpenAPI index to enable diffing without full model dependency.

type UnusedResult

type UnusedResult struct {
	URI       string
	Component string // e.g. "schemas/Pet", "responses/NotFound"
	Kind      string // e.g. "schemas", "responses"
	Name      string
	Range     ctypes.Range
}

UnusedResult represents the result of dead component analysis.

func FindUnusedComponents

func FindUnusedComponents(g *graph.WorkspaceGraph, componentMap map[string][]ComponentEntry) []UnusedResult

FindUnusedComponents walks the graph's reverse edge index to detect components with zero inbound references from outside the components/ section. Returns a list of unreferenced components with their locations.

Jump to

Keyboard shortcuts

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