arazzo

package
v0.41.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArazzo             = errors.New("invalid arazzo document")
	ErrMissingArazzoField        = errors.New("missing required 'arazzo' field")
	ErrMissingInfo               = errors.New("missing required 'info' field")
	ErrMissingSourceDescriptions = errors.New("missing required 'sourceDescriptions' field")
	ErrEmptySourceDescriptions   = errors.New("sourceDescriptions must have at least one entry")
	ErrMissingWorkflows          = errors.New("missing required 'workflows' field")
	ErrEmptyWorkflows            = errors.New("workflows must have at least one entry")
)

Document errors

View Source
var (
	ErrMissingWorkflowId   = errors.New("missing required 'workflowId'")
	ErrMissingSteps        = errors.New("missing required 'steps'")
	ErrEmptySteps          = errors.New("steps must have at least one entry")
	ErrDuplicateWorkflowId = errors.New("duplicate workflowId")
)

Workflow errors

View Source
var (
	ErrMissingStepId               = errors.New("missing required 'stepId'")
	ErrDuplicateStepId             = errors.New("duplicate stepId within workflow")
	ErrStepMutualExclusion         = errors.New("step must have exactly one of operationId, operationPath, or workflowId")
	ErrExecutorNotConfigured       = errors.New("executor is not configured")
	ErrUnsupportedSelectorOutput   = errors.New("selector outputs are not supported by the execution engine")
	ErrUnsupportedExecutionFeature = errors.New("Arazzo 1.1 execution feature is not supported by the execution engine")
)

Step errors

View Source
var (
	ErrMissingParameterName  = errors.New("missing required 'name'")
	ErrMissingParameterIn    = errors.New("missing required 'in' for operation parameter")
	ErrInvalidParameterIn    = errors.New("'in' must be path, query, header, or cookie")
	ErrParameterInNotAllowed = errors.New("'in' is not permitted for workflow or action parameters")
	ErrMissingParameterValue = errors.New("missing required 'value'")
)

Parameter errors

View Source
var (
	ErrMissingActionName     = errors.New("missing required 'name'")
	ErrMissingActionType     = errors.New("missing required 'type'")
	ErrInvalidSuccessType    = errors.New("success action type must be 'end' or 'goto'")
	ErrInvalidFailureType    = errors.New("failure action type must be 'end', 'retry', or 'goto'")
	ErrActionMutualExclusion = errors.New("action cannot have both workflowId and stepId")
	ErrGotoRequiresTarget    = errors.New("goto action requires workflowId or stepId")
	ErrStepIdNotInWorkflow   = errors.New("stepId must reference a step in the current workflow")
)

Action errors

View Source
var (
	ErrInvalidExpression            = errors.New("invalid runtime expression")
	ErrUnknownExpressionPrefix      = errors.New("unknown expression prefix")
	ErrUnsupportedExpressionDialect = errors.New("expression dialect evaluation is not supported")
)

Expression errors

View Source
var (
	ErrUnresolvedWorkflowRef  = errors.New("workflowId references unknown workflow")
	ErrUnresolvedSourceDesc   = errors.New("sourceDescription reference not found")
	ErrUnresolvedOperationRef = errors.New("operation reference not found")
	ErrOperationSourceMapping = errors.New("operation source mapping failed")
	ErrUnresolvedComponent    = errors.New("component reference not found")
	ErrCircularDependency     = errors.New("circular workflow dependency detected")
)

Reference errors

View Source
var ErrDuplicateSourceIdentity = errors.New("duplicate source document identity")

ErrDuplicateSourceIdentity indicates ambiguous supplied-document identity.

View Source
var (
	ErrMissingCondition = errors.New("missing required 'condition'")
)

Criterion errors

View Source
var (
	ErrSourceDescLoadFailed = errors.New("failed to load source description")
)

Source description errors

Functions

func ClearCriterionCaches deprecated

func ClearCriterionCaches()

ClearCriterionCaches is a no-op retained for backward compatibility. Criterion caches are now scoped per-Engine instance and cleared via Engine.ClearCaches().

Deprecated: Use Engine.ClearCaches() instead.

func EvaluateCriterion

func EvaluateCriterion(criterion *high.Criterion, exprCtx *expression.Context) (bool, error)

EvaluateCriterion evaluates a single criterion against an expression context. This standalone function does not use caching. For cached evaluation, use an Engine.

Types

type ArazzoDocumentFactory

type ArazzoDocumentFactory func(sourceURL string, bytes []byte) (*high.Arazzo, error)

