Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ParsedComment ¶
type ParsedComment struct {
// Summary is a brief summary of the comment.
Summary string
// Description is a longer description of the comment.
Description string
// Tags are a list of tags extracted from the comment.
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 {
// The final map of named components that will be added to the spec.
Components map[string]*openapi3.SchemaRef
// contains filtered or unexported fields
}
SchemaGenerator turns Go types into OpenAPI schema definitions.
func NewSchemaGenerator ¶
func NewSchemaGenerator() *SchemaGenerator
NewSchemaGenerator returns a new SchemaGenerator instance.
func (*SchemaGenerator) GenerateSchema ¶ added in v0.1.4
func (sg *SchemaGenerator) GenerateSchema(t types.Type) *openapi3.SchemaRef
GenerateSchema is the main public entry point for creating a schema from a Go type.
type State ¶ added in v0.1.4
type State struct {
Fset *token.FileSet
// 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
Config *config.Config
GroupMetadata model.GroupMetadataMap
// OperationMetadata stores metadata parsed from `respec.Route` builders,
// keyed by the handler's unique types.Object.
OperationMetadata map[types.Object]*respec.HandlerMetadata
// 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 (*State) FindAndParseRouteMetadata ¶ added in v0.2.8
func (s *State) FindAndParseRouteMetadata()
FindAndParseRouteMetadata scans the AST for `respec.Handler(...).Unwrap()` call chains.
func (*State) FindGroupMetadata ¶ added in v0.2.2
func (s *State) FindGroupMetadata()
FindGroupMetadata scans the project for `respec.Meta(r)` calls and builds a map associating the router variable `r` with its chained metadata.
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.