config

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config handles parsing and loading yapi config files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindUnknownKeys

func FindUnknownKeys(raw map[string]any) []string

FindUnknownKeys checks a raw map for keys not in knownV1Keys. Returns a sorted slice of unknown key names.

Types

type ChainStep

type ChainStep struct {
	Name     string           `yaml:"name"` // Required: unique step identifier
	ConfigV1 `yaml:",inline"` // All ConfigV1 fields available as overrides
}

ChainStep represents a single step in a request chain. It embeds ConfigV1 so all config fields are available as overrides.

type ConfigV1

type ConfigV1 struct {
	Yapi           string            `yaml:"yapi"` // The version tag
	URL            string            `yaml:"url"`
	Path           string            `yaml:"path,omitempty"`
	Method         string            `yaml:"method,omitempty"` // HTTP method (GET, POST, PUT, DELETE, etc.)
	ContentType    string            `yaml:"content_type,omitempty"`
	Headers        map[string]string `yaml:"headers,omitempty"`
	Body           map[string]any    `yaml:"body,omitempty"`
	JSON           string            `yaml:"json,omitempty"` // Raw JSON override
	Query          map[string]string `yaml:"query,omitempty"`
	Graphql        string            `yaml:"graphql,omitempty"`   // GraphQL query/mutation
	Variables      map[string]any    `yaml:"variables,omitempty"` // GraphQL variables
	Service        string            `yaml:"service,omitempty"`   // gRPC
	RPC            string            `yaml:"rpc,omitempty"`       // gRPC
	Proto          string            `yaml:"proto,omitempty"`     // gRPC
	ProtoPath      string            `yaml:"proto_path,omitempty"`
	Data           string            `yaml:"data,omitempty"`     // TCP raw data
	Encoding       string            `yaml:"encoding,omitempty"` // text, hex, base64
	JQFilter       string            `yaml:"jq_filter,omitempty"`
	Insecure       bool              `yaml:"insecure,omitempty"`     // For gRPC
	Plaintext      bool              `yaml:"plaintext,omitempty"`    // For gRPC
	ReadTimeout    int               `yaml:"read_timeout,omitempty"` // TCP read timeout in seconds
	IdleTimeout    int               `yaml:"idle_timeout,omitempty"` // TCP idle timeout in milliseconds (default 500)
	CloseAfterSend bool              `yaml:"close_after_send,omitempty"`

	// Flow control
	Delay string `yaml:"delay,omitempty"` // Wait before executing this step (e.g. "5s", "500ms")

	// Expect defines assertions to run after the request
	Expect Expectation `yaml:"expect,omitempty"`

	// Chain allows executing multiple dependent requests
	Chain []ChainStep `yaml:"chain,omitempty"`
}

ConfigV1 represents the v1 YAML schema

func (*ConfigV1) Merge

func (c *ConfigV1) Merge(step ChainStep) ConfigV1

Merge creates a full ConfigV1 by applying step overrides to the base config. Maps are deep copied to avoid polluting the shared base config between steps.

func (*ConfigV1) ToDomain

func (c *ConfigV1) ToDomain() (*domain.Request, error)

ToDomain converts V1 YAML to the Canonical Config

type Envelope

type Envelope struct {
	Yapi string `yaml:"yapi"`
}

Envelope is used solely to peek at the version

type Expectation

type Expectation struct {
	Status any      `yaml:"status,omitempty"` // int or []int
	Assert []string `yaml:"assert,omitempty"` // JQ expressions that must evaluate to true
}

Expectation defines assertions for a chain step

type ParseResult

type ParseResult struct {
	Request  *domain.Request
	Warnings []string
	Chain    []ChainStep // Chain steps if this is a chain config
	Base     *ConfigV1   // Base config for chain merging
	Expect   Expectation // Expectations for single request validation
}

ParseResult holds the output of parsing a yapi config file.

func Load

func Load(path string) (*ParseResult, error)

Load reads and parses a yapi config file from the given path.

func LoadFromString

func LoadFromString(data string) (*ParseResult, error)

LoadFromString parses a yapi config from raw YAML data.

Jump to

Keyboard shortcuts

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