ArazzoDocumentFactory creates a parsed Arazzo document from raw bytes. The sourceURL provides location context for relative reference resolution.

type ArazzoSourceAdapter added in v0.39.0

type ArazzoSourceAdapter interface {
	SourceDocumentAdapter
	HasWorkflow(string) bool
}

ArazzoSourceAdapter exposes Arazzo workflow lookups.

type AsyncAPISourceAdapter added in v0.39.0

type AsyncAPISourceAdapter interface {
	SourceDocumentAdapter
	HasChannel(string) bool
	HasOperation(string) bool
}

AsyncAPISourceAdapter exposes AsyncAPI channel and operation lookups.

type CandidateDocument added in v0.39.0

type CandidateDocument struct {
	Type             string
	ResolvedIdentity string
	RetrievalURI     string
	SourceBytes      []byte
	RootNode         *yaml.Node
	OpenAPIDocument  *v3high.Document
	ArazzoDocument   *high.Arazzo
	Adapter          SourceDocumentAdapter
}

CandidateDocument is a supplied source document and its portable/retrieval identities.

type CandidateDocumentProvider added in v0.39.0

type CandidateDocumentProvider interface {
	Documents(context.Context) ([]CandidateDocument, error)
}

CandidateDocumentProvider supplies application-owned source documents without I/O.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine orchestrates the execution of Arazzo workflows. An Engine is NOT safe for concurrent use from multiple goroutines.

func NewEngine

func NewEngine(doc *high.Arazzo, executor Executor, sources []*ResolvedSource) *Engine

NewEngine creates a new Engine for executing Arazzo workflows.

func NewEngineWithConfig

func NewEngineWithConfig(doc *high.Arazzo, executor Executor, sources []*ResolvedSource, config *EngineConfig) *Engine

NewEngineWithConfig creates a new Engine with custom configuration.

func (*Engine) ClearCaches

func (e *Engine) ClearCaches()

ClearCaches resets all per-engine caches (expressions, regex, JSONPath).

func (*Engine) RunAll

func (e *Engine) RunAll(ctx context.Context, inputs map[string]map[string]any) (*RunResult, error)

RunAll executes all workflows in dependency order.

func (*Engine) RunWorkflow

func (e *Engine) RunWorkflow(ctx context.Context, workflowId string, inputs map[string]any) (*WorkflowResult, error)

RunWorkflow executes a single workflow by its ID.

type EngineConfig

type EngineConfig struct {
	RetainResponseBodies bool // If false, nil out response bodies after extracting outputs

	// SleepFunc, when non-nil, replaces the engine's default wait between
	// retry attempts (a failure action's retryAfter). The engine calls it
	// with the workflow context and the retryAfter duration; returning an
	// error aborts the workflow, exactly as a cancelled context does with
	// the default sleeper.
	//
	// Injecting it lets a host substitute its own timer: a durable workflow
	// runtime (Temporal, DBOS, Restate) passes its replay-safe durable
	// sleep — a real time.Timer inside a replayed workflow body would block
	// the scheduler or break determinism — and tests pass a recording fake
	// to avoid real waits. Nil uses the default context-aware timer.
	SleepFunc func(ctx context.Context, d time.Duration) error
}

EngineConfig configures engine behavior.

type ExecutionRequest

type ExecutionRequest struct {
	Source        *ResolvedSource
	OperationID   string
	OperationPath string
	Method        string
	Parameters    map[string]any
	RequestBody   any
	ContentType   string
}

ExecutionRequest represents a request to execute an API operation.

type ExecutionResponse

type ExecutionResponse struct {
	StatusCode int
	Headers    map[string][]string
	Body       any
	URL        string // Actual request URL (populated by Executor)
	Method     string // HTTP method used (populated by Executor)
}

ExecutionResponse represents the response from an API operation execution.

type Executor

type Executor interface {
	Execute(ctx context.Context, req *ExecutionRequest) (*ExecutionResponse, error)
}

Executor defines the interface for executing API calls.

type HTTPSourceHandler added in v0.39.0

type HTTPSourceHandler func(context.Context, string) ([]byte, error)

HTTPSourceHandler retrieves source bytes while honoring caller cancellation and deadlines.

type InMemoryResolverConfig added in v0.39.0

type InMemoryResolverConfig struct {
	OpenAPIFactory OpenAPIDocumentFactory
	ArazzoFactory  ArazzoDocumentFactory
	Fallback       SourceDocumentResolver
	MaxSources     int // Maximum candidate documents to accept (default: 50).
}

InMemoryResolverConfig configures candidate parsing, limits, and an optional explicit fallback.

type InMemorySourceResolver added in v0.39.0

