graph

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 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 PathHop added in v1.22.0

type PathHop struct {
	Node    NodeID
	Edge    *Edge // nil for the seed node
	Forward bool  // true = followed out-edge, false = followed in-edge
}

PathHop represents a single node in a bidirectional shortest path.

type SchemaGraph

type SchemaGraph struct {
	Schemas    []SchemaNode
	Operations []OperationNode
	Index      *openapi.Index // the source index, for component/security access
	// 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) InEdges

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

InEdges returns the incoming edges to the given node.

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) SchemaByName

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

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

func (*SchemaGraph) SchemaByPtr added in v1.22.0

func (g *SchemaGraph) SchemaByPtr(ptr *oas3.JSONSchemaReferenceable) (NodeID, bool)

SchemaByPtr returns the NodeID for a schema identified by its pointer.

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) ShortestBidiPath added in v1.22.0

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

ShortestBidiPath finds the shortest undirected path between two nodes, following both out-edges and in-edges. Each hop records which direction the edge was traversed (Forward=true for out-edges, false for in-edges). Returns nil if no path exists.

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
	AllOfCount    int
	OneOfCount    int
	AnyOfCount    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