runner

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package runner executes API requests and chains.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssertionResult

type AssertionResult struct {
	Expression    string
	Passed        bool
	Error         error
	ActualValue   string // The actual value from evaluation (for failed assertions)
	ExpectedValue string // The expected value (for failed assertions)
	LeftSide      string // The left side of comparison (e.g., ".id")
	Operator      string // The operator (e.g., "==", "!=", ">", etc.)
}

AssertionResult holds the result of a single assertion

type ChainContext

type ChainContext struct {
	Results      map[string]StepResult
	EnvOverrides map[string]string // Environment variables from project config
}

ChainContext tracks results from chain steps for variable interpolation.

func NewChainContext

func NewChainContext(envOverrides map[string]string) *ChainContext

NewChainContext creates a new chain context for tracking step results.

func (*ChainContext) AddResult

func (c *ChainContext) AddResult(name string, result *Result)

AddResult stores a step result for later variable interpolation.

func (*ChainContext) ExpandVariables

func (c *ChainContext) ExpandVariables(input string) (string, error)

ExpandVariables replaces $var and ${var} with values from Env or Chain Context.

func (*ChainContext) ResolveVariableRaw

func (c *ChainContext) ResolveVariableRaw(input string) (any, bool)

ResolveVariableRaw checks if input is a pure variable reference (e.g. "$step.field" or "${step.field}") and returns the raw typed value. Returns (value, true) if resolved, (nil, false) otherwise.

type ChainResult

type ChainResult struct {
	Results            []*Result            // Results from each step
	StepNames          []string             // Names of each step
	ExpectationResults []*ExpectationResult // Expectation results from each step
}

ChainResult holds the output of a chain execution

func RunChain

func RunChain(ctx context.Context, factory ExecutorFactory, base *config.ConfigV1, steps []config.ChainStep, opts Options) (*ChainResult, error)

RunChain executes a sequence of steps, merging each step with the base config

type ExecutorFactory

type ExecutorFactory interface {
	Create(transport string) (executor.TransportFunc, error)
}

ExecutorFactory is an interface for creating transport functions

type ExpectationResult

type ExpectationResult struct {
	StatusPassed     bool
	StatusChecked    bool
	AssertionsPassed int
	AssertionsTotal  int
	AssertionResults []AssertionResult
	Error            error
}

ExpectationResult contains the results of running expectations

func CheckExpectationsWithEnv added in v0.5.0

func CheckExpectationsWithEnv(expect config.Expectation, result *Result, envVars map[string]string) *ExpectationResult

CheckExpectationsWithEnv validates the response against expected values with environment variables

func (*ExpectationResult) AllPassed

func (e *ExpectationResult) AllPassed() bool

AllPassed returns true if all expectations passed

type Options

type Options struct {
	URLOverride    string
	NoColor        bool
	BinaryOutput   bool
	Insecure       bool
	EnvOverrides   map[string]string // Environment variables from project config
	ProjectRoot    string            // Path to project root (for validation)
	ProjectEnv     string            // Selected environment name (for validation)
	ConfigFilePath string            // Path to the yapi config file (for relative output_file resolution)
}

Options for execution

type Result

type Result struct {
	Body        string
	ContentType string
	StatusCode  int
	Warnings    []string
	RequestURL  string        // The full constructed URL (HTTP/GraphQL only)
	Duration    time.Duration // Time taken for the request
	BodyLines   int
	BodyChars   int
	BodyBytes   int
	Headers     map[string]string // Response headers
}

Result holds the output of a yapi execution

func Run

func Run(ctx context.Context, exec executor.TransportFunc, req *domain.Request, warnings []string, opts Options) (*Result, error)

Run executes a yapi request and returns the result.

type StepResult

type StepResult struct {
	BodyRaw    string
	BodyJSON   map[string]any
	Headers    map[string]string
	StatusCode int
}

StepResult holds the output of a single chain step.

Jump to

Keyboard shortcuts

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