graph

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package graph provides a pre-computed directed graph over OpenAPI schemas and operations, materialized from an openapi.Index for efficient structural queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	From  NodeID
	To    NodeID
	Kind  EdgeKind
	Label string // property name, pattern key, or index
}

Edge represents a directed edge between two schema nodes.

type EdgeKind

type EdgeKind int

EdgeKind represents the type of relationship between two schema nodes.

const (
	EdgeProperty         EdgeKind = iota // properties/X
	EdgeItems                            // items
	EdgeAllOf                            // allOf[i]
	EdgeOneOf                            // oneOf[i]
	EdgeAnyOf                            // anyOf[i]
	EdgeAdditionalProps                  // additionalProperties
	EdgeNot                              // not
	EdgeIf                               // if
	EdgeThen                             // then
	EdgeElse                             // else
	EdgeContains                         // contains
	EdgePrefixItems                      // prefixItems[i]
	EdgeDependentSchema                  // dependentSchemas/X
	EdgePatternProperty                  // patternProperties/X
	EdgePropertyNames                    // propertyNames
	EdgeUnevaluatedItems                 // unevaluatedItems
	EdgeUnevaluatedProps                 // unevaluatedProperties
	EdgeRef                              // resolved $ref
)

type NodeID

type NodeID int

NodeID is a unique identifier for a node in the graph.

type OperationNode

type OperationNode struct {
	ID             NodeID
	Name           string // operationId or "METHOD /path"
	Method         string
	Path           string
	OperationID    string
	Operation      *openapi.Operation
	Location       openapi.Locations
	SchemaCount    int
	ComponentCount int
}

OperationNode represents an operation in the graph.

type SchemaGraph

type SchemaGraph struct {
	Schemas    []SchemaNode
	Operations []OperationNode
	// contains filtered or unexported fields
}

SchemaGraph is a pre-computed directed graph over OpenAPI schemas and operations.

func Build

func Build(_ context.Context, idx *openapi.Index) *SchemaGraph

Build constructs a SchemaGraph from an openapi.Index.

func (*SchemaGraph) Ancestors

func (g *SchemaGraph) Ancestors(id NodeID) []NodeID

Ancestors returns all schema NodeIDs that can transitively reach the given node via in-edges.

func (*SchemaGraph) ConnectedComponent

func (g *SchemaGraph) ConnectedComponent(schemaSeeds, opSeeds []NodeID) (schemas []NodeID, ops []NodeID)

ConnectedComponent computes the full connected component reachable from the given seed schema and operation nodes. It treats schema edges as undirected (follows both out-edges and in-edges) and crosses schema↔operation links. Returns the sets of reachable schema and operation NodeIDs (including seeds).

func (*SchemaGraph) InEdges

func (g *SchemaGraph) InEdges(id NodeID) []Edge

InEdges returns the incoming edges to the given node.

func (*SchemaGraph) Neighbors

func (g *SchemaGraph) Neighbors(id NodeID, maxDepth int) []NodeID

Neighbors returns schema NodeIDs within maxDepth hops of the given node, following both out-edges and in-edges (bidirectional BFS). The result excludes the seed node itself.

func (*SchemaGraph) OperationSchemas

func (g *SchemaGraph) OperationSchemas(opID NodeID) []NodeID

OperationSchemas returns the schema NodeIDs reachable from the given operation. Results are sorted by NodeID for deterministic output.

func (*SchemaGraph) OutEdges

func (g *SchemaGraph) OutEdges(id NodeID) []Edge

OutEdges returns the outgoing edges from the given node.

func (*SchemaGraph) Reachable

func (g *SchemaGraph) Reachable(id NodeID) []NodeID

Reachable returns all schema NodeIDs transitively reachable from the given node via out-edges.

func (*SchemaGraph) SchemaByName

func (g *SchemaGraph) SchemaByName(name string) (SchemaNode, bool)

SchemaByName returns the schema node with the given component name, if any.

func (*SchemaGraph) SchemaOpCount

func (g *SchemaGraph) SchemaOpCount(id NodeID) int

SchemaOpCount returns the number of operations that reference the given schema.

func (*SchemaGraph) SchemaOperations

func (g *SchemaGraph) SchemaOperations(schemaID NodeID) []NodeID

SchemaOperations returns the operation NodeIDs that reference the given schema. Results are sorted by NodeID for deterministic output.

func (*SchemaGraph) ShortestPath

func (g *SchemaGraph) ShortestPath(from, to NodeID) []NodeID

ShortestPath returns the shortest path from `from` to `to` using out-edges (BFS). Returns nil if no path exists. The returned slice includes both endpoints.

func (*SchemaGraph) StronglyConnectedComponents

func (g *SchemaGraph) StronglyConnectedComponents() [][]NodeID

StronglyConnectedComponents returns the SCCs of the schema graph using Tarjan's algorithm. Only returns components with more than one node (i.e., actual cycles, not singleton nodes).

type SchemaNode

type SchemaNode struct {
	ID            NodeID
	Name          string // component name or JSON pointer
	Path          string // JSON pointer in document
	Schema        *oas3.JSONSchemaReferenceable
	Location      openapi.Locations
	IsComponent   bool
	IsInline      bool
	IsExternal    bool
	IsBoolean     bool
	IsCircular    bool
	HasRef        bool
	Type          string // primary schema type
	Depth         int
	InDegree      int
	OutDegree     int
	UnionWidth    int
	PropertyCount int
	Hash          string
}

SchemaNode represents a schema in the graph.

Jump to

Keyboard shortcuts

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