Documentation
¶
Overview ¶
Package oq implements a pipeline query language for OpenAPI schema graphs.
Queries are written as pipeline expressions:
schemas | where(depth > 5) | sort-by(depth, desc) | take(10) | select name, depth
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
- func FormatYAML(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
func FormatYAML ¶ added in v1.22.0
func FormatYAML(result *Result, g *graph.SchemaGraph) string
FormatYAML formats results as raw YAML from the underlying schema/operation objects. For multiple results, outputs a YAML stream with --- separators. This enables piping into yq for content-level queries.
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, toon)
EmitYAML bool // emit raw YAML nodes instead of formatted output
}
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 GroupRowResult ParameterResult ResponseResult RequestBodyResult ContentTypeResult HeaderResult SecuritySchemeResult SecurityRequirementResult ServerResult TagResult LinkResult )
type Row ¶
type Row struct {
Kind ResultKind
SchemaIdx int // index into SchemaGraph.Schemas
OpIdx int // index into SchemaGraph.Operations
// Edge annotations (populated by traversal stages)
Via string // edge type: "property", "items", "allOf", "oneOf", "ref", etc.
Key string // edge key: property name, array index, etc.
From string // source node name (the node that contains the reference)
Target string // target/seed node name (the node traversal originated from)
Direction string // "→" (outgoing) or "←" (incoming) — set by bidi traversals
// BFS depth (populated by depth-limited traversals)
BFSDepth int
// Group annotations (populated by group-by stages)
GroupKey string // group key value
GroupCount int // number of members in the group
GroupNames []string // member names
// Navigation objects (populated by navigation stages)
Parameter *openapi.Parameter
Response *openapi.Response
RequestBody *openapi.RequestBody
ContentType *openapi.MediaType
Header *openapi.Header
SecurityScheme *openapi.SecurityScheme
// Propagated context from parent navigation stages
StatusCode string // propagated from response rows to content-types/headers
MediaTypeName string // media type key (e.g., "application/json")
HeaderName string // header name
ComponentKey string // component key name or parameter name
SchemeName string // security scheme name
Scopes []string // security requirement scopes
SourceOpIdx int // operation this row originated from (-1 if N/A)
// Server, Tag, Link objects (populated by server/tag/link sources/stages)
Server *openapi.Server
Tag *openapi.Tag
Link *openapi.Link
LinkName string // link name within response
CallbackName string // callback name within operation
}
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, StageHighest, StageLowest, StageRefs
PathFrom string // for StagePath
PathTo string // for StagePath
Format string // for StageFormat
VarName string // for StageLet
RefsDir string // for StageRefs: "out", "in", or "" (bidi)
}
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 StageRefs StageProperties StageItems StageToOperations StageToSchemas StageExplain StageFields StageSample StagePath StageHighest StageLowest StageFormat StageBlastRadius StageOrphans StageLeaves StageCycles StageClusters StageCrossTag StageLast StageLet StageOrigin StageToYAML StageParameters StageResponses StageRequestBody StageContentTypes StageHeaders StageToSchema // singular: extract schema from nav row StageOperation // back-navigate to source operation StageSecurity // operation security requirements StageMembers // union members (allOf/oneOf/anyOf children) or group row expansion StageCallbacks // operation callbacks → operations StageLinks // response links StageAdditionalProperties // schema additional properties traversal StagePatternProperties // schema pattern properties traversal )