mutation

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenerateOptions

type GenerateOptions struct {
	Intents      []MutationIntent // Which intents to include (default: all)
	MaxPerIntent int              // Max mutations per intent (default: 5)
	SchemaHint   *SchemaHint      // Optional spec constraints
}

GenerateOptions controls variant generation.

func DefaultGenerateOptions

func DefaultGenerateOptions() *GenerateOptions

DefaultGenerateOptions returns default generation options.

type Mutation

type Mutation struct {
	Value  string         // The mutated value
	Intent MutationIntent // Why this mutation was generated
	Label  string         // Human-readable description (e.g., "increment by 1")
}

Mutation represents a single mutated value with metadata.

type MutationIntent

type MutationIntent int

MutationIntent describes the purpose of a mutation set.

const (
	IntentNeighbor   MutationIntent = iota // Semantically close variants (increment, swap)
	IntentBoundary                         // Edge cases, limits, overflows
	IntentEscalation                       // Privilege escalation variants
	IntentFormat                           // Format/type confusion
	IntentEmpty                            // Null, empty, undefined
)

func (MutationIntent) String

func (m MutationIntent) String() string

String returns the human-readable name of the MutationIntent.

type MutationSet

type MutationSet struct {
	OriginalValue string
	DetectedType  ValueType
	Mutations     []Mutation
}

MutationSet holds classified mutations for a single insertion point.

func Generate

func Generate(value string, vtype ValueType, opts *GenerateOptions) MutationSet

Generate produces mutations for the given value and detected type. Options control which intents are included and how many variants per intent.

type SchemaHint

type SchemaHint struct {
	Type      string   // "integer", "string", "boolean", "number"
	Format    string   // "uuid", "email", "date-time", "uri", etc.
	Enum      []string // Allowed values from spec
	Minimum   *float64 // Minimum value constraint
	Maximum   *float64 // Maximum value constraint
	MinLength *int     // Minimum string length
	MaxLength *int     // Maximum string length
	Pattern   string   // Regex pattern from spec
	ParamName string   // Parameter name for context-aware detection
}

SchemaHint provides optional type information from OpenAPI or other specs.

func BuildSchemaHint

func BuildSchemaHint(paramName string, schema *openapi3.Schema) *SchemaHint

BuildSchemaHint extracts mutation-relevant hints from an OpenAPI schema and parameter name.

type ValueType

type ValueType int

ValueType represents the semantic type of a parameter value.

const (
	TypeUnknown        ValueType = iota
	TypeInteger                  // "123", "0", "-5"
	TypeFloat                    // "3.14", "0.001"
	TypeBoolean                  // "true", "false", "1", "0", "yes", "no"
	TypeUUID                     // "550e8400-e29b-41d4-a716-446655440000"
	TypeEmail                    // "user@example.com"
	TypeTimestamp                // "2026-01-15T10:30:00Z"
	TypeDate                     // "2026-01-15"
	TypeIPv4                     // "192.168.1.10"
	TypeIPv6                     // "::1", "fe80::1"
	TypePath                     // "/api/v1/users"
	TypeEnum                     // Detected from OpenAPI spec or pattern matching
	TypeSequentialID             // "1001" (numeric, in ID-like context)
	TypeStructuredCode           // "ORD-00042", "INV-2024-001"
	TypeJWT                      // "eyJhbGciOi..."
	TypeBase64                   // Valid base64-encoded content
	TypeHexEncoded               // "4a6f686e" (hex-encoded)
	TypeURL                      // "https://example.com/callback"
	TypePhoneNumber              // "+1-555-123-4567"
	TypeCreditCard               // "4532015112830366" (Luhn-valid)
	TypeSlug                     // "my-blog-post", "user_profile_page"
	TypeJSON                     // '{"key":"value"}'
	TypeEmpty                    // ""
)

func Classify

func Classify(value string, hint *SchemaHint) ValueType

Classify detects the semantic ValueType of a raw string value. An optional SchemaHint provides overrides from OpenAPI or other specs. The hint's ParamName field provides context-aware classification boosting.

func SchemaHintToValueType

func SchemaHintToValueType(hint *SchemaHint) ValueType

SchemaHintToValueType converts a SchemaHint's format/type to a ValueType. This is useful when you have a hint but no observed value.

func (ValueType) String

func (v ValueType) String() string

String returns the human-readable name of the ValueType.

Jump to

Keyboard shortcuts

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