Documentation
¶
Overview ¶
Package oq implements a pipeline query language for OpenAPI schema graphs.
Queries are written as pipeline expressions with jq-inspired syntax:
schemas.components | select(depth > 5) | sort_by(depth; desc) | first(10) | pick name, depth
Legacy syntax (where, sort, take, select fields) is also supported.
Index ¶
- func ExpandDefs(pipelineText string, defs []FuncDef) (string, error)
- func FieldValuePublic(row Row, name string, g *graph.SchemaGraph) expr.Value
- func FormatJSON(result *Result, g *graph.SchemaGraph) string
- func FormatMarkdown(result *Result, g *graph.SchemaGraph) string
- func FormatTable(result *Result, g *graph.SchemaGraph) string
- func FormatToon(result *Result, g *graph.SchemaGraph) string
- type FuncDef
- type GroupResult
- type Query
- type Result
- type ResultKind
- type Row
- type Stage
- type StageKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandDefs ¶
ExpandDefs performs text-level macro expansion on pipeline segments. Each segment that matches a def name gets replaced with the def's body (with params substituted).
func FieldValuePublic ¶
FieldValuePublic returns the value of a named field for the given row. Exported for testing and external consumers.
func FormatJSON ¶
func FormatJSON(result *Result, g *graph.SchemaGraph) string
FormatJSON formats a result as JSON.
func FormatMarkdown ¶
func FormatMarkdown(result *Result, g *graph.SchemaGraph) string
FormatMarkdown formats a result as a markdown table.
func FormatTable ¶
func FormatTable(result *Result, g *graph.SchemaGraph) string
FormatTable formats a result as a simple table string.
func FormatToon ¶
func FormatToon(result *Result, g *graph.SchemaGraph) string
FormatToon formats a result in the TOON (Token-Oriented Object Notation) format. TOON uses tabular array syntax for uniform rows: header[N]{field1,field2,...}: followed by comma-delimited data rows. See https://github.com/toon-format/toon
Types ¶
type FuncDef ¶
type FuncDef struct {
Name string
Params []string // with $ prefix
Body string // raw pipeline text
}
FuncDef represents a user-defined function.
type GroupResult ¶
GroupResult represents a group-by aggregation result.
type Query ¶
Query represents a parsed query with optional includes, defs, and pipeline stages.
func ParseQuery ¶
ParseQuery parses a full query string including optional includes, defs, and pipeline.
type Result ¶
type Result struct {
Rows []Row
Fields []string // projected fields (empty = all)
IsCount bool
Count int
Groups []GroupResult
Explain string // human-readable pipeline explanation
FormatHint string // format preference from format stage (table, json, markdown)
}
Result is the output of a query execution.
func Execute ¶
func Execute(query string, g *graph.SchemaGraph) (*Result, error)
Execute parses and executes a query against the given graph.
func ExecuteWithSearchPaths ¶
func ExecuteWithSearchPaths(query string, g *graph.SchemaGraph, searchPaths []string) (*Result, error)
ExecuteWithSearchPaths parses and executes a query, searching for modules in the given paths.
type ResultKind ¶
type ResultKind int
ResultKind distinguishes between schema and operation result rows.
const ( SchemaResult ResultKind = iota OperationResult )
type Row ¶
type Row struct {
Kind ResultKind
SchemaIdx int // index into SchemaGraph.Schemas
OpIdx int // index into SchemaGraph.Operations
// Edge annotations (populated by 1-hop traversal stages)
EdgeKind string // edge type: "property", "items", "allOf", "oneOf", "ref", etc.
EdgeLabel string // edge label: property name, array index, etc.
EdgeFrom string // source node name
}
Row represents a single result in the pipeline.
type Stage ¶
type Stage struct {
Kind StageKind
Source string // for StageSource
Expr string // for StageWhere, StageLet
Fields []string // for StageSelect, StageGroupBy
SortField string // for StageSort
SortDesc bool // for StageSort
Limit int // for StageTake, StageLast, StageSample, StageTop, StageBottom
PathFrom string // for StagePath
PathTo string // for StagePath
Format string // for StageFormat
VarName string // for StageLet
}
Stage represents a single stage in the query pipeline.
type StageKind ¶
type StageKind int
StageKind represents the type of pipeline stage.
const ( StageSource StageKind = iota StageWhere StageSelect StageSort StageTake StageUnique StageGroupBy StageCount StageRefsOut StageRefsIn StageReachable StageAncestors StageProperties StageUnionMembers StageItems StageOps StageSchemas StageExplain StageFields StageSample StagePath StageTop StageBottom StageFormat StageConnected StageBlastRadius StageNeighbors StageOrphans StageLeaves StageCycles StageClusters StageTagBoundary StageLast StageLet )