expression

package
v0.36.5 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 4 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package expression implements the Arazzo runtime expression parser and evaluator. https://spec.openapis.org/arazzo/v1.0.1#runtime-expressions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(expr Expression, ctx *Context) (any, error)

Evaluate resolves a parsed Expression against a Context.

func EvaluateString

func EvaluateString(input string, ctx *Context) (any, error)

EvaluateString parses and evaluates a runtime expression string in one call.

func UnescapeJSONPointer

func UnescapeJSONPointer(s string) string

UnescapeJSONPointer applies RFC 6901 unescaping: ~1 -> /, ~0 -> ~

func Validate

func Validate(input string) error

Validate checks whether a string is a valid runtime expression without allocating a full AST.

Types

type ComponentsContext

type ComponentsContext struct {
	Parameters     map[string]any
	SuccessActions map[string]any
	FailureActions map[string]any
	Inputs         map[string]any
}

ComponentsContext holds resolved component data.

type Context

type Context struct {
	URL             string
	Method          string
	StatusCode      int
	RequestHeaders  map[string]string
	RequestQuery    map[string]string
	RequestPath     map[string]string
	RequestBody     *yaml.Node
	ResponseHeaders map[string]string
	ResponseBody    *yaml.Node
	Inputs          map[string]any
	Outputs         map[string]any
	Steps           map[string]*StepContext
	Workflows       map[string]*WorkflowContext
	SourceDescs     map[string]*SourceDescContext
	Components      *ComponentsContext
}

Context holds runtime values for expression evaluation.

type Expression

type Expression struct {
	Type        ExpressionType // The kind of expression
	Raw         string         // Original input string
	Name        string         // First segment after prefix (header name, step ID, etc.)
	Tail        string         // Everything after name for Steps/Workflows/SourceDescriptions/Components
	Property    string         // Sub-property for request/response sources (header/query/path name)
	JSONPointer string         // For body references: the #/path portion
}

Expression represents a parsed Arazzo runtime expression.

func Parse

func Parse(input string) (Expression, error)

Parse parses a single Arazzo runtime expression. Returns a value type to avoid heap allocation.

type ExpressionType

type ExpressionType int

ExpressionType identifies the kind of runtime expression.

const (
	URL                 ExpressionType = iota // $url
	Method                                    // $method
	StatusCode                                // $statusCode
	RequestHeader                             // $request.header.{name}
	RequestQuery                              // $request.query.{name}
	RequestPath                               // $request.path.{name}
	RequestBody                               // $request.body{#/json-pointer}
	ResponseHeader                            // $response.header.{name}
	ResponseQuery                             // $response.query.{name}
	ResponsePath                              // $response.path.{name}
	ResponseBody                              // $response.body{#/json-pointer}
	Inputs                                    // $inputs.{name}
	Outputs                                   // $outputs.{name}
	Steps                                     // $steps.{name}[.tail]
	Workflows                                 // $workflows.{name}[.tail]
	SourceDescriptions                        // $sourceDescriptions.{name}[.tail]
	Components                                // $components.{name}[.tail]
	ComponentParameters                       // $components.parameters.{name}
)

type SourceDescContext

type SourceDescContext struct {
	URL string
}

SourceDescContext holds resolved source description data.

type StepContext

type StepContext struct {
	Inputs  map[string]any
	Outputs map[string]any
}

StepContext holds inputs and outputs for a specific step.

type Token

type Token struct {
	Literal      string     // Non-empty if this is a literal text segment
	Expression   Expression // Valid if IsExpression is true
	IsExpression bool       // True if this token is an expression
}

Token represents a segment in an embedded expression string like "prefix {$expr} suffix".

func ParseEmbedded

func ParseEmbedded(input string) ([]Token, error)

ParseEmbedded parses a string that may contain embedded runtime expressions in {$...} blocks. Returns alternating literal and expression tokens.

type WorkflowContext

type WorkflowContext struct {
	Inputs  map[string]any
	Outputs map[string]any
}

WorkflowContext holds inputs and outputs for a specific workflow.

Jump to

Keyboard shortcuts

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