graph

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package graph infers producer-consumer dependencies between OpenAPI operations. It analyzes response schemas (producers) and request parameters/bodies (consumers), then matches them using name, type and path signals to produce a confidence-scored dependency graph.

Index

Constants

View Source
const MinConfidence = 0.50

MinConfidence is the minimum confidence score for a dependency edge to be included in the graph.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dependency

type Dependency struct {
	Producer   ValueRef `json:"producer"`
	Consumer   ValueRef `json:"consumer"`
	Confidence float64  `json:"confidence"`
	Reason     Reason   `json:"reason"`
}

Dependency is a confidence-scored edge from a producer value to a consumer value.

func Match

func Match(producers, consumers []ValueRef) []Dependency

Match takes extracted producers and consumers and infers confidence-scored dependency edges.

func (Dependency) String

func (d Dependency) String() string

String returns a one-line description of the dependency.

type Graph

type Graph struct {
	Producers    []ValueRef   `json:"producers"`
	Consumers    []ValueRef   `json:"consumers"`
	Dependencies []Dependency `json:"dependencies"`
}

Graph is the inferred dependency graph for a spec.

func Build

func Build(spec *openapi.Spec) *Graph

Build is the top-level entry point: extract producers and consumers from the spec, match them, and return the complete graph.

func (*Graph) EdgesForConsumer

func (g *Graph) EdgesForConsumer(operationKey string) []Dependency

EdgesForConsumer returns all dependencies that produce values for the given consumer operation key.

func (*Graph) EdgesFromProducer

func (g *Graph) EdgesFromProducer(operationKey string) []Dependency

EdgesFromProducer returns all dependencies that consume values from the given producer operation key.

func (*Graph) JSON

func (g *Graph) JSON() (string, error)

JSON renders the dependency graph as indented JSON.

func (*Graph) Mermaid

func (g *Graph) Mermaid() string

Mermaid renders the dependency graph as a Mermaid flowchart diagram.

func (*Graph) SortedDependencies

func (g *Graph) SortedDependencies() []Dependency

SortedDependencies returns dependencies sorted by confidence (descending), then by producer and consumer strings for determinism.

func (*Graph) Text

func (g *Graph) Text() string

Text renders the dependency graph as a human-readable text report.

type Location

type Location string

Location describes where a value lives in an operation's input or output.

const (
	LocPath     Location = "path"
	LocQuery    Location = "query"
	LocHeader   Location = "header"
	LocBody     Location = "body"
	LocResponse Location = "response"
)

type Reason

type Reason struct {
	Signals []Signal `json:"signals"`
}

Reason describes why a dependency edge was inferred, listing the signals that matched and their individual contributions.

func (Reason) Summary

func (r Reason) Summary() string

Summary returns a comma-separated list of signal names.

type Signal

type Signal struct {
	Name       string  `json:"name"`
	Confidence float64 `json:"confidence"`
	Detail     string  `json:"detail"`
}

Signal is a single piece of evidence supporting a dependency edge.

type ValueRef

type ValueRef struct {
	OperationKey string         `json:"operation"`
	Method       string         `json:"method"`
	Path         string         `json:"path"`
	Location     Location       `json:"location"`
	FieldPath    string         `json:"field"`
	Schema       *schema.Schema `json:"-"`
}

ValueRef references a single value in an operation's input or output. FieldPath uses dot notation for nested object fields (e.g. "user.id").

func ExtractConsumers

func ExtractConsumers(ops []*openapi.Operation) []ValueRef

ExtractConsumers walks all operations' request parameters and request bodies and extracts candidate consumer values.

func ExtractProducers

func ExtractProducers(ops []*openapi.Operation) []ValueRef

ExtractProducers walks all operations' success (2xx) response schemas and extracts candidate producer values. Object response schemas yield their properties; array responses yield their item schema's properties.

func (ValueRef) String

func (v ValueRef) String() string

String returns a human-readable reference like "POST /users.response.id".

Jump to

Keyboard shortcuts

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