type InMemorySourceResolver struct {
	// contains filtered or unexported fields
}

InMemorySourceResolver resolves supplied documents before consulting an explicit fallback.

func NewInMemorySourceResolver added in v0.39.0

func NewInMemorySourceResolver(
	ctx context.Context,
	provider CandidateDocumentProvider,
	config *InMemoryResolverConfig,
) (*InMemorySourceResolver, error)

NewInMemorySourceResolver fully parses supplied candidates once and builds immutable lookup maps.

func (*InMemorySourceResolver) Resolve added in v0.39.0

Resolve returns an identity match first, then a retrieval-location match, then an explicit fallback.

type LegacySourceResolver added in v0.39.0

type LegacySourceResolver struct {
	// contains filtered or unexported fields
}

LegacySourceResolver adapts the existing opt-in file/HTTP resolver to SourceDocumentResolver.

func NewLegacySourceResolver added in v0.39.0

func NewLegacySourceResolver(config *ResolveConfig) *LegacySourceResolver

NewLegacySourceResolver creates an explicit compatibility adapter around ResolveSources.

func (*LegacySourceResolver) Resolve added in v0.39.0

Resolve delegates one request to the existing resolver without enabling implicit retrieval elsewhere.

type OpenAPIDocumentFactory

type OpenAPIDocumentFactory func(sourceURL string, bytes []byte) (*v3high.Document, error)

OpenAPIDocumentFactory creates a parsed OpenAPI document from raw bytes. The sourceURL provides location context for relative reference resolution.

type OpenAPISourceAdapter added in v0.39.0

type OpenAPISourceAdapter interface {
	SourceDocumentAdapter
	HasOperationID(string) bool
	HasOperationPath(string) bool
}

OpenAPISourceAdapter exposes OpenAPI operation lookups to downstream validators.

type ResolveConfig

type ResolveConfig struct {
	OpenAPIFactory OpenAPIDocumentFactory // Creates *v3high.Document from bytes
	ArazzoFactory  ArazzoDocumentFactory  // Creates *high.Arazzo from bytes
	BaseURL        string
	// HTTPHandlerWithContext is preferred for custom retrieval because it can
	// stop work when ResolveSourcesWithContext is cancelled or times out.
	HTTPHandlerWithContext HTTPSourceHandler
	// HTTPHandler is retained for compatibility. It is checked for cancellation
	// before invocation, but its legacy signature cannot stop in-flight work.
	HTTPHandler func(url string) ([]byte, error)
	HTTPClient  *http.Client
	FSRoots     []string

	Timeout        time.Duration // Per-source fetch timeout (default: 30s)
	MaxBodySize    int64         // Max response body in bytes (default: 10MB)
	AllowedSchemes []string      // URL scheme allowlist (default: ["https", "http", "file"])
	AllowedHosts   []string      // Host allowlist (nil = allow all)
	MaxSources     int           // Max source descriptions to resolve (default: 50)
}

ResolveConfig configures how source descriptions are resolved.

type ResolvedSource

type ResolvedSource struct {
	Name            string           // SourceDescription name
	URL             string           // Resolved URL
	Identity        string           // Portable resolved identity, usually resolved $self
	RetrievalURI    string           // Location from which the document was retrieved
	Type            string           // "openapi" or "arazzo"
	SourceBytes     []byte           // Original source bytes when supplied or retrieved
	RootNode        *yaml.Node       // Original root node when supplied
	OpenAPIDocument *v3high.Document // Non-nil when Type == "openapi"
	ArazzoDocument  *high.Arazzo     // Non-nil when Type == "arazzo"
	Adapter         SourceDocumentAdapter
}

ResolvedSource represents a successfully resolved source description.

func ResolveSources

func ResolveSources(doc *high.Arazzo, config *ResolveConfig) ([]*ResolvedSource, error)

ResolveSources resolves all source descriptions in an Arazzo document.

Retrieval is not cancellable through this entry point; it applies only the per-source timeout from ResolveConfig. Use ResolveSourcesWithContext to make in-flight retrieval respond to caller cancellation.

func ResolveSourcesWithContext added in v0.39.0

func ResolveSourcesWithContext(
	ctx context.Context,
	doc *high.Arazzo,
	config *ResolveConfig,
) ([]*ResolvedSource, error)

ResolveSourcesWithContext resolves all source descriptions in an Arazzo document. Built-in HTTP retrieval and HTTPHandlerWithContext honor caller cancellation and the per-source timeout, whichever elapses first. The legacy HTTPHandler can only observe cancellation before it is invoked because its signature has no context.

