analyzer

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Analyze added in v0.1.4

func Analyze(projectPath string, cfg *config.Config) (*model.APIModel, error)

Analyze is the main entry point that orchestrates the entire analysis pipeline.

Types

type ParsedComment

type ParsedComment struct {
	Summary     string
	Description string
	Tags        []string
}

ParsedComment holds the structured data extracted from a doc comment.

type ResolvedType added in v0.1.4

type ResolvedType struct {
	// The canonical representation of the type. This is what we use for reliable comparisons.
	Object *types.Named
	// A pointer to the original definition from the config file.
	Definition *config.RouterDefinition
}

ResolvedType represents a type from the config that has been resolved to its canonical go/types object.

type SchemaGenerator

type SchemaGenerator struct {
	// contains filtered or unexported fields
}

SchemaGenerator turns Go types into OpenAPI schema definitions.

func NewSchemaGenerator

func NewSchemaGenerator() *SchemaGenerator

func (*SchemaGenerator) GenerateSchema added in v0.1.4

func (sg *SchemaGenerator) GenerateSchema(t types.Type) *openapi3.SchemaRef

GenerateSchema is the main entry point for creating a schema from a Go type. It returns a reference to the schema, which will be placed in the components section.

type State added in v0.1.4

type State struct {

	// A map of fully-qualified type names to their resolved canonical types.
	// This is populated by the resolver (Phase 1).
	// Example key: "github.com/go-chi/chi/v5.Mux"
	ResolvedRouterTypes map[string]*ResolvedType

	// The discovered universe of all relevant declarations in the project.
	// This is populated by the universe discoverer (Phase 2).
	Universe *Universe

	// --- Data Flow Analysis State ---
	// The queue of analysis tasks.
	Worklist []WorklistItem
	// A map to link expressions (like call results) to the tracked value they produce.
	ExprResults map[ast.Expr]*TrackedValue
	// A map to link variable/parameter objects to the tracked value they hold.
	VarValues map[types.Object]*TrackedValue

	// The root of the final constructed API route graph.
	RouteGraph *model.RouteNode

	// --- Schema Generation State ---
	// The schema generator instance.
	SchemaGen *SchemaGenerator
	// contains filtered or unexported fields
}

State is the central data structure that holds all information gathered during the multi-phase analysis of the target project.

func NewState added in v0.1.4

func NewState(pkgs []*packages.Package, cfg *config.Config) (*State, error)

type TrackedValue added in v0.1.4

type TrackedValue struct {
	// The expression where this value was created (e.g., the `chi.NewRouter()` call).
	Source ast.Expr
	// The specific router definition this value corresponds to.
	RouterDef *config.RouterDefinition

	// --- Chaining and Hierarchy ---
	Parent     *TrackedValue
	PathPrefix string
	// The node in our API graph that corresponds to this specific router or group.
	Node *model.RouteNode
}

TrackedValue represents a value (e.g., a router instance) that we are tracing through the program's data flow.

type Universe added in v0.1.4

type Universe struct {
	// A map of function objects to their AST declaration nodes.
	Functions map[types.Object]*ast.FuncDecl

	// A map of constant objects to their value specifications.
	// This helps in resolving path segments that are defined as constants.
	Constants map[types.Object]*ast.ValueSpec
}

Universe contains maps of all relevant top-level declarations in the project. This serves as a quick lookup table for the rest of the analysis.

type WorklistItem added in v0.1.4

type WorklistItem struct {
	// The AST node representing the usage of a tracked value (e.g., an `*ast.Ident` for a variable).
	Node ast.Node
	// The value being tracked at this node.
	Value *TrackedValue
}

WorklistItem represents a single task for our data flow analysis. It contains a node to analyze and the value associated with it.

Jump to

Keyboard shortcuts

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