type RunResult

type RunResult struct {
	Workflows []*WorkflowResult
	Success   bool
	Duration  time.Duration
}

RunResult represents the result of executing all workflows.

type SourceDocumentAdapter added in v0.39.0

type SourceDocumentAdapter interface {
	SourceType() string
}

SourceDocumentAdapter identifies a source document without coupling libopenapi to a concrete library.

type SourceDocumentResolver added in v0.39.0

type SourceDocumentResolver interface {
	Resolve(context.Context, SourceRequest) (*ResolvedSource, error)
}

SourceDocumentResolver resolves one source request. Implementations must honor cancellation.

type SourceRequest added in v0.39.0

type SourceRequest struct {
	Name    string
	URL     string
	Type    string
	BaseURI string
}

SourceRequest describes one sourceDescription lookup.

type StepFailureError

type StepFailureError struct {
	StepId         string
	CriterionIndex int // -1 if not criterion-related
	Message        string
	Cause          error
}

StepFailureError represents a step execution failure with structured context.

func (*StepFailureError) Error

func (e *StepFailureError) Error() string

func (*StepFailureError) Unwrap

func (e *StepFailureError) Unwrap() error

type StepResult

type StepResult struct {
	StepId     string
	Success    bool
	StatusCode int
	Outputs    map[string]any
	Error      error
	Duration   time.Duration
	Retries    int
}

StepResult represents the result of executing a single step.

type UnsupportedExecutionFeatureError added in v0.39.0

type UnsupportedExecutionFeatureError struct {
	WorkflowId string
	StepId     string
	Field      string
}

UnsupportedExecutionFeatureError identifies a modeled Arazzo 1.1 feature whose execution semantics are intentionally deferred.

func (*UnsupportedExecutionFeatureError) Error added in v0.39.0

Error returns stable workflow, step, and field context.

func (*UnsupportedExecutionFeatureError) Unwrap added in v0.39.0

Unwrap exposes ErrUnsupportedExecutionFeature for errors.Is.

type UnsupportedSelectorOutputError added in v0.39.0

type UnsupportedSelectorOutputError struct {
	WorkflowId string
	StepId     string
	OutputName string
}

UnsupportedSelectorOutputError identifies a 1.1 Selector Object output that the current execution engine cannot evaluate safely.

func (*UnsupportedSelectorOutputError) Error added in v0.39.0

Error returns stable workflow, step, and output context.

func (*UnsupportedSelectorOutputError) Unwrap added in v0.39.0

Unwrap exposes ErrUnsupportedSelectorOutput for errors.Is.

type ValidationError

type ValidationError struct {
	Path   string // e.g. "workflows[0].steps[2].parameters[1]"
	Line   int
	Column int
	Cause  error
}

ValidationError represents a structured validation error with source location.

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

type ValidationResult

type ValidationResult struct {
	Errors   []*ValidationError
	Warnings []*Warning
}

ValidationResult holds all validation errors and warnings.

func Validate

func Validate(doc *high.Arazzo) *ValidationResult

Validate performs compatibility validation for the legacy Arazzo 1.0 surface. Complete schema-driven Arazzo validation, including 1.1, belongs in libopenapi-validator. Returns nil when no supported errors or warnings are found; callers should nil-check the result before accessing it.

func (*ValidationResult) Error

func (r *ValidationResult) Error() string

Error implements the error interface, returning all errors as a combined string.

func (*ValidationResult) HasErrors

func (r *ValidationResult) HasErrors() bool

HasErrors returns true if there are any validation errors.

func (*ValidationResult) HasWarnings

func (r *ValidationResult) HasWarnings() bool

HasWarnings returns true if there are any validation warnings.

func (*ValidationResult) Unwrap

func (r *ValidationResult) Unwrap() []error

Unwrap returns the individual validation errors for use with errors.Is/As (Go 1.20+).

type Warning

type Warning struct {
	Path    string
	Line    int
	Column  int
	Message string
}

Warning represents a non-fatal validation issue.

func (*Warning) String

func (w *Warning) String() string

type WorkflowResult

type WorkflowResult struct {
	WorkflowId string
	Success    bool
	Inputs     map[string]any
	Outputs    map[string]any
	Steps      []*StepResult
	Error      error
	Duration   time.Duration
}

WorkflowResult represents the result of executing a single workflow.

Directories

Path Synopsis
Package expression implements the Arazzo runtime expression parser, local symbol resolver, and evaluator.
Package expression implements the Arazzo runtime expression parser, local symbol resolver, and evaluator.

Jump to

Keyboard shortcuts

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